View on GitHub

RefactoringPHP

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

Consolidate Conditional Expression (263)

Old Code

<?php
if ( $anEmployee->seniority < 2 ) {
    return 0;
}
if ( $anEmployee->monthsDisabled > 12 ) {
    return 0;
}
if ( $anEmployee->isPartTime ) {
    return 0;
}

New Code

<?php
if ( isNotEligableForDisability() ) {
    return 0;
}

function isNotEligableForDisablity()
{
    return $anEmployee->seniority < 2 ||
        $anEmployee->monthsDisabled > 12 ||
        $anEmployee->isPartTime;
}