PHP 7.4/8.0: new ChangedConcatOperatorPrecedence sniff by jrfnl · Pull Request #805 · PHPCompatibility/PHPCompatibility

@jrfnl jrfnl mentioned this pull request

Jun 1, 2019

40 tasks

@jrfnl

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

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.

wimg

wimg approved these changes Jun 16, 2019

@wimg wimg deleted the php-7.4/concatenation-precedence branch

June 16, 2019 13:24