From 1893f2bc54e422d1158557f67b94d822793cdbce Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Wed, 18 Dec 2024 15:09:00 +0545 Subject: [PATCH 1/2] Add more methods in the exclusion list of alternative functions --- phpcs-rulesets/plugin-review.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpcs-rulesets/plugin-review.xml b/phpcs-rulesets/plugin-review.xml index e86c7a4a..a8bfc2ce 100644 --- a/phpcs-rulesets/plugin-review.xml +++ b/phpcs-rulesets/plugin-review.xml @@ -106,6 +106,8 @@ error + + From 6e93050861dff00a747135d0fdfb73bc77cd3a79 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Wed, 18 Dec 2024 15:19:57 +0545 Subject: [PATCH 2/2] Add test for updated function exclusion list --- .../plugins/test-plugin-review-phpcs-errors/load.php | 3 +++ .../Checker/Checks/Plugin_Review_PHPCS_Check_Tests.php | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/tests/phpunit/testdata/plugins/test-plugin-review-phpcs-errors/load.php b/tests/phpunit/testdata/plugins/test-plugin-review-phpcs-errors/load.php index c2ad33a6..6a2f6c26 100644 --- a/tests/phpunit/testdata/plugins/test-plugin-review-phpcs-errors/load.php +++ b/tests/phpunit/testdata/plugins/test-plugin-review-phpcs-errors/load.php @@ -36,3 +36,6 @@ $encoded_value = json_encode( array( 'key' => 'value' ) ); custom_function(&$myvar); + +file_get_contents( $url ); +file_put_contents(); diff --git a/tests/phpunit/tests/Checker/Checks/Plugin_Review_PHPCS_Check_Tests.php b/tests/phpunit/tests/Checker/Checks/Plugin_Review_PHPCS_Check_Tests.php index 509d3141..f395878c 100644 --- a/tests/phpunit/tests/Checker/Checks/Plugin_Review_PHPCS_Check_Tests.php +++ b/tests/phpunit/tests/Checker/Checks/Plugin_Review_PHPCS_Check_Tests.php @@ -54,6 +54,12 @@ public function test_run_with_errors() { // There should not be WordPress.WP.AlternativeFunctions.json_encode_json_encode error on Line no 36 and column no at 18. $this->assertCount( 0, wp_list_filter( $errors['load.php'][36][18], array( 'code' => 'WordPress.WP.AlternativeFunctions.json_encode_json_encode' ) ) ); + // There should not be WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents error on Line no 40 and column no 1. + $this->assertCount( 0, wp_list_filter( $errors['load.php'][40][1], array( 'code' => 'WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents' ) ) ); + + // There should not be WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents error on Line no 41 and column no 1. + $this->assertCount( 0, wp_list_filter( $errors['load.php'][41][1], array( 'code' => 'WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents' ) ) ); + // Check for WordPress.Security.ValidatedSanitizedInput warnings on Line no 15 and column no at 27. $this->assertCount( 1, wp_list_filter( $warnings['load.php'][15][27], array( 'code' => 'WordPress.Security.ValidatedSanitizedInput.InputNotValidated' ) ) ); $this->assertCount( 1, wp_list_filter( $warnings['load.php'][15][27], array( 'code' => 'WordPress.Security.ValidatedSanitizedInput.MissingUnslash' ) ) );