Skip to content

PHP 8.4 asymmetric visibility properties: add tests to four sniffs #2551

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

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

rodrigoprimo
Copy link
Collaborator

Asymmetric visibility properties were introduced in PHP 8.4 (https://wiki.php.net/rfc/asymmetric-visibility-v2). PHPCS started supporting it in version 3.13.0 (PHPCSStandards/PHP_CodeSniffer#871). Since WPCS requires PHPCS 3.13.x, with @jrfnl's help, I investigated what needed to be updated in the WPCS repository to accommodate this new syntax.

In this PR, I'm adding tests to WordPress.NamingConventions.PrefixAllGlobals, WordPress.NamingConventions.ValidVariableName, WordPress.Security.NonceVerification, and WordPress.WP.GlobalVariablesOverride to safeguard that those four sniffs continue to handle asymmetric visibility properties correctly, as those sniffs have code related to class properties or parameters passed to the class constructor (in the case of asymmetric visibility combined with constructor promoted properties). No changes were required to the code of those sniffs.

As far as I could check, no further changes are required in the WPCS codebase to accommodate the new asymmetric visibility properties syntax.

To be able to add tests to WordPress.WP.GlobalVariablesOverride, I had to move a test with an intentional syntax error to a separate file. While doing that, I made a small improvement to the code comment in the sniff related to the moved test.

…lity properties

This commit adds a few tests using asymmetric visibility properties (including in constructor property promotion) to the `WordPress.NamingConventions.PrefixAllGlobals` tests. This is just to ensure that the part of the sniff code that ignores properties or method parameters (in the case of constructor property promotion) continues to handle PHP 8.4+ asymmetric visibility properties correctly. No change to the sniff code is needed.
…ility properties

This commit adds a few tests using asymmetric visibility properties (including in constructor property promotion) to the `WordPress.NamingConventions.ValidVariableName` tests. This is just to ensure that the sniff continues to apply its variable name rules when dealing with asymmetric visibility properties added in PHP 8.4.

The sniff was already handling asymmetric visibility properties correctly, and no change to the sniff code is needed.
…erties

This commit adds a test using asymmetric visibility properties to the `WordPress.Security.NonceVerification` tests. This is just to ensure that the sniff continues to ignore PHP 8.4+ asymmetric visibility properties.

The sniff was already handling asymmetric visibility properties correctly, and no change to the sniff code is needed.
Also update code comment related to the moved parse error test to include one more case where the code might bow out.
…perties

This commit adds a few tests using asymmetric visibility properties (including in constructor property promotion) to the `WordPress.WP.GlobalVariablesOverride` tests. This is just to ensure that the part of the sniff code that ignores properties or method parameters (in the case of constructor property promotion) continues to handle PHP 8.4+ asymmetric visibility properties correctly. No change to the sniff code is needed.
@rodrigoprimo rodrigoprimo force-pushed the asymmetric-visibility-properties branch from 7f8a941 to a1f0108 Compare July 18, 2025 19:42
@rodrigoprimo
Copy link
Collaborator Author

I had to force push without changes to rerun the build because of an unrelated phpstan 403: rate limit exceeded error.

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.

2 participants