View on GitHub

RefactoringPHP

A PHP version of the refactors from Refactoring: Improving the Design of Existing Code (Second Edition) by Martin Fowler

Decompose Conditional (260)

Old Code

<?php
if ( !$aDate->isBefore($plan->summerStart) && !$aDate->isAfter($plan->summerEnd) {
    $charge = $quantity * $plan->summerRate;
} else {
    $charge = $quantity * $plan->regularRate + $plan->regularServiceCharge;
}

New Code

<?php
if ( summer() ) {
    $charge = summerCharge();
} else {
    $charge = regularCharge();
}