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

NamingConventions/ValidVariableName: implement PHPCSUtils and support modern PHP #2192

Merged
merged 10 commits into from
Jan 11, 2023

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jan 10, 2023

NamingConventions/ValidVariableName: sync with upstream

Synced in relevant changes as made upstream in the following commit:

NamingConventions/ValidVariableName: bug fix

When a text string with interpolated variables contained a variable on the $wordpress_mixed_case_vars list, any variables found in the text string after it would not be examined or flagged.

Fixed now.

Includes test proving the bug and safeguarding the fix.

NamingConventions/ValidVariableName: implement PHPCSUtils [1]

Includes minor efficiency tweak.

Includes adding a test for the OO property verification, which was so far untested.

NamingConventions/ValidVariableName: implement PHPCSUtils [2]

Includes minor efficiency tweaks.

NamingConventions/ValidVariableName: implement PHPCSUtils [3]

Improve and stabilize the retrieval of embedded variables by:

  1. Using the TextStrings::getEmbed() method to retrieve all embedded expressions.
  2. Subsequently still using the regex to match variables within embedded expressions, but with an improved regex.
    • Fixed the \x7f-\xff range to \x80-\xff (was originally wrong in the PHP manual).
    • Only match a variable in braces - ${foo} - when the braces are balanced.
      Note: this syntax is deprecated as per PHP 8.2, but that's not the concern of this sniff.
    • Capture the variable name in a named match.

Includes tests.

NamingConventions/ValidVariableName: add tests with PHP 7.4+ arrow functions

... to safeguard those are handled correctly.

NamingConventions/ValidVariableName: allow for the PHP 8.0+ nullsafe object operator

Check for both the T_OBJECT_OPERATOR as well as the T_NULLSAFE_OBJECT_OPERATOR.

Includes unit tests.

NamingConventions/ValidVariableName: add tests with PHP 8.1+ enums

... to safeguard variables found in those are handled correctly.

NamingConventions/ValidVariableName: add extra test

... which tests code previously untested.

NamingConventions/ValidVariableName: minor documentation improvement

Synced in relevant changes as made upstream in the following commit:
* squizlabs/PHP_CodeSniffer@beeb36f - Making sure the sniff works correctly with PHP 7.4+ typed properties.
When a text string with interpolated variables contained a variable on the `$wordpress_mixed_case_vars` list, any variables found in the text string _after_ it would not be examined or flagged.

Fixed now.

Includes test proving the bug and safeguarding the fix.
Includes minor efficiency tweak.

Includes adding a test for the OO property verification, which was so far untested.
Improve and stabilize the retrieval of embedded variables by:
1. Using the `TextStrings::getEmbed()` method to retrieve all embedded expressions.
2. Subsequently still using the regex to match variables within embedded expressions, but with an improved regex.
    - Fixed the `\x7f-\xff` range to `\x80-\xff` (was originally wrong in the PHP manual).
    - Only match a variable in braces - `${foo}` - when the braces are balanced.
        Note: this syntax is deprecated as per PHP 8.2, but that's not the concern of this sniff.
    - Capture the variable name in a named match.

Includes tests.
…nctions

... to safeguard those are handled correctly.
…object operator

Check for both the `T_OBJECT_OPERATOR` as well as the `T_NULLSAFE_OBJECT_OPERATOR`.

Includes unit tests.
... to safeguard variables found in those are handled correctly.
... which tests code previously untested.
Copy link
Member

@GaryJones GaryJones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dingo-d dingo-d merged commit b9412cb into develop Jan 11, 2023
@dingo-d dingo-d deleted the feature/validvariablename-phpcsutils-and-modern-php branch January 11, 2023 09:11
@jrfnl jrfnl mentioned this pull request Jan 11, 2023
19 tasks
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