-
-
Notifications
You must be signed in to change notification settings - Fork 490
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
WP/AlternativeFunctions: implement PHPCSUtils and support modern PHP #2169
Merged
GaryJones
merged 13 commits into
develop
from
feature/alternativefunctions-phpcsutils-and-modern-php
Dec 21, 2022
Merged
WP/AlternativeFunctions: implement PHPCSUtils and support modern PHP #2169
GaryJones
merged 13 commits into
develop
from
feature/alternativefunctions-phpcsutils-and-modern-php
Dec 21, 2022
Conversation
This file contains 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
Orders function name lists alphabetically. The group ordering, while not in alphabetic order, is left as-is for now. This commit does not add or delete any functions from the lists.
... for properties which were added to the sniff after the initial conception.
... from `protected` to `private` for properties which are only intended to be used by the sniff itself anyway.
…ot applied The `wp_parse_url()` alternative to `parse_url()` was introduced in WP 4.4.0, but didn't have support for the `$component` parameter until WP 4.7.0. For that reason, special casing was put in place in PR 1369 (WPCS 1.0.0) to examine whether the `$component` parameter was passed to `parse_url()` or not and to only advise the switch to `wp_parse_url()`: 1. If the `$component` parameter was _not_ used and the `minimum_wp_version` was `4.4` or higher. 2. If the `$component` parameter **_was_** used and the `minimum_wp_version` was `4.7` or higher. Unfortunately, the special casing was looking for the wrong function name match, so has never worked. The additional tests now added demonstrate the bug. This PR, combined with the previously pulled `version_compare()` related fix from 2149, fix the bug. --- Includes a follow up to 2121 The "final" `// phpcs:set` annotations in the test case file should always reset to the default value for the property. The default value which was being used, however, was out of date. Fixed now.
…] / strip_tags() 1. Adjusted the way it is determined whether the PHP native function can be replaced with the WP version of the same using the updated PHPCSUtils 1.0.0-alpha4 `PassedParameters` functionality. 2. Verified the parameter name used is in line with the name as per the PHP 8.0 release. PHP itself renamed a lot of parameters in PHP 8.0. As named parameters did not exist before PHP 8.0, the parameter name as per PHP 8.0 (or above) is the only relevant name. Ref: https://www.php.net/manual/en/function.strip-tags Includes additional unit tests.
…] / parse_url() 1. Adjusted the way it is determined whether the PHP native function can be replaced with the WP version of the same using the updated PHPCSUtils 1.0.0-alpha4 `PassedParameters` functionality. 2. Verified the parameter name used is in line with the name as per the PHP 8.0 release. PHP itself renamed a lot of parameters in PHP 8.0. As named parameters did not exist before PHP 8.0, the parameter name as per PHP 8.0 (or above) is the only relevant name. Ref: https://www.php.net/manual/en/function.parse-url Includes additional unit tests.
…] / file_get_contents() 1. Adjusted the way it is determined whether the PHP native function can be replaced with the WP version of the same using the updated PHPCSUtils 1.0.0-alpha4 `PassedParameters` functionality. 2. Verified the parameter names used are in line with the names as per the PHP 8.0 release. PHP itself renamed a lot of parameters in PHP 8.0. As named parameters did not exist before PHP 8.0, the parameter name as per PHP 8.0 (or above) is the only relevant name. Ref: https://www.php.net/manual/en/function.file-get-contents Includes additional unit tests.
…] / readfile/fopen/file_put_contents() 1. Adjusted the way it is determined whether the PHP native function can be replaced with the WP version of the same using the updated PHPCSUtils 1.0.0-alpha4 `PassedParameters` functionality. 2. Verified the parameter names used are in line with the names as per the PHP 8.0 release. PHP itself renamed a lot of parameters in PHP 8.0. As named parameters did not exist before PHP 8.0, the parameter name as per PHP 8.0 (or above) is the only relevant name. Refs: * https://www.php.net/manual/en/function.readfile * https://www.php.net/manual/en/function.fopen * https://www.php.net/manual/en/function.file-put-contents Includes additional unit tests.
…ents() The `'raw'` key in the parameter arrays returned from the `PassedParameters` class contains - as per the name - the _raw_ contents of the parameter. Since PHPCSUtils 1.0.0-alpha4, the return array also contain a `'clean'` index, which contains the contents of the parameter cleaned of comments. By switching to using that key, some false negatives and false positives get fixed. Includes unit tests demonstrating the issue and safeguarding the fix.
…ontents() The `'raw'` key in the parameter arrays returned from the `PassedParameters` class contains - as per the name - the _raw_ contents of the parameter. Since PHPCSUtils 1.0.0-alpha4, the return array also contain a `'clean'` index, which contains the contents of the parameter cleaned of comments. While this doesn't make a difference functionally (no false positives/negatives), it may improve performance a tiny bit as there is less text for the `is_local_data_stream()` method to handle.
dingo-d
approved these changes
Dec 21, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
GaryJones
approved these changes
Dec 21, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅
GaryJones
deleted the
feature/alternativefunctions-phpcsutils-and-modern-php
branch
December 21, 2022 14:17
19 tasks
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.
WP/AlternativeFunctions: order lists alphabetically
Follow up on #2108
Orders function name lists alphabetically. The group ordering, while not in alphabetic order, is left as-is for now.
This commit does not add or delete any functions from the lists.
WP/AlternativeFunctions: add missing
@since
tags... for properties which were added to the sniff after the initial conception.
WP/AlternativeFunctions: change property visibility
... from
protected
toprivate
for properties which are only intended to be used by the sniff itself anyway.WP/AlternativeFunctions: remove stray blank lines at top of test file
WP/AlternativeFunctions: move parse_url related tests down
WP/AlternativeFunctions: bug fix - special casing for parse_url was not applied
The
wp_parse_url()
alternative toparse_url()
was introduced in WP 4.4.0, but didn't have support for the$component
parameter until WP 4.7.0.For that reason, special casing was put in place in PR #1369 (WPCS 1.0.0) to examine whether the
$component
parameter was passed toparse_url()
or not and to only advise the switch towp_parse_url()
:$component
parameter was not used and theminimum_wp_version
was4.4
or higher.$component
parameter was used and theminimum_wp_version
was4.7
or higher.Unfortunately, the special casing was looking for the wrong function name match, so has never worked.
The additional tests now added demonstrate the bug.
This commit, combined with the previously pulled
version_compare()
related fix from #2149, fixes the bug.Includes a follow up to #2121
The "final"
// phpcs:set
annotations in the test case file should always reset to the default value for the property. The default value which was being used, however, was out of date.Fixed now.
WP/AlternativeFunctions: add support for PHP 8.0+ named parameters [1] / strip_tags()
PassedParameters
functionality.PHP itself renamed a lot of parameters in PHP 8.0. As named parameters did not exist before PHP 8.0, the parameter name as per PHP 8.0 (or above) is the only relevant name.
Ref: https://www.php.net/manual/en/function.strip-tags
Includes additional unit tests.
WP/AlternativeFunctions: add support for PHP 8.0+ named parameters [2] / parse_url()
PassedParameters
functionality.PHP itself renamed a lot of parameters in PHP 8.0. As named parameters did not exist before PHP 8.0, the parameter name as per PHP 8.0 (or above) is the only relevant name.
Ref: https://www.php.net/manual/en/function.parse-url
Includes additional unit tests.
WP/AlternativeFunctions: add support for PHP 8.0+ named parameters [3] / file_get_contents()
PassedParameters
functionality.PHP itself renamed a lot of parameters in PHP 8.0. As named parameters did not exist before PHP 8.0, the parameter name as per PHP 8.0 (or above) is the only relevant name.
Ref: https://www.php.net/manual/en/function.file-get-contents
Includes additional unit tests.
WP/AlternativeFunctions: minor code readability improvements
WP/AlternativeFunctions: add support for PHP 8.0+ named parameters [4] / readfile/fopen/file_put_contents()
PassedParameters
functionality.PHP itself renamed a lot of parameters in PHP 8.0. As named parameters did not exist before PHP 8.0, the parameter name as per PHP 8.0 (or above) is the only relevant name.
Refs:
Includes additional unit tests.
WP/AlternativeFunctions: prevent some false positives / file_get_contents()
The
'raw'
key in the parameter arrays returned from thePassedParameters
class contains - as per the name - the raw contents of the parameter.Since PHPCSUtils 1.0.0-alpha4, the return array also contain a
'clean'
index, which contains the contents of the parameter cleaned of comments.By switching to using that key, some false negatives and false positives get fixed.
Includes unit tests demonstrating the issue and safeguarding the fix.
WP/AlternativeFunctions: minor code tweak / readfile/fopen/file_put_contents()
The
'raw'
key in the parameter arrays returned from thePassedParameters
class contains - as per the name - the raw contents of the parameter.Since PHPCSUtils 1.0.0-alpha4, the return array also contain a
'clean'
index, which contains the contents of the parameter cleaned of comments.While this doesn't make a difference functionally (no false positives/negatives), it may improve performance a tiny bit as there is less text for the
is_local_data_stream()
method to handle.