Skip to content

PHP 7.4/8.0: new ChangedConcatOperatorPrecedence sniff#805

Merged
wimg merged 2 commits intomasterfrom
php-7.4/concatenation-precedence
Jun 16, 2019
Merged

PHP 7.4/8.0: new ChangedConcatOperatorPrecedence sniff#805
wimg merged 2 commits intomasterfrom
php-7.4/concatenation-precedence

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented May 31, 2019

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:

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

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:

@jrfnl jrfnl added this to the 9.x Next milestone May 31, 2019
@jrfnl jrfnl force-pushed the php-7.4/concatenation-precedence branch from 82ea841 to 6e3a78d Compare May 31, 2019 16:02
@jrfnl jrfnl requested a review from wimg May 31, 2019 21:32
... 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
@jrfnl jrfnl force-pushed the php-7.4/concatenation-precedence branch 3 times, most recently from 6d0b44c to c4c681d Compare June 2, 2019 19:37
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.
@jrfnl jrfnl force-pushed the php-7.4/concatenation-precedence branch from c4c681d to d753cd1 Compare June 2, 2019 22:29
@jrchamp
Copy link
Contributor

jrchamp commented Jun 7, 2019

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 wimg merged commit 3973ccc into master Jun 16, 2019
@wimg wimg deleted the php-7.4/concatenation-precedence branch June 16, 2019 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants