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 validation checking functionality to dedicated ValidationHelper, implement PHPCSUtils + other improvements #2264

Merged
merged 12 commits into from
Jun 25, 2023

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jun 23, 2023

Move validation checking functionality to dedicated ValidationHelper

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

This commit moves the is_validated() method to the new WordPressCS\WordPress\Helpers\ValidationHelper class and starts using that class in the relevant sniffs.

The method has been made stand-alone and now expects the $phpcsFile to be passed to it.
The method signature has changed from protected to public static.

Related to #1465

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

Security/ValidatedSanitizedInput: rename test case file

... to allow for adding additional test case files testing specific (parse error) situations.

ValidationHelper::is_validated(): add some extra tests

... in particular testing the defensive coding which is in place in the helper method.

ValidationHelper::is_validated(): implement PHPCSUtils

ValidationHelper::is_validated(): move inline array to property [1]

ValidationHelper::is_validated(): move inline array to property [2]

Includes bug fix as the function name comparison was not done in a case-insensitive manner.

Tested by adjusting one of the existing tests.

ValidationHelper::is_validated(): extract some duplicate code to a separate method

ValidationHelper::is_validated(): add note about PHP 7.4 arrow functions

ValidationHelper::is_validated(): add support for PHP 8.0 named parameters

Includes tests in the WordPress.Security.ValidatedSanitizedInput test file.

ValidationHelper::is_validated(): don't examine PHP 8.0 attributes which may look like function calls

Includes test in the WordPress.Security.ValidatedSanitizedInput test file.

ValidationHelper::is_validated(): don't examine PHP 8.1 first call callables which look like function calls

This already is handled via the PassedParameters class.

Includes test in the WordPress.Security.ValidatedSanitizedInput test file.

ValidationHelper::is_validated(): various minor tweaks

Includes extra test for additionally added defensive coding.

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.

WordPress/Helpers/ValidationHelper.php Outdated Show resolved Hide resolved
jrfnl added 12 commits June 23, 2023 22:17
The `is_validated()` utility method is only used by a small set of sniffs, so is better placed in a dedicated class.

This commit moves the `is_validated()` method to the new `WordPressCS\WordPress\Helpers\ValidationHelper` class and starts using that class in the relevant sniffs.

The method has been made stand-alone and now expects the `$phpcsFile` to be passed to it.
The method signature has changed from `protected` to `public static`.

Related to 1465

This method will be tested via the `WordPress.Security.ValidatedSanitizedInput` sniff (via pre-existing tests).
... to allow for adding additional test case files testing specific (parse error) situations.
... in particular testing the defensive coding which is in place in the helper method.
Includes bug fix as the function name comparison was not done in a case-insensitive manner.

Tested by adjusting one of the existing tests.
…eters

Includes tests in the `WordPress.Security.ValidatedSanitizedInput` test file.
…ich may look like function calls

Includes test in the `WordPress.Security.ValidatedSanitizedInput` test file.
…llables which look like function calls

This already is handled via the `PassedParameters` class.

Includes test in the `WordPress.Security.ValidatedSanitizedInput` test file.
Includes extra test for additionally added defensive coding.
@jrfnl jrfnl force-pushed the feature/move-is-validated-and-improve branch from 5f7b100 to 946dffb Compare June 23, 2023 20:18
@dingo-d dingo-d merged commit 917d35d into develop Jun 25, 2023
@dingo-d dingo-d deleted the feature/move-is-validated-and-improve branch June 25, 2023 18:59
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