Php-cs-fixer: [RFC] NoUnreachableCodeFixer

Created on 19 Apr 2016  路  7Comments  路  Source: FriendsOfPHP/PHP-CS-Fixer

What do you think about fixer that would remove non-reachable code?

eg

before:

functinon foo()
{
    echo 1;
    return;
    echo 2;
}

after:

functinon foo()
{
    echo 1;
    return;
}
kinfeature request

Most helpful comment

             case 'directdebit':
                 return 'test';
                 break;

please let the fixer remove the break in these cases as well :)

All 7 comments

馃憤 to have this. However I think this could be a risky fixer for some. It won't change what the code would do, but often unreachable code isn't intentional and people should actually run the code which is unreachable.

often unreachable code isn't intentional

agree

and people should actually run the code which is unreachable

why?

@keradus, I think it should be named "UnreachableCodeFixer" (instead of "NoUnreachableCodeFixer" which seems a contradiction for what you're proposing).

We name rules after state the code will follow after fixing. For all fixers. Just for consistency. So, after fixing, there should be no unreachable code.

Excellent then @keradus. Thanks for the clarification.

             case 'directdebit':
                 return 'test';
                 break;

please let the fixer remove the break in these cases as well :)

As much as having this fixer would be great I'm not sure it's worth the effort - would be very complicated and Vimeo's Psalm has --find-dead-code option to do exactly this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

datenmeister picture datenmeister  路  3Comments

EvgenyOrekhov picture EvgenyOrekhov  路  3Comments

EvgenyOrekhov picture EvgenyOrekhov  路  3Comments

BackEndTea picture BackEndTea  路  3Comments

ndench picture ndench  路  3Comments