YoastCS: drop support PHP < 7.2 & modernize the codebase #324
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.
Drop support for PHP < 7.2
The majority of the Yoast codebases now have a minimum of PHP 7.2.
Additionally, the YoastCS checks should give the same results independently of the PHP version on which the CS check is being run, which means that generally speaking, the CS check is run on a high PHP version, both locally as well as in CI.
With this in mind, there is no reason to keep the YoastCS minimum supported PHP version at PHP 5.4, so let's bring it in line with the other Yoast codebases and let it have a PHP 7.2 minimum.
Note: PHP_CodeSniffer itself still has a PHP 5.4 minimum. PHPCS 4.x is expected to have a PHP 7.2 minimum and this change is in line with that.
YoastCS/Modernize: add explicit visibility to all OO constants
YoastCS/Modernize: use constant arrays
Prior to PHP 5.6 class constants couldn't contain arrays. As support for PHP < 7.2 has now been dropped, unchangable properties containing arrays should be changed to constants.
YoastCS/Modernize: selectively use null coalescing
PHP 7.0 introduced the null coalesce operator. This commit implements the use of the operator in select places.
YoastCS/Modernize - Tests: add PHP native return type declarations
As support for PHP < 7.2 has now been dropped, PHP native parameter and return type declarations can be used.
There are, however, a couple of caveats:
Also note that a
TypeError
thrown by a sniff, would stop the scan of a file dead, so let's be conservative with adding type declarations in the sniffs for now, but add them freely to the tests.