Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0: Move "deprecation" related utilities to dedicated DeprecationHelper + handle PHP 8.0 attributes #2052

Merged
merged 2 commits into from
May 17, 2022

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented May 16, 2022

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 new WordPressCS\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.

jrfnl added 2 commits May 16, 2022 13:45
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 new `WordPressCS\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
…claration 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`).
@jrfnl jrfnl merged commit 1afe9b8 into develop May 17, 2022
@jrfnl jrfnl deleted the feature/1465-new-deprecationhelper branch May 17, 2022 12:18
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