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

Move is_in_array_comparison() utility method to dedicated ContextHelper + fixes #2234

Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Apr 24, 2023

Move is_in_array_comparison() utility method to dedicated ContextHelper

The is_in_array_comparison() utility method is only used by a small set of sniffs, so is better placed in a dedicated class.

This commit moves the is_in_array_comparison() method and the associated $arrayCompareFunctions property to the new WordPressCS\WordPress\Helpers\ContextHelper class and starts using that class in the relevant sniffs.

Related to #1465

This method will be tested via the WordPress.Security.NonceVerification sniff (via pre-existing and new tests).

ContextHelper::is_in_array_comparison(): bug fix for case-insensitivity

Function names are case-insensitive. The ContextHelper::is_in_function_call() method already handles this correctly, but the ContextHelper::is_in_array_comparison() method did not, which could result in Undefined array key error notices.

Tested by adjusting one of the tests.

ContextHelper::is_in_array_comparison(): add support for PHP 8.0 named parameters

With named parameters, the function call may have two parameters, without the required $filter_value param being one of them. Would make for an invalid function call, but that's not the concern of this sniff.

Fixed now by looking for a specific named parameter.

Includes tests in the WordPress.Security.NonceVerification test file (which include PHP 7.3+ trailing commas in function calls).

…elper`

The `is_in_array_comparison()` utility method is only used by a small set of sniffs, so is better placed in a dedicated class.

This commit moves the `is_in_array_comparison()` method and the associated `$arrayCompareFunctions` property to the new `WordPressCS\WordPress\Helpers\ContextHelper` class and starts using that class in the relevant sniffs.

Related to 1465

This method will be tested via the `WordPress.Security.NonceVerification` sniff (via pre-existing and new tests).
Function names are case-insensitive. The `ContextHelper::is_in_function_call()` method already handles this correctly, but the `ContextHelper::is_in_array_comparison()` method did not, which could result in `Undefined array key` error notices.

Tested by adjusting one of the tests.
…d parameters

With named parameters, the function call may have two parameters, without the required `$filter_value` param being one of them. Would make for an invalid function call, but that's not the concern of this sniff.

Fixed now by looking for a specific named parameter.

Includes tests in the `WordPress.Security.NonceVerification` test file (which include PHP 7.3+ trailing commas in function calls).
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.

@GaryJones GaryJones merged commit 84eb923 into develop Apr 25, 2023
35 checks passed
@GaryJones GaryJones deleted the feature/move-is_in_array_comparison-to-helper-class branch April 25, 2023 14:55
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.

None yet

3 participants