Skip to content

PHP 8 throw expressions not supported by Squiz.PHP.NonExecutableCode rule #3592

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

Closed
ZebulanStanphill opened this issue May 13, 2022 · 2 comments · Fixed by #3777
Closed

PHP 8 throw expressions not supported by Squiz.PHP.NonExecutableCode rule #3592

ZebulanStanphill opened this issue May 13, 2022 · 2 comments · Fixed by #3777
Milestone

Comments

@ZebulanStanphill
Copy link

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:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs test.php ...
  3. 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
@derrabus
Copy link

related: #2857

@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
None yet
Development

Successfully merging a pull request may close this issue.

4 participants