Describe the bug
The throw expression added in PHP 8 is not supported by the Squiz.PHP.NonExecutableCode rule.
Code sample
<?php declare(strict_types=1);
function doStuff(?string $thing): string {
$foo = $thing ?? throw new \Exception();
return $foo;
}
Custom ruleset
<?xml version="1.0"?>
<ruleset name="My Custom Standard">
<rule ref="Squiz.PHP.NonExecutableCode" />
</ruleset>
To reproduce
Steps to reproduce the behavior:
- Create a file called
test.php with the code sample above...
- Run
phpcs test.php ...
- See error message displayed
6 | WARNING | Code after the THROW statement on line 4 cannot be executed
Expected behavior
Throw expressions should be recognized as expressions, not statements.
Versions (please complete the following information):
- OS: KDE Neon Linux
- PHP: 8.1
- PHPCS: 9.5.20
- Standard: Squiz