Skip to content

WIP: PHPCS 4.x changes#3

Open
rodrigoprimo wants to merge 47 commits intodevelopfrom
phpcs-4
Open

WIP: PHPCS 4.x changes#3
rodrigoprimo wants to merge 47 commits intodevelopfrom
phpcs-4

Conversation

@rodrigoprimo
Copy link
Copy Markdown
Owner

Creating this PR to test the GH action changes.

@rodrigoprimo rodrigoprimo force-pushed the phpcs-4 branch 4 times, most recently from f04e071 to c78b598 Compare September 19, 2025 17:57
@rodrigoprimo rodrigoprimo force-pushed the phpcs-4 branch 2 times, most recently from 50244fd to 4d6533c Compare October 2, 2025 22:20
@rodrigoprimo rodrigoprimo force-pushed the phpcs-4 branch 6 times, most recently from 3e1ea76 to 9aeec04 Compare October 21, 2025 19:25
@rodrigoprimo rodrigoprimo force-pushed the phpcs-4 branch 4 times, most recently from f7ad57e to 9e2a835 Compare October 30, 2025 17:10
@rodrigoprimo rodrigoprimo force-pushed the phpcs-4 branch 5 times, most recently from 8113034 to cd42bc6 Compare November 7, 2025 21:35
@rodrigoprimo rodrigoprimo force-pushed the phpcs-4 branch 5 times, most recently from a4c6ab1 to b4d3fb3 Compare November 18, 2025 13:33
@rodrigoprimo rodrigoprimo force-pushed the phpcs-4 branch 3 times, most recently from d8fd190 to d20de47 Compare November 19, 2025 15:21
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization of fully qualified function calls when checking if a nonce verification function is used in the code.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization when skipping over function calls while checking the hook name.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization when checking if a given fully qualified function is a target function. In those cases, the leading backslash is removed from the token content to allow for the function name comparisons to continue working as they worked in PHPCS 3.x.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization when checking for calls to `define()` and hook functions to handle fully qualified calls correctly.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization when checking if a given token is a target token.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization when checking function calls after the `T_ASPERAND` token.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization when determining the name of the function being called.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization when checking if a WP time constant was used and when checking the name of a first-class callable. It also updates a few test expectation to account for the difference in the sniff behavior when running with PHPCS 3.x and 4.x.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization when checking if a PHP native array key exists function was used.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization when determining if a constant is global or not.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization when checking the name of a given constants to see if it is one of the discouraged constants and when checking if `define()` was called.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization to this sniff.
Correctly handle changing fully qualified `\current_time()` function name.
Update the README.md file to document the limitations of running the sniff together with PHPCS >= 4.0.

Remember to pull the corresponding PR to update the wiki.
PHPCS 4.x removed special test-specific code from the Ruleset class that handled `Config::$sniffs` restrictions differently when `PHP_CODESNIFFER_IN_TESTS` was defined (see PHPCSStandards/PHP_CodeSniffer/ 996).

This caused `testStdIn()` tests that used `$config->standards = array('WordPress')` to attempt loading the entire WordPress standard with all dependencies, resulting in errors about missing standards.

The fix uses minimal ruleset XML files that only include the specific sniff being tested making the test pass with both PHPCS 3.x and 4.x.
Add support for the new namespaced name tokenization used in PHPCS 4.0. Since the tokenization changed between PHPCS 3 and 4, different logic is used depending on the PHPCS version.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization when searching for the function name in the ContextHelper::$arrayCompareFunctions array.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization of fully qualified function calls and static method calls to this sniff. It also updates a few of the test expectations as the number of errors vary depending on whether running PHPCS 3.x or 4.x.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization to this method.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization of fully qualified calls to `\wpdb::prepare()`, `\sprintf()`, `\implode()` and `\array_fill()`.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization of fully qualified calls to WPDB methods and also ensure that the method bails when handling `T_NAME_QUALIFIED` and `T_NAME_RELATIVE` tokens.

As a side effect, this also fixes a bug where the method would not bail early when the token is not T_STRING, T_VARIABLE, or T_NAME_FULLY_QUALIFIED, which could cause it to return true for any token followed by an object operator and a target method call.
Update the expectation for three test cases as they are different between PHPCS 3.x and PHPCS 4.x (see 2665).
The `is_escaping_function()` and `is_auto_escaped_function()` methods now use `ltrim()` to strip the leading backslash from fully qualified function names, ensuring they are correctly recognized when tokenized as `T_NAME_FULLY_QUALIFIED` in PHPCS 4.0.
… 4.0

Use `ltrim()` to strip the leading backslash from fully qualified function names, ensuring they are correctly recognized when tokenized as `T_NAME_FULLY_QUALIFIED` in PHPCS 4.0.
Use `ltrim()` to strip the leading backslash from fully qualified function names, ensuring they are correctly recognized when tokenized as `T_NAME_FULLY_QUALIFIED` in PHPCS 4.0.
Use `ltrim()` to strip the leading backslash from fully qualified function names, ensuring they are correctly recognized when tokenized as `T_NAME_FULLY_QUALIFIED` in PHPCS 4.0.
PHPCS 4.0 introduced a change where empty string values in array
properties are converted to `null`. This is documented in the
Version 4.0 Developer Upgrade Guide (https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Version-4.0-Developer-Upgrade-Guide#property-type-casting-has-been-made-more-consistent):

> Array elements can now no longer contain an empty string value
> as that value will be cast to `null`.

This affected the sniffs PrefixAllGlobals and NoSilencedErrors.
Both pass array values to `strtolower()`, which triggers a PHP 8.5
deprecation warning when `null` is passed.

The fix is different for each sniff:

- PrefixAllGlobals: Convert `null` back to empty string at the
start of the validation loop. This preserves the "prefix too short"
error that alerts users about invalid configuration.

- NoSilencedErrors: Filter out `null` values before processing.
Unlike PrefixAllGlobals, this sniff has no validation that
provides user feedback for invalid entries, so filtering is cleaner.
A test case was added to safeguard against the deprecation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant