PHP 7.4/8.0: new RemovedTernaryAssociativity sniff#810
Merged
Conversation
... to determine whether a ternary is a short ternary, i.e. without the middle. This method will :fingers_crossed: also be introduced into PHPCS itself in version 3.5.0. Upstream, the method will be 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
40 tasks
PHP 7.4 deprecates nesting of ternaries without explicit use of parentheses. PHP 8.0 will remove the (left-)associativity of ternaries completely. This will become a compile-time error. Refs: * https://wiki.php.net/rfc/ternary_associativity * php/php-src@09ea55c (PHP 7.4 deprecation) * https://gist.github.com/nikic/b6214f87b0e4a7c6fe26919ac849194f Includes unit tests. To test this sniff, I have run it over some 200.000 files. While I can't say for sure whether there were any missed problem cases (false negatives), all the issues detected by the sniff were actual cases of nested ternaries which would become problematic in PHP 7.4/8.0. Related to 808
8be24c8 to
d6d7ba4
Compare
wimg
approved these changes
Jun 3, 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.
PHP 7.4 deprecates nesting of ternaries without explicit use of parentheses.
PHP 8.0 will remove the (left-)associativity of ternaries completely. This will become a compile-time error.
Refs:
Includes unit tests.
To test this sniff, I have run it over some 200.000 files. While I can't say for sure whether there were any missed problem cases (false negatives), all the issues detected by the sniff were actual cases of nested ternaries which would become problematic in PHP 7.4/8.0 (and most, if not all, were bugs).
Related to #808
This PR includes adding a new
Sniff::isShortTernary()method to determine whether a ternary is a short ternary, i.e. without the middle.This method will 🤞 also be introduced into PHPCS itself in version 3.5.0.
Upstream, the method will be 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:
This PR also implements the use of this new
Sniff::isShortTernary()method in the existingNewShortTernarysniff.