3.0: Move "deprecation" related utilities to dedicated DeprecationHelper + handle PHP 8.0 attributes #2052
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.
Move "deprecation" related utilities to dedicated DeprecationHelper
The "deprecation" related utilities are only used by a small set of sniffs, so are better placed in a dedicated class.
This commit moves the
is_function_deprecated()
method to a newWordPressCS\WordPress\Helpers\DeprecationHelper
and starts using that class in the relevant sniffs.Note:
It is expected for PHPCSUtils to have dedicated methods for the same at some point in the future. If/when those methods become available, it is recommended for the sniffs to start using the PHPCSUtils methods and for this class to be deprecated and removed in the next major release.
Related to #1465
PHP 8.0 | DeprecationHelper: allow for attributes between function declaration and docblock
PHP 8.0 introduced attributes, which can be placed - and commonly are placed - between a function declaration and its docblock.
Ref: https://www.php.net/manual/en/language.attributes.php
This commit updates the
is_function_deprecated()
method to skip over attributes. This prevents false positives when a function is deprecated, but also has an attribute.Tested via both sniffs using the helper class.
Includes renaming a local variable to be more descriptive (
$ignore
instead of$find
).👉🏻 Note: this doesn't add full support for attributes to WPCS, it just adds it to this particular method.