PHP 7.4/8.0: new ChangedConcatOperatorPrecedence sniff#805
Merged
Conversation
82ea841 to
6e3a78d
Compare
40 tasks
... to determine whether a `+` or `-` is an operator or a unary, i.e. `-1`. This method will :fingers_crossed: also be introduced into PHPCS itself in version 3.5.0. Upstream, the method has been pulled with unit tests. As the intention is for this method to primarily be hosted within PHPCS, it seemed redundant to duplicate those here. Refs: * squizlabs/PHP_CodeSniffer#2456 * squizlabs/PHP_CodeSniffer@3167110
6d0b44c to
c4c681d
Compare
As of PHP 8.0, the operator precedence of concatenation will be lowered, with deprecation notices being thrown as of PHP 7.4 for unparenthesized expressions containing an '.' before a '+' or '-'. Refs: * https://wiki.php.net/rfc/concatenation_precedence * php/php-src@3b23694 (PHP 7.4 deprecation) * php/php-src@61ee869 (PHP 8.0 precedence change) Notes: - I've not been able to come up with a valid unit test which would involve `&` as a reference, but I suspect this should be accounted for all the same, so the sniff does account for it. **NOTE**: the name of the sniff does not comply with the "normal" naming pattern, but I'm not sure what would be a more appropriate name `ForbiddenConcatBeforePlusMinusWithoutParenthesis` seems a bit overly long, just as `RemovedConcatPrecedenceSameAsPlusMinus`. Ideas welcome.
c4c681d to
d753cd1
Compare
Contributor
|
I think the name you chose works well. The word "Changed" seems optional as differences are implied and the Sniff is focused on the ConcatOperator and it's relative Precedence. As far as ideas that support the "normal naming", my best ideas are "NewConcatOperatorPrecedence" and "ForbiddenAmbiguousConcatOperator" (with or without "Precendence"). Whatever you choose will work well, but hopefully these ideas from left field will help somewhat. 🥂 |
wimg
approved these changes
Jun 16, 2019
This file contains hidden or 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
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.
As of PHP 8.0, the operator precedence of concatenation will be lowered, with deprecation notices being thrown as of PHP 7.4 for unparenthesized expressions containing an '.' before a '+' or '-'.
Refs:
Notes:
&as a reference, but I suspect this should be accounted for all the same, so the sniff does account for it.NOTE: the name of the sniff does not comply with the "normal" naming pattern, but I'm not sure what would be a more appropriate name
ForbiddenConcatBeforePlusMinusWithoutParenthesisseems a bit overly long, just asRemovedConcatPrecedenceSameAsPlusMinus.Ideas welcome.
Related #808
This PR includes adding a new
Sniff::isUnaryPlusMinus()method to determine whether a+or-is an operator or a unary, i.e.-1.This method will 🤞 also be introduced into PHPCS itself in version 3.5.0.
Upstream, the method has been pulled with unit tests. As the intention is for this method to primarily be hosted within PHPCS, it seemed redundant to duplicate those here.
Refs: