Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Squiz.PHP.NonExecutableCode.Unreachable when using ternary operator #2857

Closed
kkmuffme opened this issue Feb 5, 2020 · 5 comments · Fixed by #3777
Closed

Squiz.PHP.NonExecutableCode.Unreachable when using ternary operator #2857

kkmuffme opened this issue Feb 5, 2020 · 5 comments · Fixed by #3777

Comments

@kkmuffme
Copy link

kkmuffme commented Feb 5, 2020

Getting Squiz.PHP.NonExecutableCode.Unreachable for following (valid) code:

$var = 'hello';
echo $var == 'foo' ? 'bar' : die( 'world' );

echo 'example';
@gsherwood
Copy link
Member

This is absolutely a bug, but I've been trying to decide if I remove all these non-code-style sniffs in version 4 instead of trying to support them. It's not what PHPCS is good at and not a collection of sniffs I have time to keep updated.

I'll leave this open as a bug until I decide either way, but no work will be done on it until I do.

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Mar 9, 2020
@kkmuffme
Copy link
Author

kkmuffme commented Mar 9, 2020

Overall, these work really good and there's few bugs in those, so I think it would be great if they could be kept, as they are really useful.

@alies-dev
Copy link

the same for null coalescing operation + throw (php 8):

$referrer = $invitedUser->referrer ?? throw new \DomainException('Should not be reached!');

if ($referrer->email) {
    ...
}
 35 | WARNING | Code after the THROW statement on line 33 cannot be executed
    |         | (Squiz.PHP.NonExecutableCode.Unreachable)

@dpi
Copy link

dpi commented Nov 19, 2021

Affects external issue https://www.drupal.org/project/date_recur/issues/3250423

@jrfnl
Copy link
Contributor

jrfnl commented Dec 8, 2023

FYI: the fix for this issue is included in today's PHP_CodeSniffer 3.8.0 release.

As per #3932, development on PHP_CodeSniffer will continue in the PHPCSStandards/PHP_CodeSniffer repository. If you want to stay informed, you may want to start "watching" that repo (or watching releases from that repo).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PHPCS v3 Development
Ready for Release
Development

Successfully merging a pull request may close this issue.

5 participants