aik099 / CodingStandard

The PHP_CodeSniffer coding standard I'm using on all of my projects
BSD 3-Clause "New" or "Revised" License
5 stars 2 forks source link

Method/function-wide IF statement #81

Open aik099 opened 9 years ago

aik099 commented 9 years ago

When large IF statement is extracted, during refactoring, to separate method it's important to transform it the way that it will exit method immediately using inverted condition to decrease nesting level in that method.

If transformation wasn't made by developer and method has method-wide IF statement, then this must be reported as an error.

Before:

...
if ( $condition ) {
    // some stuff
}
...

After:

...
function someStuff()
{
    if ( !$condition ) {
        return;
    }

    // some stuff
}
...