-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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/NonExecutableCode: slew of bug fixes, mostly related to modern PHP #3777
Merged
gsherwood
merged 7 commits into
squizlabs:master
from
jrfnl:feature/2857-3592-squiz-nonexecutable-code-allow-for-php8-throw-expressions
May 4, 2023
Merged
Squiz/NonExecutableCode: slew of bug fixes, mostly related to modern PHP #3777
gsherwood
merged 7 commits into
squizlabs:master
from
jrfnl:feature/2857-3592-squiz-nonexecutable-code-allow-for-php8-throw-expressions
May 4, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`$prev` is already defined in exactly the same way on line 66. No need to re-define it.
…s them Aside from `T_EXIT`, PHP (prior to PHP 8.0) does not allow for the inline use of the other tokens this sniff registers. While using those tokens inline would result in a parse error, that is not the concern of this sniff. By ignoring these, the sniff causes false negatives. This commit makes the sniff more selective and only ignores inline statements for tokens which are allowed in inline statements. Includes unit test.
The sniff, as it was, only allowed for `or` and `||` logical operators before a termination expression, not for `and`, `&&` or `xor`, while PHP allows these too. See: https://3v4l.org/OWS4n#veol Fixed now. Includes unit tests.
The `T_EXIT` token can be used in ternaries without affecting code after the ternary expression. See: https://3v4l.org/oMWuA#veol Fixed now. Includes unit test. Fixes 2857
… coalesce (equals) PHP 7.0 introduced the null coalesce operator. PHP 7.4 introduced the null coalesce equals operator. The `T_EXIT` token can be used in combination with those without affecting the code directly following it. See: https://3v4l.org/C218d#veol Fixed now. Includes unit test. Related to 2857
…ions PHP 7.4 introduced arrow functions. The `T_EXIT` token can be used in those without affecting the code following it. See: https://3v4l.org/gSrt4#veol Fixed now. Includes unit test.
PHP 8.0 introduced the ability to use `throw` as an expression instead of as a statement. Ref: https://wiki.php.net/rfc/throw_expression When used as an expression, the `throw` does not necessarily affect the code after it. See: https://3v4l.org/AmMf2 Fixed now. Includes unit tests. Fixes 3592
@gsherwood Could this PR please be earmarked for PHPCS 3.8.0 ? |
jrfnl
deleted the
feature/2857-3592-squiz-nonexecutable-code-allow-for-php8-throw-expressions
branch
May 4, 2023 07:41
gsherwood
added a commit
that referenced
this pull request
May 4, 2023
FYI: this fix 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Squiz/NonExecutableCode: remove redundant line
$prev
is already defined in exactly the same way on line 66. No need to re-define it.Squiz/NonExecutableCode: only ignore inline statements when PHP allows them
Aside from
T_EXIT
, PHP (prior to PHP 8.0) does not allow for the inline use of the other tokens this sniff registers.While using those tokens inline would result in a parse error, that is not the concern of this sniff.
By ignoring these, the sniff causes false negatives.
This commit makes the sniff more selective and only ignores inline statements for tokens which are allowed in inline statements.
Includes unit test.
Squiz/NonExecutableCode: bug fix - allow for all logic operators
The sniff, as it was, only allowed for
or
and||
logical operators before a termination expression, not forand
,&&
orxor
, while PHP allows these too.See: https://3v4l.org/OWS4n#veol
Fixed now.
Includes unit tests.
Squiz/NonExecutableCode: bug fix - expressions in ternary
The
T_EXIT
token can be used in ternaries without affecting code after the ternary expression.See: https://3v4l.org/oMWuA#veol
Fixed now.
Includes unit test.
Fixes #2857
Squiz/NonExecutableCode: bug fix - expressions after PHP 7.0/7.4 null coalesce (equals)
PHP 7.0 introduced the null coalesce operator.
PHP 7.4 introduced the null coalesce equals operator.
The
T_EXIT
token can be used in combination with those without affecting the code directly following it.See: https://3v4l.org/C218d#veol
Fixed now.
Includes unit test.
Related to #2857
Squiz/NonExecutableCode: bug fix - expressions in PHP 7.4 arrow functions
PHP 7.4 introduced arrow functions. The
T_EXIT
token can be used in those without affecting the code following it.See: https://3v4l.org/gSrt4#veol
Fixed now.
Includes unit test.
Squiz/NonExecutableCode: bug fix - PHP 8.0 inline throw expressions
PHP 8.0 introduced the ability to use
throw
as an expression instead of as a statement.Ref: https://wiki.php.net/rfc/throw_expression
When used as an expression, the
throw
does not necessarily affect the code after it.See: https://3v4l.org/AmMf2
Fixed now.
Includes unit tests.
Fixes #3592