squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.68k stars 1.48k forks source link

False positives for exception expression #3919

Closed Chi-teck closed 1 year ago

Chi-teck commented 1 year ago

Describe the bug

Since PHP 8.0 expressions can now throw exceptions. So the code below is valid. However, it triggers Squiz.PHP.NonExecutableCode.Unreachable warning.

Code sample

$input = TRUE;
$input ?: throw new \RuntimeException('Error.');
echo 'The code was executed';
jrfnl commented 1 year ago

Closing as already fixed via #3777, which will be included in PHPCS 3.8.0.

jrfnl commented 11 months ago

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).