From 6ac41da7a9816f1324af9f2286f68054c67dc37d Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 19 Dec 2022 22:55:45 +0100 Subject: [PATCH 01/13] WP/AlternativeFunctions: order lists alphabetically Orders function name lists alphabetically. The group ordering, while not in alphabetic order, is left as-is for now. This commit does not add or delete any functions from the lists. --- .../Sniffs/WP/AlternativeFunctionsSniff.php | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php index dbca31c0a4..ad8b422eec 100644 --- a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php +++ b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php @@ -152,20 +152,20 @@ public function getGroups() { 'chgrp', 'chmod', 'chown', - 'is_writable', - 'is_writeable', - 'mkdir', - 'rmdir', - 'touch', - 'readfile', 'fclose', + 'file_put_contents', 'fopen', + 'fputs', 'fread', - 'fwrite', - 'file_put_contents', 'fsockopen', + 'fwrite', + 'is_writable', + 'is_writeable', + 'mkdir', 'pfsockopen', - 'fputs', + 'readfile', + 'rmdir', + 'touch', ), ), @@ -183,8 +183,8 @@ public function getGroups() { 'message' => '%s() is discouraged. Rand seeding is not necessary when using the wp_rand() function (as you should).', 'since' => '2.6.2', 'functions' => array( - 'srand', 'mt_srand', + 'srand', ), ), @@ -193,8 +193,8 @@ public function getGroups() { 'message' => '%s() is discouraged. Use the far less predictable wp_rand() instead.', 'since' => '2.6.2', 'functions' => array( - 'rand', 'mt_rand', + 'rand', ), ), ); @@ -287,9 +287,9 @@ public function process_matched_token( $stackPtr, $group_name, $matched_content break; - case 'readfile': - case 'fopen': case 'file_put_contents': + case 'fopen': + case 'readfile': /* * Allow for handling raw data streams from the request body. */ From 56a8cc9c61ef3599eff88d92961acb8ae21c6518 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 14 Dec 2022 17:33:30 +0100 Subject: [PATCH 02/13] WP/AlternativeFunctions: add missing `@since` tags ... for properties which were added to the sniff after the initial conception. --- WordPress/Sniffs/WP/AlternativeFunctionsSniff.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php index ad8b422eec..4fa5fa0d59 100644 --- a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php +++ b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php @@ -35,6 +35,8 @@ class AlternativeFunctionsSniff extends AbstractFunctionRestrictionsSniff { * * @link https://www.php.net/wrappers.php * + * @since 2.1.0 + * * @var array */ protected $allowed_local_streams = array( @@ -51,6 +53,8 @@ class AlternativeFunctionsSniff extends AbstractFunctionRestrictionsSniff { * * @link https://www.php.net/wrappers.php * + * @since 2.1.0 + * * @var array */ protected $allowed_local_stream_partials = array( @@ -63,6 +67,8 @@ class AlternativeFunctionsSniff extends AbstractFunctionRestrictionsSniff { * * @link https://www.php.net/wrappers.php * + * @since 2.1.0 + * * @var array */ protected $allowed_local_stream_constants = array( From 70154e55e2473a6f3b4eb95e76232939deb5e116 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 14 Dec 2022 17:37:32 +0100 Subject: [PATCH 03/13] WP/AlternativeFunctions: change property visibility ... from `protected` to `private` for properties which are only intended to be used by the sniff itself anyway. --- WordPress/Sniffs/WP/AlternativeFunctionsSniff.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php index 4fa5fa0d59..82bf8950a1 100644 --- a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php +++ b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php @@ -36,10 +36,11 @@ class AlternativeFunctionsSniff extends AbstractFunctionRestrictionsSniff { * @link https://www.php.net/wrappers.php * * @since 2.1.0 + * @since 3.0.0 The visibility was changed from `protected` to `private`. * * @var array */ - protected $allowed_local_streams = array( + private $allowed_local_streams = array( 'php://input' => true, 'php://output' => true, 'php://stdin' => true, @@ -54,10 +55,11 @@ class AlternativeFunctionsSniff extends AbstractFunctionRestrictionsSniff { * @link https://www.php.net/wrappers.php * * @since 2.1.0 + * @since 3.0.0 The visibility was changed from `protected` to `private`. * * @var array */ - protected $allowed_local_stream_partials = array( + private $allowed_local_stream_partials = array( 'php://temp/', 'php://fd/', ); @@ -68,10 +70,11 @@ class AlternativeFunctionsSniff extends AbstractFunctionRestrictionsSniff { * @link https://www.php.net/wrappers.php * * @since 2.1.0 + * @since 3.0.0 The visibility was changed from `protected` to `private`. * * @var array */ - protected $allowed_local_stream_constants = array( + private $allowed_local_stream_constants = array( 'STDIN' => true, 'STDOUT' => true, 'STDERR' => true, From b503057cf88fa90c0f1b070454762a9c8f5db7a3 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 15 Dec 2022 07:26:45 +0100 Subject: [PATCH 04/13] WP/AlternativeFunctions: remove stray blank lines at top of test file --- .../Tests/WP/AlternativeFunctionsUnitTest.inc | 2 -- .../Tests/WP/AlternativeFunctionsUnitTest.php | 25 +++++++++---------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc index ea9baea449..a2e8c0489b 100644 --- a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc +++ b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc @@ -1,7 +1,5 @@ 1, + 4 => 1, 5 => 1, - 6 => 1, - 7 => 1, + 8 => 1, 10 => 1, 12 => 1, 14 => 1, + 15 => 1, 16 => 1, 17 => 1, 18 => 1, @@ -54,17 +56,17 @@ public function getWarningList() { 24 => 1, 25 => 1, 26 => 1, - 27 => 1, - 28 => 1, - 40 => 1, + 38 => 1, + 42 => 1, 44 => 1, - 46 => 1, + 45 => 1, 47 => 1, - 49 => 1, - 67 => 1, - 68 => 1, - 73 => 1, + 65 => 1, + 66 => 1, + 71 => 1, + 78 => 1, 80 => 1, + 81 => 1, 82 => 1, 83 => 1, 84 => 1, @@ -74,9 +76,6 @@ public function getWarningList() { 88 => 1, 89 => 1, 90 => 1, - 91 => 1, - 92 => 1, ); } - } From 744e83bb363b0d46fe19b835100674d2afd424f7 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 15 Dec 2022 07:31:57 +0100 Subject: [PATCH 05/13] WP/AlternativeFunctions: move parse_url related tests down --- .../Tests/WP/AlternativeFunctionsUnitTest.inc | 20 ++++++------ .../Tests/WP/AlternativeFunctionsUnitTest.php | 32 +++++++++---------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc index a2e8c0489b..dcc220034b 100644 --- a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc +++ b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc @@ -26,18 +26,8 @@ srand(); // Warning. mt_srand(); // Warning. wp_rand(); // OK. -// phpcs:set WordPress.WP.AlternativeFunctions minimum_wp_version 4.0 -parse_url( 'http://example.com/' ); // OK. -// phpcs:set WordPress.WP.AlternativeFunctions minimum_wp_version 4.6 - strip_tags( $something, '