From c95b44b6e6dab9e7bc50dee62ee65ba67901bfae Mon Sep 17 00:00:00 2001 From: Rebecca Hum Date: Wed, 28 Nov 2018 12:37:16 -0700 Subject: [PATCH 001/241] Remove get_the_title() from list of autoescaped functions since admins can enter HTML into the title field. --- WordPress/Sniff.php | 1 - WordPress/Tests/Security/EscapeOutputUnitTest.inc | 4 ++++ WordPress/Tests/Security/EscapeOutputUnitTest.php | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 07a0f4693d..c43d0e5bda 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -231,7 +231,6 @@ abstract class Sniff implements PHPCS_Sniff { 'get_the_ID' => true, 'get_the_post_thumbnail' => true, 'get_the_term_list' => true, - 'get_the_title' => true, 'next_comments_link' => true, 'next_image_link' => true, 'next_post_link' => true, diff --git a/WordPress/Tests/Security/EscapeOutputUnitTest.inc b/WordPress/Tests/Security/EscapeOutputUnitTest.inc index 4a804da85a..d27ec631f1 100644 --- a/WordPress/Tests/Security/EscapeOutputUnitTest.inc +++ b/WordPress/Tests/Security/EscapeOutputUnitTest.inc @@ -285,3 +285,7 @@ echo // phpcs:ignore WP.Secur1ty.EscapeOutput -- WPCS: XSS ok. (sniff name mang echo esc_html( $something ), $something_else, esc_html( $something_more ); // phpcs:ignore WP.Secur1ty.EscapeOutput -- WPCS: XSS ok. (sniff name mangled on purpose). + +echo get_the_title(); // Bad. +echo wp_kses_post( get_the_title() ); // Ok. +echo esc_html( get_the_title() ); // Ok. diff --git a/WordPress/Tests/Security/EscapeOutputUnitTest.php b/WordPress/Tests/Security/EscapeOutputUnitTest.php index bb33ed5fee..be2ef97053 100644 --- a/WordPress/Tests/Security/EscapeOutputUnitTest.php +++ b/WordPress/Tests/Security/EscapeOutputUnitTest.php @@ -78,6 +78,7 @@ public function getErrorList() { 263 => 1, 264 => 1, 266 => 1, + 289 => 1, ); } From b3786f32fdaae4a3eaf92fe95213e17a4c2d62b4 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 4 Nov 2018 20:16:55 +0100 Subject: [PATCH 002/241] Minor CS/QA fixes --- WordPress/Sniff.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 07a0f4693d..32b9264792 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -2390,7 +2390,7 @@ public function get_declared_namespace_name( $stackPtr ) { \T_STRING => true, \T_NS_SEPARATOR => true, ); - $validTokens = $acceptedTokens + Tokens::$emptyTokens; + $validTokens = $acceptedTokens + Tokens::$emptyTokens; $namespaceName = ''; while ( isset( $validTokens[ $this->tokens[ $nextToken ]['code'] ] ) ) { @@ -2493,7 +2493,7 @@ public function is_class_property( $stackPtr ) { $deepest_open = array_pop( $parenthesis ); if ( $deepest_open < $scopePtr || isset( $this->tokens[ $deepest_open ]['parenthesis_owner'] ) === false - || T_FUNCTION !== $this->tokens[ $this->tokens[ $deepest_open ]['parenthesis_owner'] ]['code'] + || \T_FUNCTION !== $this->tokens[ $this->tokens[ $deepest_open ]['parenthesis_owner'] ]['code'] ) { return true; } From 6df379d6ec488fbd459b99386471d6bb506aeb2a Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 04:40:48 +0100 Subject: [PATCH 003/241] Update default minimum_supported_version to WP 4.7 The minimum version should be three versions behind the latest WP release, so what with 5.0 having come out last week, it should now be 4.7. --- WordPress/Sniff.php | 2 +- WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc | 8 ++++---- WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php | 7 ++++--- WordPress/Tests/WP/DeprecatedParametersUnitTest.inc | 2 +- phpcs.xml.dist.sample | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 07a0f4693d..3323758848 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -82,7 +82,7 @@ abstract class Sniff implements PHPCS_Sniff { * * @var string WordPress version. */ - public $minimum_supported_version = '4.6'; + public $minimum_supported_version = '4.7'; /** * Custom list of classes which test classes can extend. diff --git a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc index a2d83c015d..55b5107e2f 100644 --- a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc +++ b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc @@ -315,14 +315,14 @@ get_comments_popup_template(); get_currentuserinfo(); is_comments_popup(); use function popuplinks as something_else; // Related to issue #1306. - -/* - * Warning. - */ /* ============ WP 4.6 ============ */ post_form_autocomplete_off(); wp_embed_handler_googlevideo(); wp_get_sites(); + +/* + * Warning. + */ /* ============ WP 4.7 ============ */ _sort_nav_menu_items(); _usort_terms_by_ID(); diff --git a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php index 9457a77234..f9bbc40a27 100644 --- a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php @@ -28,7 +28,7 @@ class DeprecatedFunctionsUnitTest extends AbstractSniffUnitTest { */ public function getErrorList() { - $errors = array_fill( 8, 310, 1 ); + $errors = array_fill( 8, 314, 1 ); // Unset the lines related to version comments. unset( @@ -59,7 +59,8 @@ public function getErrorList() { $errors[290], $errors[295], $errors[303], - $errors[310] + $errors[310], + $errors[318] ); return $errors; @@ -72,7 +73,7 @@ public function getErrorList() { */ public function getWarningList() { - $warnings = array_fill( 323, 17, 1 ); + $warnings = array_fill( 326, 14, 1 ); // Unset the lines related to version comments. unset( $warnings[326], $warnings[333], $warnings[335] ); diff --git a/WordPress/Tests/WP/DeprecatedParametersUnitTest.inc b/WordPress/Tests/WP/DeprecatedParametersUnitTest.inc index ba7c2a9c7c..7e35ad422a 100644 --- a/WordPress/Tests/WP/DeprecatedParametersUnitTest.inc +++ b/WordPress/Tests/WP/DeprecatedParametersUnitTest.inc @@ -60,7 +60,7 @@ wp_title_rss( 'deprecated' ); wp_upload_bits( '', 'deprecated' ); xfn_check( '', '', 'deprecated' ); -// All will give an WARNING as they have been deprecated after WP 4.5. +// All will give an WARNING as they have been deprecated after WP 4.7. get_category_parents( '', '', '', '', array( 'deprecated') ); unregister_setting( '', '', '', 'deprecated' ); diff --git a/phpcs.xml.dist.sample b/phpcs.xml.dist.sample index 4563369602..d0fe264fe3 100644 --- a/phpcs.xml.dist.sample +++ b/phpcs.xml.dist.sample @@ -69,7 +69,7 @@ the wiki: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties --> - + From 232d26ffdf11fe6967d3608a6d3766c85046e319 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 16 Dec 2018 13:05:06 +0100 Subject: [PATCH 004/241] Minor documentation fixes --- WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php b/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php index daf9c4a8d6..e243c3d82a 100644 --- a/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php +++ b/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php @@ -121,7 +121,7 @@ class I18nTextDomainFixerSniff extends AbstractFunctionParameterSniff { * * @since 1.2.0 * - * @var string + * @var bool */ private $is_valid = false; @@ -139,7 +139,7 @@ class I18nTextDomainFixerSniff extends AbstractFunctionParameterSniff { * * @since 1.2.0 * - * @var string + * @var bool */ private $header_found = false; From 6354a2aead0be300d97764e43293270250602793 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 16 Dec 2018 16:02:00 +0100 Subject: [PATCH 005/241] Docs ruleset: Minor tweaks * Move one exclusion into a block of exclusions for the same sniff. * Exclude a complete sniff where all errorcodes from that sniff were excluded anyway. --- WordPress-Docs/ruleset.xml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/WordPress-Docs/ruleset.xml b/WordPress-Docs/ruleset.xml index 3a95dd6cff..02abd0e73d 100644 --- a/WordPress-Docs/ruleset.xml +++ b/WordPress-Docs/ruleset.xml @@ -61,6 +61,8 @@ + + @@ -81,9 +83,6 @@ - - - @@ -105,8 +104,6 @@ - - - + From 1656d2a5f3fe2035de87403cec522dc270a4ccc0 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Mon, 7 May 2018 21:12:37 +0100 Subject: [PATCH 006/241] Remove all functions from the auto escape list that don't return a value. --- WordPress/Sniff.php | 75 --------------------------------------------- 1 file changed, 75 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 4a025cea99..ca7ca0bad8 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -178,40 +178,11 @@ abstract class Sniff implements PHPCS_Sniff { 'calendar_week_mod' => true, 'category_description' => true, 'checked' => true, - 'comment_author_email_link' => true, - 'comment_author_email' => true, - 'comment_author_IP' => true, - 'comment_author_link' => true, - 'comment_author_rss' => true, - 'comment_author_url_link' => true, - 'comment_author_url' => true, - 'comment_author' => true, 'comment_class' => true, - 'comment_date' => true, - 'comment_excerpt' => true, - 'comment_form_title' => true, - 'comment_form' => true, - 'comment_id_fields' => true, - 'comment_ID' => true, - 'comment_reply_link' => true, - 'comment_text_rss' => true, - 'comment_text' => true, - 'comment_time' => true, - 'comment_type' => true, - 'comments_link' => true, - 'comments_number' => true, - 'comments_popup_link' => true, - 'comments_popup_script' => true, - 'comments_rss_link' => true, 'count' => true, - 'delete_get_calendar_cache' => true, 'disabled' => true, 'do_shortcode' => true, 'do_shortcode_tag' => true, - 'edit_bookmark_link' => true, - 'edit_comment_link' => true, - 'edit_post_link' => true, - 'edit_tag_link' => true, 'get_archives_link' => true, 'get_attachment_link' => true, 'get_avatar' => true, @@ -220,29 +191,16 @@ abstract class Sniff implements PHPCS_Sniff { 'get_comment_author_link' => true, 'get_current_blog_id' => true, 'get_delete_post_link' => true, - 'get_footer' => true, - 'get_header' => true, 'get_search_form' => true, 'get_search_query' => true, - 'get_sidebar' => true, 'get_the_author_link' => true, 'get_the_author' => true, 'get_the_date' => true, 'get_the_ID' => true, 'get_the_post_thumbnail' => true, 'get_the_term_list' => true, - 'next_comments_link' => true, - 'next_image_link' => true, - 'next_post_link' => true, - 'next_posts_link' => true, 'paginate_comments_links' => true, - 'permalink_anchor' => true, 'post_type_archive_title' => true, - 'posts_nav_link' => true, - 'previous_comments_link' => true, - 'previous_image_link' => true, - 'previous_post_link' => true, - 'previous_posts_link' => true, 'readonly' => true, 'selected' => true, 'single_cat_title' => true, @@ -250,45 +208,15 @@ abstract class Sniff implements PHPCS_Sniff { 'single_post_title' => true, 'single_tag_title' => true, 'single_term_title' => true, - 'sticky_class' => true, 'tag_description' => true, 'term_description' => true, - 'the_attachment_link' => true, - 'the_author_link' => true, - 'the_author_meta' => true, - 'the_author_posts_link' => true, - 'the_author_posts' => true, 'the_author' => true, - 'the_category_rss' => true, - 'the_category' => true, - 'the_content_rss' => true, - 'the_content' => true, - 'the_date_xml' => true, 'the_date' => true, - 'the_excerpt_rss' => true, - 'the_excerpt' => true, - 'the_feed_link' => true, - 'the_ID' => true, - 'the_meta' => true, - 'the_modified_author' => true, - 'the_modified_date' => true, - 'the_modified_time' => true, - 'the_permalink' => true, - 'the_post_thumbnail' => true, - 'the_search_query' => true, - 'the_shortlink' => true, - 'the_tags' => true, - 'the_taxonomies' => true, - 'the_terms' => true, - 'the_time' => true, 'the_title_attribute' => true, - 'the_title_rss' => true, - 'the_title' => true, 'vip_powered_wpcom' => true, 'walk_nav_menu_tree' => true, 'wp_dropdown_categories' => true, 'wp_dropdown_users' => true, - 'wp_enqueue_script' => true, 'wp_generate_tag_cloud' => true, 'wp_get_archives' => true, 'wp_get_attachment_image' => true, @@ -300,11 +228,8 @@ abstract class Sniff implements PHPCS_Sniff { 'wp_list_comments' => true, 'wp_login_form' => true, 'wp_loginout' => true, - 'wp_meta' => true, 'wp_nav_menu' => true, 'wp_register' => true, - 'wp_shortlink_header' => true, - 'wp_shortlink_wp_head' => true, 'wp_tag_cloud' => true, 'wp_title' => true, ); From 3cd9400d858268e1bd2689717e3644b540fac7e2 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 17 Dec 2018 00:22:56 +0100 Subject: [PATCH 007/241] Changelog for WPCS version 1.2.1 * Release date set at this Tuesday December 18th. * Includes all currently merged changes. --- CHANGELOG.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbcbc75b88..97a14f7ab8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,22 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a _No documentation available about unreleased changes as of yet._ +## [1.2.1] - 2018-12-18 + +Note: This will be the last release supporting PHP_CodeSniffer 2.x. + +### Changed +- The default value for `minimum_supported_wp_version`, as used by a [number of sniffs detecting usage of deprecated WP features](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#minimum-wp-version-to-check-for-usage-of-deprecated-functions-classes-and-function-parameters), has been updated to `4.7`. +- The `WordPress.NamingConventions.PrefixAllGlobals` sniff will now report the error for hook names and constant names declared with `define()` on the line containing the parameter for the hook/constant name. Previously, it would report the error on the line containing the function call. +- Various minor housekeeping fixes to inline documentation, rulesets, code. + +### Removed +- `comment_author_email_link()`, `comment_author_email()`, `comment_author_IP()`, `comment_author_link()`, `comment_author_rss()`, `comment_author_url_link()`, `comment_author_url()`, `comment_author()`, `comment_date()`, `comment_excerpt()`, `comment_form_title()`, `comment_form()`, `comment_id_fields()`, `comment_ID()`, `comment_reply_link()`, `comment_text_rss()`, `comment_text()`, `comment_time()`, `comment_type()`, `comments_link()`, `comments_number()`, `comments_popup_link()`, `comments_popup_script()`, `comments_rss_link()`, `delete_get_calendar_cache()`, `edit_bookmark_link()`, `edit_comment_link()`, `edit_post_link()`, `edit_tag_link()`, `get_footer()`, `get_header()`, `get_sidebar()`, `get_the_title()`, `next_comments_link()`, `next_image_link()`, `next_post_link()`, `next_posts_link()`, `permalink_anchor()`, `posts_nav_link()`, `previous_comments_link()`, `previous_image_link()`, `previous_post_link()`, `previous_posts_link()`, `sticky_class()`, `the_attachment_link()`, `the_author_link()`, `the_author_meta()`, `the_author_posts_link()`, `the_author_posts()`, `the_category_rss()`, `the_category()`, `the_content_rss()`, `the_content()`, `the_date_xml()`, `the_excerpt_rss()`, `the_excerpt()`, `the_feed_link()`, `the_ID()`, `the_meta()`, `the_modified_author()`, `the_modified_date()`, `the_modified_time()`, `the_permalink()`, `the_post_thumbnail()`, `the_search_query()`, `the_shortlink()`, `the_tags()`, `the_taxonomies()`, `the_terms()`, `the_time()`, `the_title_rss()`, `the_title()`, `wp_enqueue_script()`, `wp_meta()`, `wp_shortlink_header()` and `wp_shortlink_wp_head()` from the list of auto-escaped functions `Sniff::$autoEscapedFunctions`. This affects the `WordPress.Security.EscapeOutput` sniff. + +### Fixed +- The `WordPress.WhiteSpace.PrecisionAlignment` sniff would loose the value of a custom set `ignoreAlignmentTokens` property when scanning more than one file. + + ## [1.2.0] - 2018-11-12 ### Added @@ -810,6 +826,7 @@ See the comparison for full list. Initial tagged release. [Unreleased]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/master...HEAD +[1.2.1]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.2.0...1.2.1 [1.2.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.1.0...1.2.0 [1.1.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.0.0...1.1.0 [1.0.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/0.14.1...1.0.0 From 239ce3f33ed765f448cb85d95e64e81b034995ac Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 04:01:30 +0100 Subject: [PATCH 008/241] WPCS 2.0.0: Remove the deprecated VIP ruleset and sniffs The VIP ruleset and sniffs were deprecated in WPCS 1.0.0 and will now be removed for WPCS 2.0.0. --- .travis.yml | 2 - README.md | 7 +- WordPress-VIP/ruleset.xml | 231 --------- WordPress/Sniff.php | 1 - WordPress/Sniffs/VIP/AdminBarRemovalSniff.php | 465 ------------------ WordPress/Sniffs/VIP/CronIntervalSniff.php | 89 ---- .../Sniffs/VIP/DirectDatabaseQuerySniff.php | 78 --- .../VIP/FileSystemWritesDisallowSniff.php | 152 ------ WordPress/Sniffs/VIP/OrderByRandSniff.php | 107 ---- WordPress/Sniffs/VIP/PluginMenuSlugSniff.php | 65 --- WordPress/Sniffs/VIP/PostsPerPageSniff.php | 105 ---- .../Sniffs/VIP/RestrictedFunctionsSniff.php | 280 ----------- .../Sniffs/VIP/RestrictedVariablesSniff.php | 113 ----- .../Sniffs/VIP/SessionFunctionsUsageSniff.php | 126 ----- .../Sniffs/VIP/SessionVariableUsageSniff.php | 81 --- WordPress/Sniffs/VIP/SlowDBQuerySniff.php | 76 --- .../Sniffs/VIP/SuperGlobalInputUsageSniff.php | 87 ---- WordPress/Sniffs/VIP/TimezoneChangeSniff.php | 75 --- .../VIP/ValidatedSanitizedInputSniff.php | 77 --- .../ArrayDeclarationSpacingUnitTest.1.inc | 4 +- ...rrayDeclarationSpacingUnitTest.1.inc.fixed | 4 +- .../ArrayDeclarationSpacingUnitTest.2.inc | 4 +- ...rrayDeclarationSpacingUnitTest.2.inc.fixed | 4 +- .../Tests/VIP/AdminBarRemovalUnitTest.css | 55 --- .../Tests/VIP/AdminBarRemovalUnitTest.inc | 108 ---- .../Tests/VIP/AdminBarRemovalUnitTest.php | 105 ---- WordPress/Tests/VIP/CronIntervalUnitTest.inc | 6 - WordPress/Tests/VIP/CronIntervalUnitTest.php | 48 -- .../Tests/VIP/DirectDatabaseQueryUnitTest.inc | 6 - .../Tests/VIP/DirectDatabaseQueryUnitTest.php | 46 -- .../VIP/FileSystemWritesDisallowUnitTest.inc | 49 -- .../VIP/FileSystemWritesDisallowUnitTest.php | 68 --- WordPress/Tests/VIP/OrderByRandUnitTest.inc | 18 - WordPress/Tests/VIP/OrderByRandUnitTest.php | 51 -- .../Tests/VIP/PluginMenuSlugUnitTest.inc | 3 - .../Tests/VIP/PluginMenuSlugUnitTest.php | 46 -- WordPress/Tests/VIP/PostsPerPageUnitTest.inc | 24 - WordPress/Tests/VIP/PostsPerPageUnitTest.php | 54 -- .../Tests/VIP/RestrictedFunctionsUnitTest.inc | 89 ---- .../Tests/VIP/RestrictedFunctionsUnitTest.php | 77 --- .../Tests/VIP/RestrictedVariablesUnitTest.inc | 34 -- .../Tests/VIP/RestrictedVariablesUnitTest.php | 54 -- .../VIP/SessionFunctionsUsageUnitTest.inc | 34 -- .../VIP/SessionFunctionsUsageUnitTest.php | 44 -- .../VIP/SessionVariableUsageUnitTest.inc | 4 - .../VIP/SessionVariableUsageUnitTest.php | 47 -- WordPress/Tests/VIP/SlowDBQueryUnitTest.inc | 6 - WordPress/Tests/VIP/SlowDBQueryUnitTest.php | 48 -- .../VIP/SuperGlobalInputUsageUnitTest.inc | 23 - .../VIP/SuperGlobalInputUsageUnitTest.php | 47 -- .../Tests/VIP/TimezoneChangeUnitTest.inc | 6 - .../Tests/VIP/TimezoneChangeUnitTest.php | 49 -- .../VIP/ValidatedSanitizedInputUnitTest.inc | 6 - .../VIP/ValidatedSanitizedInputUnitTest.php | 49 -- WordPress/ruleset.xml | 12 +- bin/class-ruleset-test.php | 1 - 56 files changed, 12 insertions(+), 3538 deletions(-) delete mode 100644 WordPress-VIP/ruleset.xml delete mode 100644 WordPress/Sniffs/VIP/AdminBarRemovalSniff.php delete mode 100644 WordPress/Sniffs/VIP/CronIntervalSniff.php delete mode 100644 WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php delete mode 100644 WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php delete mode 100644 WordPress/Sniffs/VIP/OrderByRandSniff.php delete mode 100644 WordPress/Sniffs/VIP/PluginMenuSlugSniff.php delete mode 100644 WordPress/Sniffs/VIP/PostsPerPageSniff.php delete mode 100644 WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php delete mode 100644 WordPress/Sniffs/VIP/RestrictedVariablesSniff.php delete mode 100644 WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php delete mode 100644 WordPress/Sniffs/VIP/SessionVariableUsageSniff.php delete mode 100644 WordPress/Sniffs/VIP/SlowDBQuerySniff.php delete mode 100644 WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php delete mode 100644 WordPress/Sniffs/VIP/TimezoneChangeSniff.php delete mode 100644 WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php delete mode 100644 WordPress/Tests/VIP/AdminBarRemovalUnitTest.css delete mode 100644 WordPress/Tests/VIP/AdminBarRemovalUnitTest.inc delete mode 100644 WordPress/Tests/VIP/AdminBarRemovalUnitTest.php delete mode 100644 WordPress/Tests/VIP/CronIntervalUnitTest.inc delete mode 100644 WordPress/Tests/VIP/CronIntervalUnitTest.php delete mode 100644 WordPress/Tests/VIP/DirectDatabaseQueryUnitTest.inc delete mode 100644 WordPress/Tests/VIP/DirectDatabaseQueryUnitTest.php delete mode 100644 WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.inc delete mode 100644 WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php delete mode 100644 WordPress/Tests/VIP/OrderByRandUnitTest.inc delete mode 100644 WordPress/Tests/VIP/OrderByRandUnitTest.php delete mode 100644 WordPress/Tests/VIP/PluginMenuSlugUnitTest.inc delete mode 100644 WordPress/Tests/VIP/PluginMenuSlugUnitTest.php delete mode 100644 WordPress/Tests/VIP/PostsPerPageUnitTest.inc delete mode 100644 WordPress/Tests/VIP/PostsPerPageUnitTest.php delete mode 100644 WordPress/Tests/VIP/RestrictedFunctionsUnitTest.inc delete mode 100644 WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php delete mode 100644 WordPress/Tests/VIP/RestrictedVariablesUnitTest.inc delete mode 100644 WordPress/Tests/VIP/RestrictedVariablesUnitTest.php delete mode 100644 WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.inc delete mode 100644 WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.php delete mode 100644 WordPress/Tests/VIP/SessionVariableUsageUnitTest.inc delete mode 100644 WordPress/Tests/VIP/SessionVariableUsageUnitTest.php delete mode 100644 WordPress/Tests/VIP/SlowDBQueryUnitTest.inc delete mode 100644 WordPress/Tests/VIP/SlowDBQueryUnitTest.php delete mode 100644 WordPress/Tests/VIP/SuperGlobalInputUsageUnitTest.inc delete mode 100644 WordPress/Tests/VIP/SuperGlobalInputUsageUnitTest.php delete mode 100644 WordPress/Tests/VIP/TimezoneChangeUnitTest.inc delete mode 100644 WordPress/Tests/VIP/TimezoneChangeUnitTest.php delete mode 100644 WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.inc delete mode 100644 WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.php diff --git a/.travis.yml b/.travis.yml index 29f5e6fe61..74ad0a2745 100644 --- a/.travis.yml +++ b/.travis.yml @@ -108,7 +108,6 @@ script: - if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress-Core; fi - if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress-Docs; fi - if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress-Extra; fi - - if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress-VIP; fi - if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress; fi # WordPress Coding Standards. # @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards @@ -123,7 +122,6 @@ script: - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-Core/ruleset.xml <(xmllint --format "./WordPress-Core/ruleset.xml"); fi - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-Docs/ruleset.xml <(xmllint --format "./WordPress-Docs/ruleset.xml"); fi - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-Extra/ruleset.xml <(xmllint --format "./WordPress-Extra/ruleset.xml"); fi - - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-VIP/ruleset.xml <(xmllint --format "./WordPress-VIP/ruleset.xml"); fi - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./phpcs.xml.dist.sample <(xmllint --format "./phpcs.xml.dist.sample"); fi # Validate the composer.json file. # @link https://getcomposer.org/doc/03-cli.md#validate diff --git a/README.md b/README.md index eb903125a1..d672ea0ed4 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ You should then see `WordPress-Core` et al listed when you run `phpcs -i`. ### Standards subsets -The project encompasses a super-set of the sniffs that the WordPress community may need. If you use the `WordPress` standard you will get all the checks. Some of them might be unnecessary for your environment, for example, those specific to WordPress.com VIP coding requirements. +The project encompasses a super-set of the sniffs that the WordPress community may need. If you use the `WordPress` standard you will get all the checks. You can use the following as standard names when invoking `phpcs` to select sniffs, fitting your needs: @@ -137,9 +137,8 @@ You can use the following as standard names when invoking `phpcs` to select snif - `WordPress-Extra` - extended ruleset for recommended best practices, not sufficiently covered in the WordPress core coding standards - includes `WordPress-Core` -**Notes:** This WPCS package contains the sniffs for another ruleset, `WordPress-VIP`. This ruleset was originally intended to aid with the [WordPress.com VIP coding requirements](https://vip.wordpress.com/documentation/vip-go/code-review-blockers-warnings-notices/), but this is no longer used or recommended by the WordPress.com VIP team or their clients, since they prefer to use their [official VIP coding standards](https://github.com/Automattic/VIP-Coding-Standards) ruleset instead. - -Before WPCS `1.0.0`, the WordPress-VIP ruleset was included as part of the complete `WordPress` ruleset. **As of `1.0.0` the `WordPress-VIP` ruleset is not part of the WordPress ruleset, and it is deprecated**. The remaining `WordPress-VIP` sniffs may still be referenced in custom rulesets, so to maintain some backwards compatibility, they will remain in WPCS until `2.0.0`. See [#1309](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1309) for more information. +**Note:** The WPCS package used to include a `WordPress-VIP` ruleset and associated sniffs, prior to WPCS 2.0.0. +The `WordPress-VIP` ruleset was originally intended to aid with the [WordPress.com VIP coding requirements](https://vip.wordpress.com/documentation/vip-go/code-review-blockers-warnings-notices/), but has been superseded. It is recommended to use the [official VIP coding standards](https://github.com/Automattic/VIP-Coding-Standards) ruleset instead for checking code against the VIP platform requirements. ### Using a custom ruleset diff --git a/WordPress-VIP/ruleset.xml b/WordPress-VIP/ruleset.xml deleted file mode 100644 index 202b3bc872..0000000000 --- a/WordPress-VIP/ruleset.xml +++ /dev/null @@ -1,231 +0,0 @@ - - - Deprecated WordPress.com VIP Coding Standards. Use the official VIP coding standards instead which can be found at https://github.com/Automattic/VIP-Coding-Standards - - - - - ./../WordPress/PHPCSAliases.php - - - - - - - - - - - - - - - - - - - - - - - - - - - error - - - - - error - - - error - - - - - - - - Using cURL functions is highly discouraged within VIP context. Check (Fetching Remote Data) on VIP Documentation. - - - %s() is highly discouraged, please use vip_safe_wp_remote_get() instead. - - - - - - - error - Attempting a database schema change is highly discouraged. - - - error - Usage of a direct database call without caching is prohibited on the VIP platform. Use wp_cache_get / wp_cache_set or wp_cache_delete. - - - - - - - error - - - - - error - Scheduling crons at %s sec ( less than %s minutes ) is prohibited. - - - - - - - error - - - error - - - - - - - - - 0 - - - - - 0 - - - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - - 0 - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index ca7ca0bad8..461faad62f 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -213,7 +213,6 @@ abstract class Sniff implements PHPCS_Sniff { 'the_author' => true, 'the_date' => true, 'the_title_attribute' => true, - 'vip_powered_wpcom' => true, 'walk_nav_menu_tree' => true, 'wp_dropdown_categories' => true, 'wp_dropdown_users' => true, diff --git a/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php b/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php deleted file mode 100644 index ba8208c601..0000000000 --- a/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php +++ /dev/null @@ -1,465 +0,0 @@ - false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * A list of tokenizers this sniff supports. - * - * @since 0.11.0 - * - * @var array - */ - public $supportedTokenizers = array( 'PHP', 'CSS' ); - - /** - * Whether or not the sniff only checks for removal of the admin bar - * or any manipulation to the visibility of the admin bar. - * - * Defaults to true: only check for removal of the admin bar. - * Set to false to check for any form of manipulation of the visibility - * of the admin bar. - * - * @since 0.11.0 - * - * @var bool - */ - public $remove_only = true; - - /** - * Functions this sniff is looking for. - * - * @since 0.11.0 - * - * @var array - */ - protected $target_functions = array( - 'show_admin_bar' => true, - 'add_filter' => true, - ); - - /** - * CSS properties this sniff is looking for. - * - * @since 0.11.0 - * - * @var array - */ - protected $target_css_properties = array( - 'visibility' => array( - 'type' => '!=', - 'value' => 'hidden', - ), - 'display' => array( - 'type' => '!=', - 'value' => 'none', - ), - 'opacity' => array( - 'type' => '>', - 'value' => 0.3, - ), - ); - - /** - * CSS selectors this sniff is looking for. - * - * @since 0.11.0 - * - * @var array - */ - protected $target_css_selectors = array( - '.show-admin-bar', - '#wpadminbar', - ); - - /** - * String tokens within PHP files we want to deal with. - * - * Set from the register() method. - * - * @since 0.11.0 - * - * @var array - */ - private $string_tokens = array(); - - /** - * Regex template for use with the CSS selectors in combination with PHP text strings. - * - * @since 0.11.0 - * - * @var string - */ - private $target_css_selectors_regex = '`(?:%s).*?\{(.*)$`'; - - /** - * Property to keep track of whether a ' ) ) { - // Make sure we check any content on this line before the closing style tag. - $this->in_style[ $file_name ] = false; - $content = trim( substr( $content, 0, strpos( $content, '' ) ) ); - } - } elseif ( true === $this->has_html_open_tag( 'style', $stackPtr, $content ) ) { - // Ok, found a ' ) ) { - // Make sure we check any content on this line after the opening style tag. - $this->in_style[ $file_name ] = true; - $content = trim( substr( $content, ( strpos( $content, '' ); - $content = trim( substr( $content, $start, ( $end - $start ) ) ); - unset( $start, $end ); - } - } else { - return; - } - - // Are we in one of the target selectors ? - if ( true === $this->in_target_selector[ $file_name ] ) { - if ( false !== strpos( $content, '}' ) ) { - // Make sure we check any content on this line before the selector closing brace. - $this->in_target_selector[ $file_name ] = false; - $content = trim( substr( $content, 0, strpos( $content, '}' ) ) ); - } - } elseif ( preg_match( $this->target_css_selectors_regex, $content, $matches ) > 0 ) { - // Ok, found a new target selector. - $content = ''; - - if ( isset( $matches[1] ) && '' !== $matches[1] ) { - if ( false === strpos( $matches[1], '}' ) ) { - // Make sure we check any content on this line before the closing brace. - $this->in_target_selector[ $file_name ] = true; - $content = trim( $matches[1] ); - } else { - // Ok, we have the selector open and close brace on the same line. - $content = trim( substr( $matches[1], 0, strpos( $matches[1], '}' ) ) ); - } - } else { - $this->in_target_selector[ $file_name ] = true; - } - } else { - return; - } - unset( $matches ); - - // Now let's do the check for the CSS properties. - if ( ! empty( $content ) ) { - foreach ( $this->target_css_properties as $property => $requirements ) { - if ( false !== strpos( $content, $property ) ) { - $error = true; - - if ( true === $this->remove_only ) { - // Check the value of the CSS property. - if ( preg_match( '`' . preg_quote( $property, '`' ) . '\s*:\s*(.+?)\s*(?:!important)?;`', $content, $matches ) > 0 ) { - $value = trim( $matches[1] ); - $valid = $this->validate_css_property_value( $value, $requirements['type'], $requirements['value'] ); - if ( true === $valid ) { - $error = false; - } - } - } - - if ( true === $error ) { - $this->phpcsFile->addError( 'Hiding of the admin bar is not allowed.', $stackPtr, 'HidingDetected' ); - } - } - } - } - } - - /** - * Processes this test for T_STYLE tokens in CSS files. - * - * @since 0.11.0 - * - * @param int $stackPtr The position of the current token in the stack passed in $tokens. - * - * @return void - */ - protected function process_css_style( $stackPtr ) { - if ( ! isset( $this->target_css_properties[ $this->tokens[ $stackPtr ]['content'] ] ) ) { - // Not one of the CSS properties we're interested in. - return; - } - - $css_property = $this->target_css_properties[ $this->tokens[ $stackPtr ]['content'] ]; - - // Check if the CSS selector matches. - $opener = $this->phpcsFile->findPrevious( \T_OPEN_CURLY_BRACKET, $stackPtr ); - if ( false !== $opener ) { - for ( $i = ( $opener - 1 ); $i >= 0; $i-- ) { - if ( isset( Tokens::$commentTokens[ $this->tokens[ $i ]['code'] ] ) - || \T_CLOSE_CURLY_BRACKET === $this->tokens[ $i ]['code'] - ) { - break; - } - } - $start = ( $i + 1 ); - $selector = trim( $this->phpcsFile->getTokensAsString( $start, ( $opener - $start ) ) ); - unset( $i ); - - foreach ( $this->target_css_selectors as $target_selector ) { - if ( false !== strpos( $selector, $target_selector ) ) { - $error = true; - - if ( true === $this->remove_only ) { - // Check the value of the CSS property. - $valuePtr = $this->phpcsFile->findNext( array( \T_COLON, \T_WHITESPACE ), ( $stackPtr + 1 ), null, true ); - $value = $this->tokens[ $valuePtr ]['content']; - $valid = $this->validate_css_property_value( $value, $css_property['type'], $css_property['value'] ); - if ( true === $valid ) { - $error = false; - } - } - - if ( true === $error ) { - $this->phpcsFile->addError( 'Hiding of the admin bar is not allowed.', $stackPtr, 'HidingDetected' ); - } - } - } - } - } - - /** - * Verify if a CSS property value complies with an expected value. - * - * {@internal This is a method stub, doing only what is needed for this sniff. - * If at some point in the future other sniff would need similar functionality, - * this method should be moved to the WordPress_Sniff class and expanded to cover - * all types of comparisons.}} - * - * @since 0.11.0 - * - * @param mixed $value The value of CSS property. - * @param string $compare_type The type of comparison to use for the validation. - * @param string $compare_value The value to compare against. - * - * @return bool True if the property value complies, false otherwise. - */ - protected function validate_css_property_value( $value, $compare_type, $compare_value ) { - switch ( $compare_type ) { - case '!=': - return $value !== $compare_value; - - case '>': - return $value > $compare_value; - - default: - return false; - } - } - -} diff --git a/WordPress/Sniffs/VIP/CronIntervalSniff.php b/WordPress/Sniffs/VIP/CronIntervalSniff.php deleted file mode 100644 index 0cf91d9486..0000000000 --- a/WordPress/Sniffs/VIP/CronIntervalSniff.php +++ /dev/null @@ -1,89 +0,0 @@ - false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * Don't use. - * - * @deprecated 1.0.0 - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.CronInterval" sniff has been renamed to "WordPress.WP.CronInterval". Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( 900 !== (int) $this->min_interval - && false === $this->thrown['FoundPropertyForDeprecatedSniff'] - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.CronInterval" sniff has been renamed to "WordPress.WP.CronInterval". Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - - return parent::process_token( $stackPtr ); - } - -} diff --git a/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php b/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php deleted file mode 100644 index a1abd4a683..0000000000 --- a/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php +++ /dev/null @@ -1,78 +0,0 @@ - false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * Don't use. - * - * @deprecated 1.0.0 - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.DirectDatabaseQuery" sniff has been renamed to "WordPress.DB.DirectDatabaseQuery". Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( false === $this->thrown['FoundPropertyForDeprecatedSniff'] - && ( ( array() !== $this->customCacheGetFunctions && $this->customCacheGetFunctions !== $this->addedCustomFunctions['cacheget'] ) - || ( array() !== $this->customCacheSetFunctions && $this->customCacheSetFunctions !== $this->addedCustomFunctions['cacheset'] ) - || ( array() !== $this->customCacheDeleteFunctions && $this->customCacheDeleteFunctions !== $this->addedCustomFunctions['cachedelete'] ) ) - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.DirectDatabaseQuery" sniff has been renamed to "WordPress.DB.DirectDatabaseQuery". Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - - return parent::process_token( $stackPtr ); - } - -} diff --git a/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php b/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php deleted file mode 100644 index d95eea636b..0000000000 --- a/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php +++ /dev/null @@ -1,152 +0,0 @@ - false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * Groups of functions to restrict. - * - * Example: groups => array( - * 'lambda' => array( - * 'type' => 'error' | 'warning', - * 'message' => 'Use anonymous functions instead please!', - * 'functions' => array( 'file_get_contents', 'create_function' ), - * ) - * ) - * - * @return array - */ - public function getGroups() { - $groups = array( - 'file_ops' => array( - 'type' => 'error', - 'message' => 'Filesystem writes are forbidden, you should not be using %s()', - 'functions' => array( - 'delete', - 'file_put_contents', - 'flock', - 'fputcsv', - 'fputs', - 'fwrite', - 'ftruncate', - 'is_writable', - 'is_writeable', - 'link', - 'rename', - 'symlink', - 'tempnam', - 'touch', - 'unlink', - ), - ), - 'directory' => array( - 'type' => 'error', - 'message' => 'Filesystem writes are forbidden, you should not be using %s()', - 'functions' => array( - 'mkdir', - 'rmdir', - ), - ), - 'chmod' => array( - 'type' => 'error', - 'message' => 'Filesystem writes are forbidden, you should not be using %s()', - 'functions' => array( - 'chgrp', - 'chown', - 'chmod', - 'lchgrp', - 'lchown', - ), - ), - ); - - /* - * Maintain old behaviour - allow for changing the error type from the ruleset - * using the `error` property. - */ - if ( false === $this->error ) { - foreach ( $groups as $group_name => $details ) { - $groups[ $group_name ]['type'] = 'warning'; - } - } - - return $groups; - } - - /** - * Process the token and handle the deprecation notices. - * - * @since 1.0.0 Added to allow for throwing the deprecation notices. - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.FileSystemWritesDisallow" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( ( ! empty( $this->exclude ) || true !== $this->error ) - && false === $this->thrown['FoundPropertyForDeprecatedSniff'] - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.FileSystemWritesDisallow" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - - return parent::process_token( $stackPtr ); - } - -} diff --git a/WordPress/Sniffs/VIP/OrderByRandSniff.php b/WordPress/Sniffs/VIP/OrderByRandSniff.php deleted file mode 100644 index 5e33df9122..0000000000 --- a/WordPress/Sniffs/VIP/OrderByRandSniff.php +++ /dev/null @@ -1,107 +0,0 @@ - rand. - * - * @link https://vip.wordpress.com/documentation/vip-go/code-review-blockers-warnings-notices/#order-by-rand - * - * @package WPCS\WordPressCodingStandards - * - * @since 0.9.0 - * @since 0.13.0 Class name changed: this class is now namespaced. - * - * @deprecated 1.0.0 This sniff has been deprecated. - * This file remains for now to prevent BC breaks. - */ -class OrderByRandSniff extends AbstractArrayAssignmentRestrictionsSniff { - - /** - * Keep track of whether the warnings have been thrown to prevent - * the messages being thrown for every token triggering the sniff. - * - * @since 1.0.0 - * - * @var array - */ - private $thrown = array( - 'DeprecatedSniff' => false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * Groups of variables to restrict. - * - * @return array - */ - public function getGroups() { - return array( - 'orderby' => array( - 'type' => 'error', - 'keys' => array( - 'orderby', - ), - ), - ); - } - - /** - * Process the token and handle the deprecation notices. - * - * @since 1.0.0 Added to allow for throwing the deprecation notices. - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.OrderByRand" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( ! empty( $this->exclude ) - && false === $this->thrown['FoundPropertyForDeprecatedSniff'] - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.OrderByRand" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - - return parent::process_token( $stackPtr ); - } - - /** - * Callback to process each confirmed key, to check value - * This must be extended to add the logic to check assignment value - * - * @param string $key Array index / key. - * @param mixed $val Assigned value. - * @param int $line Token line. - * @param array $group Group definition. - * @return mixed FALSE if no match, TRUE if matches, STRING if matches with custom error message passed to ->process(). - */ - public function callback( $key, $val, $line, $group ) { - if ( 'rand' === strtolower( $val ) ) { - return 'Detected forbidden query_var "%s" of "%s". Use vip_get_random_posts() instead.'; - } else { - return false; - } - } - -} diff --git a/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php b/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php deleted file mode 100644 index 072da87462..0000000000 --- a/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php +++ /dev/null @@ -1,65 +0,0 @@ - false, - ); - - /** - * Don't use. - * - * @deprecated 1.0.0 - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->phpcsFile->addWarning( - 'The "WordPress.VIP.PluginMenuSlug" sniff has been renamed to "WordPress.Security.PluginMenuSlug". Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - - $this->thrown['DeprecatedSniff'] = true; - } - - return parent::process_token( $stackPtr ); - } - -} diff --git a/WordPress/Sniffs/VIP/PostsPerPageSniff.php b/WordPress/Sniffs/VIP/PostsPerPageSniff.php deleted file mode 100644 index 73588a8f13..0000000000 --- a/WordPress/Sniffs/VIP/PostsPerPageSniff.php +++ /dev/null @@ -1,105 +0,0 @@ - false, - ); - - /** - * Groups of variables to restrict. - * - * @return array - */ - public function getGroups() { - return array( - 'posts_per_page' => array( - 'type' => 'error', - 'keys' => array( - 'posts_per_page', - 'nopaging', - 'numberposts', - ), - ), - ); - } - - /** - * Callback to process each confirmed key, to check value. - * - * @param string $key Array index / key. - * @param mixed $val Assigned value. - * @param int $line Token line. - * @param array $group Group definition. - * @return mixed FALSE if no match, TRUE if matches, STRING if matches - * with custom error message passed to ->process(). - */ - public function callback( $key, $val, $line, $group ) { - if ( 100 !== (int) $this->posts_per_page - && false === $this->thrown['FoundDeprecatedProperty'] - ) { - $this->phpcsFile->addWarning( - 'The "posts_per_page" property for the "WordPress.VIP.PostsPerPage" sniff is deprecated. The detection of high pagination limits has been moved to the "WordPress.WP.PostsPerPage" sniff. Please update your custom ruleset.', - 0, - 'FoundDeprecatedProperty' - ); - - $this->thrown['FoundDeprecatedProperty'] = true; - } - - $key = strtolower( $key ); - - if ( ( 'nopaging' === $key && ( 'true' === $val || 1 === $val ) ) - || ( \in_array( $key, array( 'numberposts', 'posts_per_page' ), true ) && '-1' === $val ) - ) { - return 'Disabling pagination is prohibited in VIP context, do not set `%s` to `%s` ever.'; - } - - return false; - } - -} diff --git a/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php b/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php deleted file mode 100644 index 7d7bad1c18..0000000000 --- a/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php +++ /dev/null @@ -1,280 +0,0 @@ - false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * Groups of functions to restrict. - * - * Example: groups => array( - * 'lambda' => array( - * 'type' => 'error' | 'warning', - * 'message' => 'Use anonymous functions instead please!', - * 'functions' => array( 'file_get_contents', 'create_function' ), - * ) - * ) - * - * @return array - */ - public function getGroups() { - return array( - // @link WordPress.com: https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#switch_to_blog - // @link VIP Go: https://vip.wordpress.com/documentation/vip-go/code-review-blockers-warnings-notices/#switch_to_blog - 'switch_to_blog' => array( - 'type' => 'error', - 'message' => '%s() is not something you should ever need to do in a VIP theme context. Instead use an API (XML-RPC, REST) to interact with other sites if needed.', - 'functions' => array( 'switch_to_blog' ), - ), - - 'file_get_contents' => array( - 'type' => 'warning', - 'message' => '%s() is highly discouraged, please use wpcom_vip_file_get_contents() instead.', - 'functions' => array( - 'file_get_contents', - 'vip_wp_file_get_contents', - ), - ), - - 'wpcom_vip_get_term_link' => array( - 'type' => 'error', - 'message' => '%s() is deprecated, please use get_term_link(), get_tag_link(), or get_category_link() instead.', - 'functions' => array( - 'wpcom_vip_get_term_link', - ), - ), - - 'get_page_by_path' => array( - 'type' => 'error', - 'message' => '%s() is prohibited, please use wpcom_vip_get_page_by_path() instead.', - 'functions' => array( - 'get_page_by_path', - ), - ), - - 'get_page_by_title' => array( - 'type' => 'error', - 'message' => '%s() is prohibited, please use wpcom_vip_get_page_by_title() instead.', - 'functions' => array( - 'get_page_by_title', - ), - ), - - 'wpcom_vip_get_term_by' => array( - 'type' => 'error', - 'message' => '%s() is deprecated, please use get_term_by() or get_cat_ID() instead.', - 'functions' => array( - 'wpcom_vip_get_term_by', - ), - ), - - 'wpcom_vip_get_category_by_slug' => array( - 'type' => 'error', - 'message' => '%s() is deprecated, please use get_category_by_slug() instead.', - 'functions' => array( - 'wpcom_vip_get_category_by_slug', - ), - ), - - 'url_to_postid' => array( - 'type' => 'error', - 'message' => '%s() is prohibited, please use wpcom_vip_url_to_postid() instead.', - 'functions' => array( - 'url_to_postid', - 'url_to_post_id', - ), - ), - - 'attachment_url_to_postid' => array( - 'type' => 'error', - 'message' => '%s() is prohibited, please use wpcom_vip_attachment_url_to_postid() instead.', - 'functions' => array( - 'attachment_url_to_postid', - ), - ), - - // @link WordPress.com: https://lobby.vip.wordpress.com/wordpress-com-documentation/code-review-what-we-look-for/#remote-calls - // @link VIP Go: https://vip.wordpress.com/documentation/vip-go/code-review-blockers-warnings-notices/#remote-calls - 'wp_remote_get' => array( - 'type' => 'warning', - 'message' => '%s() is highly discouraged, please use vip_safe_wp_remote_get() instead.', - 'functions' => array( - 'wp_remote_get', - ), - ), - - // @link WordPress.com: https://lobby.vip.wordpress.com/wordpress-com-documentation/code-review-what-we-look-for/#custom-roles - // @link VIP Go: https://vip.wordpress.com/documentation/vip-go/code-review-blockers-warnings-notices/#custom-roles - 'custom_role' => array( - 'type' => 'error', - 'message' => 'Use wpcom_vip_add_role() instead of %s()', - 'functions' => array( - 'add_role', - ), - ), - - // @link WordPress.com: https://lobby.vip.wordpress.com/wordpress-com-documentation/code-review-what-we-look-for/#custom-roles - // @link VIP Go: https://vip.wordpress.com/documentation/vip-go/code-review-blockers-warnings-notices/#cache-constraints - 'cookies' => array( - 'type' => 'warning', - 'message' => 'Due to using Batcache, server side based client related logic will not work, use JS instead.', - 'functions' => array( - 'setcookie', - ), - ), - - // @link WordPress.com: https://lobby.vip.wordpress.com/wordpress-com-documentation/code-review-what-we-look-for/#wp_users-and-user_meta - 'user_meta' => array( - 'type' => 'error', - 'message' => '%s() usage is highly discouraged, check VIP documentation on "Working with wp_users"', - 'functions' => array( - 'get_user_meta', - 'update_user_meta', - 'delete_user_meta', - 'add_user_meta', - ), - ), - - // @todo Introduce a sniff specific to get_posts() that checks for suppress_filters=>false being supplied. - 'get_posts' => array( - 'type' => 'warning', - 'message' => '%s() is discouraged in favor of creating a new WP_Query() so that Advanced Post Cache will cache the query, unless you explicitly supply suppress_filters => false.', - 'functions' => array( - 'get_posts', - 'wp_get_recent_posts', - 'get_children', - ), - ), - - 'term_exists' => array( - 'type' => 'error', - 'message' => '%s() is highly discouraged due to not being cached; please use wpcom_vip_term_exists() instead.', - 'functions' => array( - 'term_exists', - ), - ), - - 'count_user_posts' => array( - 'type' => 'error', - 'message' => '%s() is highly discouraged due to not being cached; please use wpcom_vip_count_user_posts() instead.', - 'functions' => array( - 'count_user_posts', - ), - ), - - 'wp_old_slug_redirect' => array( - 'type' => 'error', - 'message' => '%s() is highly discouraged due to not being cached; please use wpcom_vip_old_slug_redirect() instead.', - 'functions' => array( - 'wp_old_slug_redirect', - ), - ), - - 'get_adjacent_post' => array( - 'type' => 'error', - 'message' => '%s() is highly discouraged due to not being cached; please use wpcom_vip_get_adjacent_post() instead.', - 'functions' => array( - 'get_adjacent_post', - 'get_previous_post', - 'get_previous_post_link', - 'get_next_post', - 'get_next_post_link', - ), - ), - - 'get_intermediate_image_sizes' => array( - 'type' => 'error', - 'message' => 'Intermediate images do not exist on the VIP platform, and thus get_intermediate_image_sizes() returns an empty array() on the platform. This behavior is intentional to prevent WordPress from generating multiple thumbnails when images are uploaded.', - 'functions' => array( - 'get_intermediate_image_sizes', - ), - ), - - // @link WordPress.com: https://lobby.vip.wordpress.com/wordpress-com-documentation/code-review-what-we-look-for/#mobile-detection - // @link VIP Go: https://vip.wordpress.com/documentation/vip-go/code-review-blockers-warnings-notices/#mobile-detection - 'wp_is_mobile' => array( - 'type' => 'error', - 'message' => '%s() found. When targeting mobile visitors, jetpack_is_mobile() should be used instead of wp_is_mobile. It is more robust and works better with full page caching.', - 'functions' => array( - 'wp_is_mobile', - ), - ), - ); - } - - /** - * Process the token and handle the deprecation notices. - * - * @since 1.0.0 Added to allow for throwing the deprecation notices. - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.RestrictedFunctions" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( ! empty( $this->exclude ) - && false === $this->thrown['FoundPropertyForDeprecatedSniff'] - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.RestrictedFunctions" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - - return parent::process_token( $stackPtr ); - } - -} diff --git a/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php b/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php deleted file mode 100644 index 37a5326003..0000000000 --- a/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php +++ /dev/null @@ -1,113 +0,0 @@ - false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * Groups of variables to restrict. - * - * Example: groups => array( - * 'wpdb' => array( - * 'type' => 'error' | 'warning', - * 'message' => 'Dont use this one please!', - * 'variables' => array( '$val', '$var' ), - * 'object_vars' => array( '$foo->bar', .. ), - * 'array_members' => array( '$foo['bar']', .. ), - * ) - * ) - * - * @return array - */ - public function getGroups() { - return array( - // @link https://lobby.vip.wordpress.com/wordpress-com-documentation/code-review-what-we-look-for/#wp_users-and-user_meta - 'user_meta' => array( - 'type' => 'error', - 'message' => 'Usage of users/usermeta tables is highly discouraged in VIP context, For storing user additional user metadata, you should look at User Attributes.', - 'object_vars' => array( - '$wpdb->users', - '$wpdb->usermeta', - ), - ), - - // @link https://lobby.vip.wordpress.com/wordpress-com-documentation/code-review-what-we-look-for/#caching-constraints - 'cache_constraints' => array( - 'type' => 'warning', - 'message' => 'Due to using Batcache, server side based client related logic will not work, use JS instead.', - 'variables' => array( - '$_COOKIE', - ), - 'array_members' => array( - '$_SERVER[\'HTTP_USER_AGENT\']', - '$_SERVER[\'REMOTE_ADDR\']', - ), - ), - ); - } - - /** - * Process the token and handle the deprecation notices. - * - * @since 1.0.0 Added to allow for throwing the deprecation notices. - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.RestrictedVariables" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( ! empty( $this->exclude ) - && false === $this->thrown['FoundPropertyForDeprecatedSniff'] - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.RestrictedVariables" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - - return parent::process_token( $stackPtr ); - } - -} diff --git a/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php b/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php deleted file mode 100644 index 3554e2bbde..0000000000 --- a/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php +++ /dev/null @@ -1,126 +0,0 @@ - false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * Groups of functions to restrict. - * - * Example: groups => array( - * 'lambda' => array( - * 'type' => 'error' | 'warning', - * 'message' => 'Use anonymous functions instead please!', - * 'functions' => array( 'file_get_contents', 'create_function' ), - * ) - * ) - * - * @return array - */ - public function getGroups() { - return array( - 'session' => array( - 'type' => 'error', - 'message' => 'The use of PHP session function %s() is prohibited.', - 'functions' => array( - 'session_abort', - 'session_cache_expire', - 'session_cache_limiter', - 'session_commit', - 'session_create_id', - 'session_decode', - 'session_destroy', - 'session_encode', - 'session_gc', - 'session_get_cookie_params', - 'session_id', - 'session_is_registered', - 'session_module_name', - 'session_name', - 'session_regenerate_id', - 'session_register_shutdown', - 'session_register', - 'session_reset', - 'session_save_path', - 'session_set_cookie_params', - 'session_set_save_handler', - 'session_start', - 'session_status', - 'session_unregister', - 'session_unset', - 'session_write_close', - ), - ), - ); - } - - - /** - * Process the token and handle the deprecation notices. - * - * @since 1.0.0 Added to allow for throwing the deprecation notices. - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.SessionFunctionsUsage" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( ! empty( $this->exclude ) - && false === $this->thrown['FoundPropertyForDeprecatedSniff'] - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.SessionFunctionsUsage" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - - return parent::process_token( $stackPtr ); - } - -} diff --git a/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php b/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php deleted file mode 100644 index 945807b450..0000000000 --- a/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php +++ /dev/null @@ -1,81 +0,0 @@ - false, - ); - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() { - return array( - \T_VARIABLE, - ); - } - - /** - * Process the token and handle the deprecation notice. - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.SessionVariableUsage" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( '$_SESSION' === $this->tokens[ $stackPtr ]['content'] ) { - $this->phpcsFile->addError( - 'Usage of $_SESSION variable is prohibited.', - $stackPtr, - 'SessionVarsProhibited' - ); - } - } - -} diff --git a/WordPress/Sniffs/VIP/SlowDBQuerySniff.php b/WordPress/Sniffs/VIP/SlowDBQuerySniff.php deleted file mode 100644 index 20c6eae42e..0000000000 --- a/WordPress/Sniffs/VIP/SlowDBQuerySniff.php +++ /dev/null @@ -1,76 +0,0 @@ - false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * Don't use. - * - * @deprecated 1.0.0 - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.SlowDBQuery" sniff has been renamed to "WordPress.DB.SlowDBQuery". Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( ! empty( $this->exclude ) - && false === $this->thrown['FoundPropertyForDeprecatedSniff'] - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.SlowDBQuery" sniff has been renamed to "WordPress.DB.SlowDBQuery". Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - - return parent::process_token( $stackPtr ); - } - -} diff --git a/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php b/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php deleted file mode 100644 index 403317f9da..0000000000 --- a/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php +++ /dev/null @@ -1,87 +0,0 @@ - false, - ); - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() { - return array( - \T_VARIABLE, - ); - } - - /** - * Process the token and handle the deprecation notice. - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.SuperGlobalInputUsage" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - // Check for global input variable. - if ( ! \in_array( $this->tokens[ $stackPtr ]['content'], $this->input_superglobals, true ) ) { - return; - } - - $varName = $this->tokens[ $stackPtr ]['content']; - - // If we're overriding a superglobal with an assignment, no need to test. - if ( $this->is_assignment( $stackPtr ) ) { - return; - } - - // Check for whitelisting comment. - if ( ! $this->has_whitelist_comment( 'input var', $stackPtr ) ) { - $this->phpcsFile->addWarning( 'Detected access of super global var %s, probably needs manual inspection.', $stackPtr, 'AccessDetected', array( $varName ) ); - } - } - -} diff --git a/WordPress/Sniffs/VIP/TimezoneChangeSniff.php b/WordPress/Sniffs/VIP/TimezoneChangeSniff.php deleted file mode 100644 index 395008a7d3..0000000000 --- a/WordPress/Sniffs/VIP/TimezoneChangeSniff.php +++ /dev/null @@ -1,75 +0,0 @@ - false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * Don't use. - * - * @deprecated 1.0.0 - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.TimezoneChange" sniff has been renamed to "WordPress.WP.TimezoneChange". Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( ! empty( $this->exclude ) - && false === $this->thrown['FoundPropertyForDeprecatedSniff'] - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.TimezoneChange" sniff has been renamed to "WordPress.WP.TimezoneChange". Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - - return parent::process_token( $stackPtr ); - } - -} diff --git a/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php b/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php deleted file mode 100644 index 699c00463e..0000000000 --- a/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php +++ /dev/null @@ -1,77 +0,0 @@ - false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * Don't use. - * - * @deprecated 1.0.0 - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.ValidatedSanitizedInput" sniff has been renamed to "WordPress.Security.ValidatedSanitizedInput". Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( false === $this->thrown['FoundPropertyForDeprecatedSniff'] - && ( ( array() !== $this->customSanitizingFunctions && $this->customSanitizingFunctions !== $this->addedCustomFunctions['sanitize'] ) - || ( array() !== $this->customUnslashingSanitizingFunctions && $this->customUnslashingSanitizingFunctions !== $this->addedCustomFunctions['unslashsanitize'] ) - || false !== $this->check_validation_in_scope_only ) - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.ValidatedSanitizedInput" sniff has been renamed to "WordPress.Security.ValidatedSanitizedInput". Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - - return parent::process_token( $stackPtr ); - } - -} diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc index 50624e4346..e3120a8816 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc @@ -111,6 +111,6 @@ $bad = array( 'key1' => 'value1', 'key2' => 'value2' ); // Bad. // @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true $foo = array( - 'meta_key' => 'foo', // phpcs:ignore WordPress.VIP.SlowDBQuery.slow_db_query_meta_key - 'meta_value' => 'bar', // phpcs:ignore WordPress.VIP.SlowDBQuery.slow_db_query_meta_value + 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode + 'meta_value' => 'bar', // phpcs:ignore Standard.Category.SniffName.ErrorCode ); diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed index bc003ef79a..71b8d9c8f3 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed @@ -166,6 +166,6 @@ $bad = array( // @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true $foo = array( - 'meta_key' => 'foo', // phpcs:ignore WordPress.VIP.SlowDBQuery.slow_db_query_meta_key - 'meta_value' => 'bar', // phpcs:ignore WordPress.VIP.SlowDBQuery.slow_db_query_meta_value + 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode + 'meta_value' => 'bar', // phpcs:ignore Standard.Category.SniffName.ErrorCode ); diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc index 26436a0757..ff971e9177 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc @@ -94,6 +94,6 @@ $bad = [ 'key1' => 'value1', 'key2' => 'value2' ]; // Bad. // @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true $foo = [ - 'meta_key' => 'foo', // phpcs:ignore WordPress.VIP.SlowDBQuery.slow_db_query_meta_key - 'meta_value' => 'bar', // phpcs:ignore WordPress.VIP.SlowDBQuery.slow_db_query_meta_value + 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode + 'meta_value' => 'bar', // phpcs:ignore Standard.Category.SniffName.ErrorCode ]; diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed index 9805c7c8ff..23c25a07b2 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed @@ -150,6 +150,6 @@ $bad = [ // @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true $foo = [ - 'meta_key' => 'foo', // phpcs:ignore WordPress.VIP.SlowDBQuery.slow_db_query_meta_key - 'meta_value' => 'bar', // phpcs:ignore WordPress.VIP.SlowDBQuery.slow_db_query_meta_value + 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode + 'meta_value' => 'bar', // phpcs:ignore Standard.Category.SniffName.ErrorCode ]; diff --git a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.css b/WordPress/Tests/VIP/AdminBarRemovalUnitTest.css deleted file mode 100644 index 84d55d0d9a..0000000000 --- a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.css +++ /dev/null @@ -1,55 +0,0 @@ -#wpadminbar { - display: block; /* OK. */ - visibility: visible; /* OK. */ - opacity: 1; /* OK. */ - color: red; /* OK. */ -} - -#not-wpadminbar { - display: none; /* OK. */ - visibility: hidden; /* OK. */ - opacity: 0; /* OK. */ -} - -#wpadminbar { - display: none; /* Bad. */ - visibility: hidden; /* Bad. */ - opacity: 0; /* Bad. */ -} - -/* With !important. */ -#wpadminbar { - display: none !important; /* Bad. */ - visibility: hidden !important; /* Bad. */ - opacity: 0.0 !important; /* Bad. */ -} - -/* Indented. */ - .show-admin-bar { - visibility: hidden; /* Bad. */ - display: none !important; /* Bad. */ - opacity: 0; /* Bad. */ - } - -/* Multi-line selector. */ -.something-else, -.show-admin-bar, -#identifier { - visibility: hidden; /* Bad. */ - display: none !important; /* Bad. */ - opacity: 0; /* Bad. */ -} - - -/* @codingStandardsChangeSetting WordPress.VIP.AdminBarRemoval remove_only false */ -#wpadminbar { - display: block; /* Bad. */ - visibility: visible; /* Bad. */ - opacity: 1; /* Bad. */ -} -#not-wpadminbar { - display: none; /* OK. */ - visibility: hidden; /* OK. */ - opacity: 0; /* OK. */ -} -/* @codingStandardsChangeSetting WordPress.VIP.AdminBarRemoval remove_only true */ diff --git a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.inc b/WordPress/Tests/VIP/AdminBarRemovalUnitTest.inc deleted file mode 100644 index eb47174e9a..0000000000 --- a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.inc +++ /dev/null @@ -1,108 +0,0 @@ - -#wpadminbar { - visibility: hidden; /* Bad. */ - display: none; /* Bad. */ - opacity: 0; /* Bad. */ -} -'; - -// Various text before/after combinations. -echo ''; // Bad. - -echo 'Some text about .show-admin-bar before a style tag '; // Ok. -echo 'Some text about .show-admin-bar after a style tag'; // Ok. - -echo ''; - -// Testing T_DOUBLE_QUOTED_STRING. -echo " -"; - -// Testing T_HEREDOC. -$style = << - .show-admin-bar { - visibility: $hidden; /* Ok, value not 'hidden'. */ - } - -EOT; - -// Testing T_NOWDOC. -$style = <<<'EOT' - -EOT; - -// Testing T_INLINE_HTML -?> - - - - - - - .show-admin-bar { - visibility: $hidden; /* Bad. */ - } - .my-admin-bar { - visibility: $hidden; /* OK. */ - } - -EOT; -?> - - -/* @codingStandardsChangeSetting WordPress.VIP.AdminBarRemoval remove_only true */ diff --git a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php b/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php deleted file mode 100644 index d6b7a06516..0000000000 --- a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php +++ /dev/null @@ -1,105 +0,0 @@ - => - */ - public function getErrorList( $testFile = '' ) { - - switch ( $testFile ) { - case 'AdminBarRemovalUnitTest.inc': - return array( - 3 => 1, - 6 => 1, - 9 => 1, - 12 => 1, - 13 => 1, - 19 => 1, - 20 => 1, - 21 => 1, - 26 => 1, - 32 => 1, - 56 => 1, - 57 => 1, - 58 => 1, - 68 => 1, - 69 => 1, - 70 => 1, - 81 => 1, - 82 => 1, - 83 => 1, - 92 => 1, - 103 => 1, - 104 => 1, - 105 => 1, - ); - - case 'AdminBarRemovalUnitTest.css': - return array( - 15 => 1, - 16 => 1, - 17 => 1, - 22 => 1, - 23 => 1, - 24 => 1, - 29 => 1, - 30 => 1, - 31 => 1, - 38 => 1, - 39 => 1, - 40 => 1, - 46 => 1, - 47 => 1, - 48 => 1, - ); - - default: - return array(); - } - } - - /** - * Returns the lines where warnings should occur. - * - * @param string $testFile The name of the file being tested. - * @return array => - */ - public function getWarningList( $testFile = '' ) { - switch ( $testFile ) { - case 'AdminBarRemovalUnitTest.css': - return array( - 1 => 2, - ); - - case 'AdminBarRemovalUnitTest.inc': - return array(); - - default: - return array(); - } - } -} diff --git a/WordPress/Tests/VIP/CronIntervalUnitTest.inc b/WordPress/Tests/VIP/CronIntervalUnitTest.inc deleted file mode 100644 index 51e6582bac..0000000000 --- a/WordPress/Tests/VIP/CronIntervalUnitTest.inc +++ /dev/null @@ -1,6 +0,0 @@ - => - */ - public function getErrorList() { - return array(); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 2, - 4 => 1, - ); - } - -} diff --git a/WordPress/Tests/VIP/DirectDatabaseQueryUnitTest.inc b/WordPress/Tests/VIP/DirectDatabaseQueryUnitTest.inc deleted file mode 100644 index a8799948e3..0000000000 --- a/WordPress/Tests/VIP/DirectDatabaseQueryUnitTest.inc +++ /dev/null @@ -1,6 +0,0 @@ - => - */ - public function getErrorList() { - return array(); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 2, - ); - } - -} diff --git a/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.inc b/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.inc deleted file mode 100644 index 4a5c2b23e1..0000000000 --- a/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.inc +++ /dev/null @@ -1,49 +0,0 @@ - $loop ) { - if ( flock( $fp, LOCK_EX ) ) { // Bad. - fwrite( $fp, $text ); // Bad. - } - flock( $fp, LOCK_UN ); // Bad. -} - -fclose( $fp ); - -delete(); -fputcsv(); -fputs(); -ftruncate(); -is_writable(); -is_writeable(); -link(); -rename(); -symlink(); -tempnam(); -touch(); -unlink(); - -mkdir(); -rmdir(); - -chgrp(); -chown(); -chmod(); -lchgrp(); -lchown(); - -// @codingStandardsChangeSetting WordPress.VIP.FileSystemWritesDisallow exclude directory -mkdir(); - -// @codingStandardsChangeSetting WordPress.VIP.FileSystemWritesDisallow exclude false - - -// Issue #956. -use Fieldmanager_Link as Link; - -namespace Fieldmanager\Link\Something; -namespace Fieldmanager\Link; diff --git a/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php b/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php deleted file mode 100644 index b5d30f8a56..0000000000 --- a/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php +++ /dev/null @@ -1,68 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 3 => 1, - 9 => 1, - 10 => 1, - 12 => 1, - 17 => 1, - 18 => 1, - 19 => 1, - 20 => 1, - 21 => 1, - 22 => 1, - 23 => 1, - 24 => 1, - 25 => 1, - 26 => 1, - 27 => 1, - 28 => 1, - 30 => 1, - 31 => 1, - 33 => 1, - 34 => 1, - 35 => 1, - 36 => 1, - 37 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 2, - ); - } - -} diff --git a/WordPress/Tests/VIP/OrderByRandUnitTest.inc b/WordPress/Tests/VIP/OrderByRandUnitTest.inc deleted file mode 100644 index 0a722377df..0000000000 --- a/WordPress/Tests/VIP/OrderByRandUnitTest.inc +++ /dev/null @@ -1,18 +0,0 @@ - 'rand', // Bad. - "orderby" => "rand", // Bad. - "orderby" => "RAND", // Bad. -); - -_query_posts( 'orderby=rand' ); // Bad. - -$query_args['orderby'] = 'rand'; // Bad. - -$query_args['orderby'] = 'date'; // Ok. - -// @codingStandardsChangeSetting WordPress.VIP.OrderByRand exclude something -$query_args['orderby'] = 'rand'; // Bad. - -// @codingStandardsChangeSetting WordPress.VIP.OrderByRand exclude false \ No newline at end of file diff --git a/WordPress/Tests/VIP/OrderByRandUnitTest.php b/WordPress/Tests/VIP/OrderByRandUnitTest.php deleted file mode 100644 index 084eedfd33..0000000000 --- a/WordPress/Tests/VIP/OrderByRandUnitTest.php +++ /dev/null @@ -1,51 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 4 => 1, - 5 => 1, - 6 => 1, - 9 => 1, - 11 => 1, - 16 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 2, - ); - } - -} diff --git a/WordPress/Tests/VIP/PluginMenuSlugUnitTest.inc b/WordPress/Tests/VIP/PluginMenuSlugUnitTest.inc deleted file mode 100644 index a625119c1d..0000000000 --- a/WordPress/Tests/VIP/PluginMenuSlugUnitTest.inc +++ /dev/null @@ -1,3 +0,0 @@ - => - */ - public function getErrorList() { - return array(); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 1, - ); - } - -} diff --git a/WordPress/Tests/VIP/PostsPerPageUnitTest.inc b/WordPress/Tests/VIP/PostsPerPageUnitTest.inc deleted file mode 100644 index 25e92fbe54..0000000000 --- a/WordPress/Tests/VIP/PostsPerPageUnitTest.inc +++ /dev/null @@ -1,24 +0,0 @@ - true, // Bad. - 'posts_per_page' => 999, // OK. - 'posts_per_page' => -1, // Bad. - 'posts_per_page' => 1, // Ok. - 'posts_per_page' => '1', // Ok. -); - -_query_posts( 'nopaging=true&posts_per_page=999' ); // Bad. - -$query_args['posts_per_page'] = -1; // Bad. -$query_args['posts_per_page'] = 1; // OK. -$query_args['posts_per_page'] = '1'; // OK. -$query_args['posts_per_page'] = '-1'; // Bad. -$query_args['numberposts'] = '-1'; // Bad. - -$query_args['my_posts_per_page'] = -1; // OK. - -// Test deprecated property message. -// @codingStandardsChangeSetting WordPress.VIP.PostsPerPage posts_per_page 50 -$query_args['posts_per_page'] = 50; // OK. -// @codingStandardsChangeSetting WordPress.VIP.PostsPerPage posts_per_page 100 diff --git a/WordPress/Tests/VIP/PostsPerPageUnitTest.php b/WordPress/Tests/VIP/PostsPerPageUnitTest.php deleted file mode 100644 index c4ba575911..0000000000 --- a/WordPress/Tests/VIP/PostsPerPageUnitTest.php +++ /dev/null @@ -1,54 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 4 => 1, - 6 => 1, - 11 => 1, - 13 => 1, - 16 => 1, - 17 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 1, - ); - } - -} diff --git a/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.inc b/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.inc deleted file mode 100644 index f0f06d3a1b..0000000000 --- a/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.inc +++ /dev/null @@ -1,89 +0,0 @@ -add_role(); // Ok. -$y = Bar::add_role(); // Ok. -\SomeNamespace\add_role(); // Ok. - -\add_role(); // Error. - -wpcom_vip_get_term_link( $term ); // Error. - -get_page_by_path( $path ); // Error. - -get_page_by_title( $page_title ); // Error. - -wpcom_vip_get_term_by( $field, $value, $taxonomy ); // Error. - -wpcom_vip_get_category_by_slug( $slug ); // Error. - -url_to_postid( $url ); // Error. - -attachment_url_to_postid( $url ); // Error. -wpcom_vip_attachment_url_to_postid( $url ); // Ok. - -get_tag_link(); // Ok. -get_category_link(); // Ok. -get_cat_ID(); // Ok. -url_to_post_id(); // Error. - -get_posts(); // Warning. -wp_get_recent_posts(); // Warning. - -get_children(); // Warning. - - - - -term_exists(); // Error. -count_user_posts(); // Error. -wp_old_slug_redirect(); // Error. -get_adjacent_post(); // Error. -get_previous_post(); // Error. -get_next_post(); // Error. - - - - -get_previous_post_link(); // Error. -get_next_post_link(); // Error. -get_intermediate_image_sizes(); // Error. - - -wp_is_mobile(); // Error. - -setcookie( 'cookie[three]', 'cookiethree' ); // Warning. - -get_user_meta(); // Error. -update_user_meta(); // Error. -delete_user_meta(); // Error. -add_user_meta(); // Error. - -// @codingStandardsChangeSetting WordPress.VIP.RestrictedFunctions exclude switch_to_blog -switch_to_blog( $blogid ); // Error. - -// @codingStandardsChangeSetting WordPress.VIP.RestrictedFunctions exclude false diff --git a/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php b/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php deleted file mode 100644 index b2cb717aba..0000000000 --- a/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php +++ /dev/null @@ -1,77 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 3 => 1, - 17 => 1, - 32 => 1, - 34 => 1, - 36 => 1, - 38 => 1, - 40 => 1, - 42 => 1, - 44 => 1, - 46 => 1, - 52 => 1, - 62 => 1, - 63 => 1, - 64 => 1, - 65 => 1, - 66 => 1, - 67 => 1, - 72 => 1, - 73 => 1, - 74 => 1, - 77 => 1, - 81 => 1, - 82 => 1, - 83 => 1, - 84 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 2, - 5 => 1, - 7 => 1, - 9 => 1, - 54 => 1, - 55 => 1, - 57 => 1, - 79 => 1, - ); - } - -} diff --git a/WordPress/Tests/VIP/RestrictedVariablesUnitTest.inc b/WordPress/Tests/VIP/RestrictedVariablesUnitTest.inc deleted file mode 100644 index b4b3a65c48..0000000000 --- a/WordPress/Tests/VIP/RestrictedVariablesUnitTest.inc +++ /dev/null @@ -1,34 +0,0 @@ -users"; // Error. - -$wp_db->update( $wpdb->users, array( 'displayname' => 'Kanobe!' ), array( 'ID' => 1 ) ); // Error. - -$query = "SELECT * FROM $wpdb->usermeta"; // Error. - -$wp_db->update( $wpdb->usermeta, array( 'meta_value' => 'bar!' ), array( 'user_id' => 1, 'meta_key' => 'foo' ) ); // Error. - -$query = "SELECT * FROM $wpdb->posts"; // Ok. - -if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { // Warning. - foo( $_SERVER['HTTP_USER_AGENT'] ); // Warning. -} - -$x = $_COOKIE['bar']; // Warning. - -$y = $_SERVER['REQUEST_URI']; // Ok. - -// Error. -$query = <<usermeta -EOD; - -// Warning -$phrase = << => - */ - public function getErrorList() { - return array( - 3 => 1, - 5 => 1, - 7 => 1, - 9 => 1, - 23 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 2, - 13 => 1, - 14 => 1, - 17 => 1, - 28 => 1, - ); - } - -} diff --git a/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.inc b/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.inc deleted file mode 100644 index 086fdab098..0000000000 --- a/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.inc +++ /dev/null @@ -1,34 +0,0 @@ - => - */ - public function getErrorList() { - return array_fill( 3, 26, 1 ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 2, - ); - } - -} diff --git a/WordPress/Tests/VIP/SessionVariableUsageUnitTest.inc b/WordPress/Tests/VIP/SessionVariableUsageUnitTest.inc deleted file mode 100644 index d635ed98fa..0000000000 --- a/WordPress/Tests/VIP/SessionVariableUsageUnitTest.inc +++ /dev/null @@ -1,4 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 3 => 1, - 4 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 1, - ); - } - -} diff --git a/WordPress/Tests/VIP/SlowDBQueryUnitTest.inc b/WordPress/Tests/VIP/SlowDBQueryUnitTest.inc deleted file mode 100644 index 749e23d1e0..0000000000 --- a/WordPress/Tests/VIP/SlowDBQueryUnitTest.inc +++ /dev/null @@ -1,6 +0,0 @@ - => - */ - public function getErrorList() { - return array(); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 2, - 4 => 1, - ); - } - -} diff --git a/WordPress/Tests/VIP/SuperGlobalInputUsageUnitTest.inc b/WordPress/Tests/VIP/SuperGlobalInputUsageUnitTest.inc deleted file mode 100644 index 449117850a..0000000000 --- a/WordPress/Tests/VIP/SuperGlobalInputUsageUnitTest.inc +++ /dev/null @@ -1,23 +0,0 @@ - - // Do something. - => - */ - public function getErrorList() { - return array(); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 1, - 3 => 1, - 13 => 1, - 15 => 1, - ); - } - -} diff --git a/WordPress/Tests/VIP/TimezoneChangeUnitTest.inc b/WordPress/Tests/VIP/TimezoneChangeUnitTest.inc deleted file mode 100644 index b49ed63821..0000000000 --- a/WordPress/Tests/VIP/TimezoneChangeUnitTest.inc +++ /dev/null @@ -1,6 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 4 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 2, - ); - } - -} diff --git a/WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.inc b/WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.inc deleted file mode 100644 index 01950abed5..0000000000 --- a/WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.inc +++ /dev/null @@ -1,6 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 4 => 3, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 2, - ); - } - -} diff --git a/WordPress/ruleset.xml b/WordPress/ruleset.xml index cd3cd73dff..505d42a273 100644 --- a/WordPress/ruleset.xml +++ b/WordPress/ruleset.xml @@ -6,17 +6,7 @@ - - - - - - - - - - - + - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - - 0 - - From 969a8054f6c699652e57c4e681018c772f2499f0 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 04:17:59 +0100 Subject: [PATCH 010/241] WPCS 2.0.0: Remove deprecated Sniff::has_html_open_tag() method --- WordPress/Sniff.php | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 461faad62f..92660c6a5b 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -2326,41 +2326,6 @@ public function get_declared_namespace_name( $stackPtr ) { return $namespaceName; } - /** - * Check if a content string contains a specific html open tag. - * - * @since 0.11.0 - * @since 0.13.0 No longer allows for the PHP 5.2 bug for which the function was - * originally created. - * @since 0.13.0 The $stackPtr parameter is now optional. Either that or the - * $content parameter has to be passed. - * @deprecated 1.0.0 This method is only used by deprecated sniffs. - * - * @param string $tag_name The name of the HTML tag without brackets. So if - * searching for ' open tag, false otherwise. - */ - public function has_html_open_tag( $tag_name, $stackPtr = null, $content = false ) { - if ( false === $content && isset( $stackPtr ) ) { - $content = $this->tokens[ $stackPtr ]['content']; - } - - if ( ! empty( $content ) && false !== strpos( $content, '<' . $tag_name ) ) { - return true; - } - - return false; - } - /** * Check whether a T_CONST token is a class constant declaration. * From 71ddaac06d673249f141f8d94e71c5c812b816f6 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 6 Nov 2018 01:23:22 +0100 Subject: [PATCH 011/241] PrefixAllGlobals: use separate errorcodes for warning vs error While cleaning up a plugin, I noticed that the issue count for the `WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound` error code was different if I ran phpcs with the `-n` flag (no warnings). Error codes should be unique. Having the same error code for something which is mandatory (`error`) and recommended (`warning`) is bad practice and does not properly allow for modular disabling of notices. This PR fixes this. This is a breaking change as for the warnings, ``s for the old errorcode currently in custom rulesets will be invalidated by it, so this PR should go into WPCS 2.0.0. --- .../Sniffs/NamingConventions/PrefixAllGlobalsSniff.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index 43d5a2b9a7..796c65de58 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -794,9 +794,15 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p $data = array( 'Global constants defined' ); $error_code = 'NonPrefixedConstantFound'; + if ( false === $is_error ) { + $error_code = 'VariableConstantNameFound'; + } } else { $data = array( 'Hook names invoked' ); $error_code = 'NonPrefixedHooknameFound'; + if ( false === $is_error ) { + $error_code = 'DynamicHooknameFound'; + } } $data[] = $raw_content; From 7b920b48ff9d49342b18ec1b989dbba5dec73ec8 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 14 Aug 2018 18:56:05 +0200 Subject: [PATCH 012/241] NonceVerification: use separate errorcodes for warning vs error While cleaning up a plugin, I noticed that the issue count for the `WordPress.Security.NonceVerification.NoNonceVerification` error code was different if I ran phpcs with the `-n` flag (no warnings). Error codes should be unique. Having the same error code for something which is mandatory (`error`) and recommended (`warning`) is bad practice and does not properly allow for modular disabling of notices. This PR fixes this. As the error code is changing anyhow, I figured it made sense to also remove the duplication of the sniff name from the code. This is a breaking change as ``s for the old errorcode currently in custom rulesets will be invalidated by it, so this PR should go into WPCS 2.0.0. N.B.: The ruleset change is necessary until the deprecated sniffs have been removed. --- WordPress/Sniffs/Security/NonceVerificationSniff.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/WordPress/Sniffs/Security/NonceVerificationSniff.php b/WordPress/Sniffs/Security/NonceVerificationSniff.php index 4909a01f99..d3d6a9d40f 100644 --- a/WordPress/Sniffs/Security/NonceVerificationSniff.php +++ b/WordPress/Sniffs/Security/NonceVerificationSniff.php @@ -155,12 +155,17 @@ public function process_token( $stackPtr ) { return; } + $error_code = 'Missing'; + if ( false === $this->superglobals[ $instance['content'] ] ) { + $error_code = 'Recommended'; + } + // If we're still here, no nonce-verification function was found. $this->addMessage( 'Processing form data without nonce verification.', $stackPtr, $this->superglobals[ $instance['content'] ], - 'NoNonceVerification' + $error_code ); } From 405f264544d7fa16899c1423b6ed4e2a045b8897 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 04:17:37 +0100 Subject: [PATCH 013/241] WPCS 2.0.0: Remove deprecated properties ... and code related to them. --- .../ValidVariableNameSniff.php | 29 +---------------- .../Sniffs/Security/EscapeOutputSniff.php | 32 ++----------------- .../Security/NonceVerificationSniff.php | 26 --------------- 3 files changed, 3 insertions(+), 84 deletions(-) diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index 2325514ad2..4a364e1a5c 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -116,16 +116,6 @@ class ValidVariableNameSniff extends PHPCS_AbstractVariableSniff { 'variables' => null, ); - /** - * Custom list of properties which can have mixed case. - * - * @since 0.10.0 - * @deprecated 0.11.0 Use $customPropertiesWhitelist instead. - * - * @var string|string[] - */ - public $customVariablesWhitelist = array(); - /** * Processes this test, when one of its tokens is encountered. * @@ -303,33 +293,16 @@ public static function isSnakeCase( $var_name ) { * @return void */ protected function mergeWhiteList( File $phpcs_file ) { - if ( $this->customPropertiesWhitelist !== $this->addedCustomProperties['properties'] - || $this->customVariablesWhitelist !== $this->addedCustomProperties['variables'] - ) { + if ( $this->customPropertiesWhitelist !== $this->addedCustomProperties['properties'] ) { // Fix property potentially passed as comma-delimited string. $customProperties = Sniff::merge_custom_array( $this->customPropertiesWhitelist, array(), false ); - if ( ! empty( $this->customVariablesWhitelist ) ) { - $customProperties = Sniff::merge_custom_array( - $this->customVariablesWhitelist, - $customProperties, - false - ); - - $phpcs_file->addWarning( - 'The customVariablesWhitelist property is deprecated in favor of customPropertiesWhitelist.', - 0, - 'DeprecatedCustomVariablesWhitelist' - ); - } - $this->whitelisted_mixed_case_member_var_names = Sniff::merge_custom_array( $customProperties, $this->whitelisted_mixed_case_member_var_names ); $this->addedCustomProperties['properties'] = $this->customPropertiesWhitelist; - $this->addedCustomProperties['variables'] = $this->customVariablesWhitelist; } } diff --git a/WordPress/Sniffs/Security/EscapeOutputSniff.php b/WordPress/Sniffs/Security/EscapeOutputSniff.php index abb66540d0..428b0fc3a5 100644 --- a/WordPress/Sniffs/Security/EscapeOutputSniff.php +++ b/WordPress/Sniffs/Security/EscapeOutputSniff.php @@ -48,17 +48,6 @@ class EscapeOutputSniff extends Sniff { */ public $customAutoEscapedFunctions = array(); - /** - * Custom list of functions which escape values for output. - * - * @since 0.3.0 - * @deprecated 0.5.0 Use $customEscapingFunctions instead. - * @see \WordPress\Sniffs\Security\EscapeOutputSniff::$customEscapingFunctions - * - * @var string|string[] - */ - public $customSanitizingFunctions = array(); - /** * Custom list of functions which print output incorporating the passed values. * @@ -493,32 +482,15 @@ public function process_token( $stackPtr ) { * @return void */ protected function mergeFunctionLists() { - if ( $this->customEscapingFunctions !== $this->addedCustomFunctions['escape'] - || $this->customSanitizingFunctions !== $this->addedCustomFunctions['sanitize'] - ) { + if ( $this->customEscapingFunctions !== $this->addedCustomFunctions['escape'] ) { $customEscapeFunctions = $this->merge_custom_array( $this->customEscapingFunctions, array(), false ); - if ( ! empty( $this->customSanitizingFunctions ) ) { - $customEscapeFunctions = $this->merge_custom_array( - $this->customSanitizingFunctions, - $customEscapeFunctions, - false - ); - - $this->phpcsFile->addWarning( - 'The customSanitizingFunctions property is deprecated in favor of customEscapingFunctions.', - 0, - 'DeprecatedCustomSanitizingFunctions' - ); - } - $this->escapingFunctions = $this->merge_custom_array( $customEscapeFunctions, $this->escapingFunctions ); - $this->addedCustomFunctions['escape'] = $this->customEscapingFunctions; - $this->addedCustomFunctions['sanitize'] = $this->customSanitizingFunctions; + $this->addedCustomFunctions['escape'] = $this->customEscapingFunctions; } if ( $this->customAutoEscapedFunctions !== $this->addedCustomFunctions['autoescape'] ) { diff --git a/WordPress/Sniffs/Security/NonceVerificationSniff.php b/WordPress/Sniffs/Security/NonceVerificationSniff.php index 4909a01f99..1d80b0b87b 100644 --- a/WordPress/Sniffs/Security/NonceVerificationSniff.php +++ b/WordPress/Sniffs/Security/NonceVerificationSniff.php @@ -40,32 +40,6 @@ class NonceVerificationSniff extends Sniff { '$_REQUEST' => false, ); - /** - * Superglobals to give an error for when not accompanied by an nonce check. - * - * @since 0.5.0 - * @since 0.11.0 Changed visibility from public to protected. - * - * @deprecated 0.12.0 Replaced by $superglobals property. - * - * @var array - */ - protected $errorForSuperGlobals = array(); - - /** - * Superglobals to give a warning for when not accompanied by an nonce check. - * - * If the variable is also in the error list, that takes precedence. - * - * @since 0.5.0 - * @since 0.11.0 Changed visibility from public to protected. - * - * @deprecated 0.12.0 Replaced by $superglobals property. - * - * @var array - */ - protected $warnForSuperGlobals = array(); - /** * Custom list of functions which verify nonces. * From 0d314d0737e1092c40690ad7a070f3bf3a2b5716 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 04:55:08 +0100 Subject: [PATCH 014/241] WPCS 2.0.0: Set the minimum required PHPCS version to 3.3.1 / PHP 5.4 --- .github/CONTRIBUTING.md | 2 +- .github/ISSUE_TEMPLATE/dependency-change.md | 2 +- .phpcs.xml.dist | 5 +-- .travis.yml | 38 +++------------------ README.md | 12 +++---- composer.json | 4 +-- 6 files changed, 13 insertions(+), 50 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index a497a78486..a70d94d195 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -77,7 +77,7 @@ When you introduce a new whitelist comment, please don't forget to update the [w ## Pre-requisites * WordPress-Coding-Standards -* PHP_CodeSniffer 2.9.x or 3.x +* PHP_CodeSniffer 3.3.1 or higher * PHPUnit 4.x, 5.x, 6.x or 7.x The WordPress Coding Standards use the PHP_CodeSniffer native unit test suite for unit testing the sniffs. diff --git a/.github/ISSUE_TEMPLATE/dependency-change.md b/.github/ISSUE_TEMPLATE/dependency-change.md index 740abf51ad..1208b19678 100644 --- a/.github/ISSUE_TEMPLATE/dependency-change.md +++ b/.github/ISSUE_TEMPLATE/dependency-change.md @@ -4,7 +4,7 @@ about: A reminder to take action when a WPCS dependency changes --- - + ## Rationale diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index ec29a1708c..4bb6850731 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -35,7 +35,7 @@ - + @@ -47,9 +47,6 @@ - - - diff --git a/.travis.yml b/.travis.yml index 74ad0a2745..18cc71e459 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,10 +26,8 @@ php: env: # `master` is now 3.x. - PHPCS_BRANCH="dev-master" LINT=1 - # Lowest supported release in the 3.x series with which WPCS is compatible (and which can run the unit tests). - - PHPCS_BRANCH="3.1.0" - # Lowest tagged release in the 2.x series with which WPCS is compatible. - - PHPCS_BRANCH="2.9.0" + # Lowest supported release in the 3.x series with which WPCS is compatible. + - PHPCS_BRANCH="3.3.1" matrix: fast_finish: true @@ -42,22 +40,9 @@ matrix: packages: - libxml2-utils - # Test PHP 5.3 only against PHPCS 2.x as PHPCS 3.x has a minimum requirement of PHP 5.4. - - php: 5.3 - env: PHPCS_BRANCH="2.9.*" LINT=1 - dist: precise - # Test PHP 5.3 with short_open_tags set to On (is Off by default) - - php: 5.3 - env: PHPCS_BRANCH="2.9.0" SHORT_OPEN_TAGS=true - dist: precise - allow_failures: # Allow failures for unstable builds. - php: nightly - - php: 7.3 - env: PHPCS_BRANCH="3.1.0" - - php: 7.3 - env: PHPCS_BRANCH="2.9.0" before_install: # Speed up build time by disabling Xdebug. @@ -66,13 +51,7 @@ before_install: - phpenv config-rm xdebug.ini || echo 'No xdebug config.' - export XMLLINT_INDENT=" " - export PHPUNIT_DIR=/tmp/phpunit - - | - if [[ ${PHPCS_BRANCH:0:2} == "2." ]]; then - # --prefer-source is needed to ensure that the PHPCS unit test suite is available in PHPCS 2.9. - composer require squizlabs/php_codesniffer:${PHPCS_BRANCH} --prefer-source --update-no-dev --no-suggest --no-scripts - else - composer require squizlabs/php_codesniffer:${PHPCS_BRANCH} --update-no-dev --no-suggest --no-scripts - fi + - composer require squizlabs/php_codesniffer:${PHPCS_BRANCH} --update-no-dev --no-suggest --no-scripts - | if [[ "$SNIFF" == "1" ]]; then composer install --dev --no-suggest @@ -81,21 +60,12 @@ before_install: # The above require already does the install. $(pwd)/vendor/bin/phpcs --config-set installed_paths $(pwd) fi - # Download PHPUnit 5.x for builds on PHP 7 and nightly as the PHPCS - # test suite is currently not compatible with PHPUnit 6.x. - # Fixed at a very specific PHPUnit version. - - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." ]]; then wget -P $PHPUNIT_DIR https://phar.phpunit.de/phpunit-5.7.17.phar && chmod +x $PHPUNIT_DIR/phpunit-5.7.17.phar; fi - # Selectively adjust the ini values for the build image to test ini value dependent sniff features. - - if [[ "$SHORT_OPEN_TAGS" == "true" ]]; then echo "short_open_tag = On" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi script: # Lint the PHP files against parse errors. - if [[ "$LINT" == "1" ]]; then if find . -path ./vendor -prune -o -path ./bin -prune -o -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi; fi # Run the unit tests. - - if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then phpunit --filter WordPress $(pwd)/Test/AllTests.php; fi - - if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." && ${PHPCS_BRANCH:0:2} != "2." ]]; then phpunit --filter WordPress $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php; fi - - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --filter WordPress $(pwd)/Test/AllTests.php; fi - - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." && ${PHPCS_BRANCH:0:2} != "2." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --filter WordPress $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php; fi + - phpunit --filter WordPress $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php # Test for fixer conflicts by running the auto-fixers of the complete WPCS over the test case files. # This is not an exhaustive test, but should give an early indication for typical fixer conflicts. # For the first run, the exit code will be 1 (= all fixable errors fixed). diff --git a/README.md b/README.md index d672ea0ed4..8e9fc04d31 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ [![Last Commit to Unstable](https://img.shields.io/github/last-commit/WordPress-Coding-Standards/WordPress-Coding-Standards/develop.svg)](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/commits/develop) [![Minimum PHP Version](https://img.shields.io/packagist/php-v/wp-coding-standards/wpcs.svg?maxAge=3600)](https://packagist.org/packages/wp-coding-standards/wpcs) -[![Tested on PHP 5.3 to nightly](https://img.shields.io/badge/tested%20on-PHP%205.3%20|%205.4%20|%205.5%20|%205.6%20|%207.0%20|%207.1%20|%207.2%20|%20nightly-green.svg?maxAge=2419200)](https://travis-ci.org/WordPress-Coding-Standards/WordPress-Coding-Standards) +[![Tested on PHP 5.4 to nightly](https://img.shields.io/badge/tested%20on-PHP%205.4%20|%205.5%20|%205.6%20|%207.0%20|%207.1%20|%207.2%20|%20nightly-green.svg?maxAge=2419200)](https://travis-ci.org/WordPress-Coding-Standards/WordPress-Coding-Standards) [![License: MIT](https://poser.pugx.org/wp-coding-standards/wpcs/license)](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/LICENSE) [![Total Downloads](https://poser.pugx.org/wp-coding-standards/wpcs/downloads)](https://packagist.org/packages/wp-coding-standards/wpcs/stats) @@ -59,8 +59,7 @@ This project is a collection of [PHP_CodeSniffer](https://github.com/squizlabs/P ### Requirements -The WordPress Coding Standards require PHP 5.3 or higher and [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) version **2.9.0** or higher. -As of version 0.13.0, the WordPress Coding Standards are compatible with PHPCS 3.0.2+. In that case, the minimum PHP requirement is PHP 5.4. +The WordPress Coding Standards require PHP 5.4 or higher and [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) version **3.3.1** or higher. ### Composer @@ -75,7 +74,7 @@ Running this command will: 3. Register WordPress standards in PHP_CodeSniffer configuration. 4. Make `phpcs` command available from `wpcs/vendor/bin`. -For the convenience of using `phpcs` as a global command, you may want to add the path to the `wpcs/vendor/scripts` (PHPCS 2.x) and/or `wpcs/vendor/bin` (PHPCS 3.x) directories to a `PATH` environment variable for your operating system. +For the convenience of using `phpcs` as a global command, you may want to add the path to the `wpcs/vendor/bin` directory to a `PATH` environment variable for your operating system. #### Installing WPCS as a dependency @@ -113,13 +112,10 @@ cd ~/projects git clone https://github.com/squizlabs/PHP_CodeSniffer.git phpcs git clone -b master https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git wpcs cd phpcs -#PHPCS 2.x -./scripts/phpcs --config-set installed_paths ../wpcs -#PHPCS 3.x ./bin/phpcs --config-set installed_paths ../wpcs ``` -And then add the `~/projects/phpcs/scripts` (PHPCS 2.x) or `~/projects/phpcs/bin` (PHPCS 3.x) directory to your `PATH` environment variable via your `.bashrc`. +And then add the `~/projects/phpcs/bin` directory to your `PATH` environment variable via your `.bashrc`. You should then see `WordPress-Core` et al listed when you run `phpcs -i`. diff --git a/composer.json b/composer.json index db2f784258..f7511b0fb3 100644 --- a/composer.json +++ b/composer.json @@ -15,8 +15,8 @@ } ], "require": { - "php": ">=5.3", - "squizlabs/php_codesniffer": "^2.9.0 || ^3.0.2" + "php": ">=5.4", + "squizlabs/php_codesniffer": "^3.3.1" }, "require-dev": { "phpcompatibility/php-compatibility": "^9.0" From df7f5dfc8c73d3a89ec3e0aa85619c9c4aedc8bd Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 15:41:32 +0100 Subject: [PATCH 015/241] WPCS 2.0.0: Update the WPCS namespace To prevent conflicts with WordPress itself - especially now that WordPress will let go of the PHP 5.2 minimum supported version -, WPCS should not use the `WordPress` namespace. While PHPCS 2.x still needed to be supported, this could not be helped as it was a PHPCS requirement. Now that PHPCS 2.x support is being dropped, the namespace can be adjusted. Note: It is still a requirement that the namespace contains `StandardName\Sniffs\Category`, so we cannot replace `WordPress` with just `WordPressCS`. It has to be `WordPressCS\WordPress`. Note: This is a BC-break for any external standard which extends sniffs from WPCS. They will need to update their `use` statements to use the new WPCS namespace. Refs: * squizlabs/PHP_CodeSniffer 1469 * squizlabs/PHP_CodeSniffer 1569 * https://github.com/squizlabs/PHP_CodeSniffer/wiki/Version-3.0-Upgrade-Guide --- .github/CONTRIBUTING.md | 6 +++--- WordPress/AbstractArrayAssignmentRestrictionsSniff.php | 4 ++-- WordPress/AbstractClassRestrictionsSniff.php | 4 ++-- WordPress/AbstractFunctionParameterSniff.php | 4 ++-- WordPress/AbstractFunctionRestrictionsSniff.php | 4 ++-- WordPress/PHPCSAliases.php | 4 +++- WordPress/PHPCSHelper.php | 2 +- WordPress/Sniff.php | 4 ++-- WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php | 4 ++-- WordPress/Sniffs/Arrays/ArrayIndentationSniff.php | 6 +++--- .../Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php | 4 ++-- WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php | 4 ++-- WordPress/Sniffs/Arrays/MultipleStatementAlignmentSniff.php | 4 ++-- WordPress/Sniffs/Classes/ClassInstantiationSniff.php | 4 ++-- .../Sniffs/CodeAnalysis/AssignmentInConditionSniff.php | 4 ++-- WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php | 4 ++-- WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php | 4 ++-- WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php | 4 ++-- WordPress/Sniffs/DB/PreparedSQLSniff.php | 4 ++-- WordPress/Sniffs/DB/RestrictedClassesSniff.php | 4 ++-- WordPress/Sniffs/DB/RestrictedFunctionsSniff.php | 4 ++-- WordPress/Sniffs/DB/SlowDBQuerySniff.php | 4 ++-- WordPress/Sniffs/Files/FileNameSniff.php | 4 ++-- .../Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php | 4 ++-- .../Sniffs/NamingConventions/PrefixAllGlobalsSniff.php | 6 +++--- .../Sniffs/NamingConventions/ValidFunctionNameSniff.php | 2 +- WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php | 4 ++-- .../Sniffs/NamingConventions/ValidVariableNameSniff.php | 4 ++-- WordPress/Sniffs/PHP/DevelopmentFunctionsSniff.php | 4 ++-- WordPress/Sniffs/PHP/DiscourageGotoSniff.php | 4 ++-- WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php | 4 ++-- WordPress/Sniffs/PHP/DontExtractSniff.php | 4 ++-- WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php | 4 ++-- WordPress/Sniffs/PHP/POSIXFunctionsSniff.php | 4 ++-- WordPress/Sniffs/PHP/PregQuoteDelimiterSniff.php | 4 ++-- WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php | 4 ++-- WordPress/Sniffs/PHP/StrictComparisonsSniff.php | 4 ++-- WordPress/Sniffs/PHP/StrictInArraySniff.php | 4 ++-- WordPress/Sniffs/PHP/TypeCastsSniff.php | 4 ++-- WordPress/Sniffs/PHP/YodaConditionsSniff.php | 4 ++-- WordPress/Sniffs/Security/EscapeOutputSniff.php | 4 ++-- WordPress/Sniffs/Security/NonceVerificationSniff.php | 4 ++-- WordPress/Sniffs/Security/PluginMenuSlugSniff.php | 4 ++-- WordPress/Sniffs/Security/SafeRedirectSniff.php | 4 ++-- WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php | 4 ++-- WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php | 4 ++-- WordPress/Sniffs/WP/AlternativeFunctionsSniff.php | 4 ++-- WordPress/Sniffs/WP/CapitalPDangitSniff.php | 4 ++-- WordPress/Sniffs/WP/CronIntervalSniff.php | 4 ++-- WordPress/Sniffs/WP/DeprecatedClassesSniff.php | 4 ++-- WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php | 4 ++-- WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php | 4 ++-- WordPress/Sniffs/WP/DeprecatedParametersSniff.php | 4 ++-- WordPress/Sniffs/WP/DiscouragedConstantsSniff.php | 4 ++-- WordPress/Sniffs/WP/DiscouragedFunctionsSniff.php | 4 ++-- WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php | 4 ++-- WordPress/Sniffs/WP/EnqueuedResourcesSniff.php | 4 ++-- WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php | 4 ++-- WordPress/Sniffs/WP/I18nSniff.php | 6 +++--- WordPress/Sniffs/WP/PostsPerPageSniff.php | 4 ++-- WordPress/Sniffs/WP/TimezoneChangeSniff.php | 4 ++-- .../Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php | 4 ++-- WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php | 4 ++-- .../Sniffs/WhiteSpace/ControlStructureSpacingSniff.php | 4 ++-- WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php | 6 +++--- WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php | 2 +- WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php | 6 +++--- WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php | 2 +- WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php | 2 +- WordPress/Tests/Arrays/ArrayIndentationUnitTest.php | 2 +- .../Tests/Arrays/ArrayKeySpacingRestrictionsUnitTest.php | 2 +- WordPress/Tests/Arrays/CommaAfterArrayItemUnitTest.php | 2 +- .../Tests/Arrays/MultipleStatementAlignmentUnitTest.php | 2 +- WordPress/Tests/Classes/ClassInstantiationUnitTest.php | 2 +- .../Tests/CodeAnalysis/AssignmentInConditionUnitTest.php | 2 +- WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php | 2 +- WordPress/Tests/DB/DirectDatabaseQueryUnitTest.php | 2 +- WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php | 2 +- WordPress/Tests/DB/PreparedSQLUnitTest.php | 2 +- WordPress/Tests/DB/RestrictedClassesUnitTest.php | 4 ++-- WordPress/Tests/DB/RestrictedFunctionsUnitTest.php | 2 +- WordPress/Tests/DB/SlowDBQueryUnitTest.php | 2 +- WordPress/Tests/Files/FileNameUnitTest.php | 2 +- .../Functions/FunctionCallSignatureNoParamsUnitTest.php | 2 +- .../Tests/NamingConventions/PrefixAllGlobalsUnitTest.php | 2 +- .../Tests/NamingConventions/ValidFunctionNameUnitTest.php | 2 +- WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php | 2 +- .../Tests/NamingConventions/ValidVariableNameUnitTest.php | 2 +- WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php | 2 +- WordPress/Tests/PHP/DiscourageGotoUnitTest.php | 2 +- WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php | 2 +- WordPress/Tests/PHP/DontExtractUnitTest.php | 2 +- WordPress/Tests/PHP/NoSilencedErrorsUnitTest.php | 2 +- WordPress/Tests/PHP/POSIXFunctionsUnitTest.php | 2 +- WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.php | 2 +- WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php | 2 +- WordPress/Tests/PHP/StrictComparisonsUnitTest.php | 2 +- WordPress/Tests/PHP/StrictInArrayUnitTest.php | 2 +- WordPress/Tests/PHP/TypeCastsUnitTest.php | 4 ++-- WordPress/Tests/PHP/YodaConditionsUnitTest.php | 2 +- WordPress/Tests/Security/EscapeOutputUnitTest.php | 2 +- WordPress/Tests/Security/NonceVerificationUnitTest.php | 2 +- WordPress/Tests/Security/PluginMenuSlugUnitTest.php | 2 +- WordPress/Tests/Security/SafeRedirectUnitTest.php | 2 +- .../Tests/Security/ValidatedSanitizedInputUnitTest.php | 2 +- WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php | 2 +- WordPress/Tests/WP/AlternativeFunctionsUnitTest.php | 2 +- WordPress/Tests/WP/CapitalPDangitUnitTest.php | 2 +- WordPress/Tests/WP/CronIntervalUnitTest.php | 2 +- WordPress/Tests/WP/DeprecatedClassesUnitTest.php | 2 +- WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php | 2 +- WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.php | 2 +- WordPress/Tests/WP/DeprecatedParametersUnitTest.php | 2 +- WordPress/Tests/WP/DiscouragedConstantsUnitTest.php | 2 +- WordPress/Tests/WP/DiscouragedFunctionsUnitTest.php | 2 +- WordPress/Tests/WP/EnqueuedResourceParametersUnitTest.php | 2 +- WordPress/Tests/WP/EnqueuedResourcesUnitTest.php | 2 +- WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php | 2 +- WordPress/Tests/WP/I18nUnitTest.php | 4 ++-- WordPress/Tests/WP/PostsPerPageUnitTest.php | 2 +- WordPress/Tests/WP/TimezoneChangeUnitTest.php | 2 +- .../WhiteSpace/ArbitraryParenthesesSpacingUnitTest.php | 2 +- WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.php | 2 +- .../Tests/WhiteSpace/ControlStructureSpacingUnitTest.php | 4 ++-- WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php | 2 +- WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php | 2 +- WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php | 4 ++-- WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.php | 2 +- WordPress/ruleset.xml | 2 +- 129 files changed, 205 insertions(+), 203 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index a70d94d195..861f5a6c56 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -51,9 +51,9 @@ To this end, the `WordPress\Sniff::has_whitelist_comment()` method was introduce Example usage: ```php -namespace WordPress\Sniffs\Security; +namespace WordPressCS\WordPress\Sniffs\Security; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; class NonceVerificationSniff extends Sniff { @@ -154,7 +154,7 @@ Lets take a look at what's inside `POSIXFunctionsUnitTest.php`: ```php ... -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/AbstractArrayAssignmentRestrictionsSniff.php b/WordPress/AbstractArrayAssignmentRestrictionsSniff.php index 1f9001a023..fff3a71fc8 100644 --- a/WordPress/AbstractArrayAssignmentRestrictionsSniff.php +++ b/WordPress/AbstractArrayAssignmentRestrictionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress; +namespace WordPressCS\WordPress; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; /** * Restricts array assignment of certain keys. diff --git a/WordPress/AbstractClassRestrictionsSniff.php b/WordPress/AbstractClassRestrictionsSniff.php index f41cd138e8..05b0dcc5b7 100644 --- a/WordPress/AbstractClassRestrictionsSniff.php +++ b/WordPress/AbstractClassRestrictionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress; +namespace WordPressCS\WordPress; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Restricts usage of some classes. diff --git a/WordPress/AbstractFunctionParameterSniff.php b/WordPress/AbstractFunctionParameterSniff.php index df9350eb2b..5c059a6df2 100644 --- a/WordPress/AbstractFunctionParameterSniff.php +++ b/WordPress/AbstractFunctionParameterSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress; +namespace WordPressCS\WordPress; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Advises about parameters used in function calls. diff --git a/WordPress/AbstractFunctionRestrictionsSniff.php b/WordPress/AbstractFunctionRestrictionsSniff.php index 1b2dff3cab..416cffe049 100644 --- a/WordPress/AbstractFunctionRestrictionsSniff.php +++ b/WordPress/AbstractFunctionRestrictionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress; +namespace WordPressCS\WordPress; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/PHPCSAliases.php b/WordPress/PHPCSAliases.php index f82bac41a1..ec2fead98e 100644 --- a/WordPress/PHPCSAliases.php +++ b/WordPress/PHPCSAliases.php @@ -64,10 +64,12 @@ class_alias( 'PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SemicolonSpacing spl_autoload_register( function ( $class ) { // Only try & load our own classes. - if ( stripos( $class, 'WordPress' ) !== 0 ) { + if ( stripos( $class, 'WordPressCS' ) !== 0 ) { return; } + $class = str_replace( 'WordPressCS\\', '', $class ); + // PHPCS handles the Test and Sniff classes without problem. if ( stripos( $class, '\Tests\\' ) !== false || stripos( $class, '\Sniffs\\' ) !== false ) { return; diff --git a/WordPress/PHPCSHelper.php b/WordPress/PHPCSHelper.php index 7f20081559..9602e3c61d 100644 --- a/WordPress/PHPCSHelper.php +++ b/WordPress/PHPCSHelper.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress; +namespace WordPressCS\WordPress; use PHP_CodeSniffer_File as File; diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 92660c6a5b..96fa9978e4 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -7,12 +7,12 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress; +namespace WordPressCS\WordPress; use PHP_CodeSniffer_Sniff as PHPCS_Sniff; use PHP_CodeSniffer_File as File; use PHP_CodeSniffer_Tokens as Tokens; -use WordPress\PHPCSHelper; +use WordPressCS\WordPress\PHPCSHelper; /** * Represents a PHP_CodeSniffer sniff for sniffing WordPress coding standards. diff --git a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php index 9d482c233c..59cd9a8613 100644 --- a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Arrays; +namespace WordPressCS\WordPress\Sniffs\Arrays; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php b/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php index 96eb4f0dfb..35aa361606 100644 --- a/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Arrays; +namespace WordPressCS\WordPress\Sniffs\Arrays; -use WordPress\Sniff; -use WordPress\PHPCSHelper; +use WordPressCS\WordPress\Sniff; +use WordPressCS\WordPress\PHPCSHelper; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php b/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php index 9cd040fc14..0ef102e891 100644 --- a/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Arrays; +namespace WordPressCS\WordPress\Sniffs\Arrays; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; /** * Check for proper spacing in array key references. diff --git a/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php b/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php index 80ffde2727..648fc687cb 100644 --- a/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php +++ b/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Arrays; +namespace WordPressCS\WordPress\Sniffs\Arrays; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/Arrays/MultipleStatementAlignmentSniff.php b/WordPress/Sniffs/Arrays/MultipleStatementAlignmentSniff.php index d06994b883..ccecf224a7 100644 --- a/WordPress/Sniffs/Arrays/MultipleStatementAlignmentSniff.php +++ b/WordPress/Sniffs/Arrays/MultipleStatementAlignmentSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Arrays; +namespace WordPressCS\WordPress\Sniffs\Arrays; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; /** * Enforces alignment of the double arrow assignment operator for multi-item, multi-line arrays. diff --git a/WordPress/Sniffs/Classes/ClassInstantiationSniff.php b/WordPress/Sniffs/Classes/ClassInstantiationSniff.php index e68f0733b2..ca6c078de8 100644 --- a/WordPress/Sniffs/Classes/ClassInstantiationSniff.php +++ b/WordPress/Sniffs/Classes/ClassInstantiationSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Classes; +namespace WordPressCS\WordPress\Sniffs\Classes; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/CodeAnalysis/AssignmentInConditionSniff.php b/WordPress/Sniffs/CodeAnalysis/AssignmentInConditionSniff.php index 901df2503e..cf61fa6d86 100644 --- a/WordPress/Sniffs/CodeAnalysis/AssignmentInConditionSniff.php +++ b/WordPress/Sniffs/CodeAnalysis/AssignmentInConditionSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\CodeAnalysis; +namespace WordPressCS\WordPress\Sniffs\CodeAnalysis; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php b/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php index 2eff890987..927e89d714 100644 --- a/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php +++ b/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\CodeAnalysis; +namespace WordPressCS\WordPress\Sniffs\CodeAnalysis; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php b/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php index b1339e778f..fcc9467628 100644 --- a/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php +++ b/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\DB; +namespace WordPressCS\WordPress\Sniffs\DB; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php b/WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php index b4dafe6a17..baf5f254e5 100644 --- a/WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php +++ b/WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\DB; +namespace WordPressCS\WordPress\Sniffs\DB; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/DB/PreparedSQLSniff.php b/WordPress/Sniffs/DB/PreparedSQLSniff.php index 38f1e012fa..6084f1aabd 100644 --- a/WordPress/Sniffs/DB/PreparedSQLSniff.php +++ b/WordPress/Sniffs/DB/PreparedSQLSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\DB; +namespace WordPressCS\WordPress\Sniffs\DB; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/DB/RestrictedClassesSniff.php b/WordPress/Sniffs/DB/RestrictedClassesSniff.php index 3b6828cd7d..564a629ace 100644 --- a/WordPress/Sniffs/DB/RestrictedClassesSniff.php +++ b/WordPress/Sniffs/DB/RestrictedClassesSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\DB; +namespace WordPressCS\WordPress\Sniffs\DB; -use WordPress\AbstractClassRestrictionsSniff; +use WordPressCS\WordPress\AbstractClassRestrictionsSniff; /** * Verifies that no database related PHP classes are used. diff --git a/WordPress/Sniffs/DB/RestrictedFunctionsSniff.php b/WordPress/Sniffs/DB/RestrictedFunctionsSniff.php index b80883b76f..1981f3a8e0 100644 --- a/WordPress/Sniffs/DB/RestrictedFunctionsSniff.php +++ b/WordPress/Sniffs/DB/RestrictedFunctionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\DB; +namespace WordPressCS\WordPress\Sniffs\DB; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Verifies that no database related PHP functions are used. diff --git a/WordPress/Sniffs/DB/SlowDBQuerySniff.php b/WordPress/Sniffs/DB/SlowDBQuerySniff.php index e7592df1af..6935aae40c 100644 --- a/WordPress/Sniffs/DB/SlowDBQuerySniff.php +++ b/WordPress/Sniffs/DB/SlowDBQuerySniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\DB; +namespace WordPressCS\WordPress\Sniffs\DB; -use WordPress\AbstractArrayAssignmentRestrictionsSniff; +use WordPressCS\WordPress\AbstractArrayAssignmentRestrictionsSniff; /** * Flag potentially slow queries. diff --git a/WordPress/Sniffs/Files/FileNameSniff.php b/WordPress/Sniffs/Files/FileNameSniff.php index 057dc2bb6b..797d277d31 100644 --- a/WordPress/Sniffs/Files/FileNameSniff.php +++ b/WordPress/Sniffs/Files/FileNameSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Files; +namespace WordPressCS\WordPress\Sniffs\Files; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; /** * Ensures filenames do not contain underscores. diff --git a/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php b/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php index 820abc09b5..39759683d4 100644 --- a/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php +++ b/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Functions; +namespace WordPressCS\WordPress\Sniffs\Functions; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index 43d5a2b9a7..f915c671ec 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\NamingConventions; +namespace WordPressCS\WordPress\Sniffs\NamingConventions; -use WordPress\AbstractFunctionParameterSniff; -use WordPress\PHPCSHelper; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\PHPCSHelper; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php index dc72792185..7b3c456aec 100644 --- a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\NamingConventions; +namespace WordPressCS\WordPress\Sniffs\NamingConventions; use PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff as PHPCS_PEAR_ValidFunctionNameSniff; use PHP_CodeSniffer_File as File; diff --git a/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php index 7d7dcccff7..e72dd0992f 100644 --- a/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\NamingConventions; +namespace WordPressCS\WordPress\Sniffs\NamingConventions; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; /** * Use lowercase letters in action and filter names. Separate words via underscores. diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index 2325514ad2..67881d8cb3 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -7,12 +7,12 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\NamingConventions; +namespace WordPressCS\WordPress\Sniffs\NamingConventions; use PHP_CodeSniffer_Standards_AbstractVariableSniff as PHPCS_AbstractVariableSniff; use PHP_CodeSniffer_File as File; use PHP_CodeSniffer_Tokens as Tokens; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; /** * Checks the naming of variables and member variables. diff --git a/WordPress/Sniffs/PHP/DevelopmentFunctionsSniff.php b/WordPress/Sniffs/PHP/DevelopmentFunctionsSniff.php index 0b910ce30e..79fe642bca 100644 --- a/WordPress/Sniffs/PHP/DevelopmentFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/DevelopmentFunctionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Restrict the use of various development functions. diff --git a/WordPress/Sniffs/PHP/DiscourageGotoSniff.php b/WordPress/Sniffs/PHP/DiscourageGotoSniff.php index f41433961e..5e2ce7ede5 100644 --- a/WordPress/Sniffs/PHP/DiscourageGotoSniff.php +++ b/WordPress/Sniffs/PHP/DiscourageGotoSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; /** * Discourage the use of the PHP `goto` language construct. diff --git a/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php b/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php index 8f275f4c6f..f7d613df83 100644 --- a/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Discourages the use of various native PHP functions and suggests alternatives. diff --git a/WordPress/Sniffs/PHP/DontExtractSniff.php b/WordPress/Sniffs/PHP/DontExtractSniff.php index be4f823bdc..6db447ad0d 100644 --- a/WordPress/Sniffs/PHP/DontExtractSniff.php +++ b/WordPress/Sniffs/PHP/DontExtractSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Restricts the usage of extract(). diff --git a/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php b/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php index fca1f28fd5..d80653ccaf 100644 --- a/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php +++ b/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php b/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php index b1631c7153..a7e1b0be7b 100644 --- a/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Perl compatible regular expressions (PCRE, preg_ functions) should be used in preference diff --git a/WordPress/Sniffs/PHP/PregQuoteDelimiterSniff.php b/WordPress/Sniffs/PHP/PregQuoteDelimiterSniff.php index 87a668e086..f5e1a5a8ce 100644 --- a/WordPress/Sniffs/PHP/PregQuoteDelimiterSniff.php +++ b/WordPress/Sniffs/PHP/PregQuoteDelimiterSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; /** * Flag calling preg_quote() without the second ($delimiter) parameter. diff --git a/WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php b/WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php index 235db95e51..6bde3337d4 100644 --- a/WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Forbids the use of various native PHP functions and suggests alternatives. diff --git a/WordPress/Sniffs/PHP/StrictComparisonsSniff.php b/WordPress/Sniffs/PHP/StrictComparisonsSniff.php index ec43f504cd..97f3c4e406 100644 --- a/WordPress/Sniffs/PHP/StrictComparisonsSniff.php +++ b/WordPress/Sniffs/PHP/StrictComparisonsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; /** * Enforces Strict Comparison checks, based upon Squiz code. diff --git a/WordPress/Sniffs/PHP/StrictInArraySniff.php b/WordPress/Sniffs/PHP/StrictInArraySniff.php index c5ac94c9ed..f74f3f491d 100644 --- a/WordPress/Sniffs/PHP/StrictInArraySniff.php +++ b/WordPress/Sniffs/PHP/StrictInArraySniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; /** * Flag calling in_array(), array_search() and array_keys() without true as the third parameter. diff --git a/WordPress/Sniffs/PHP/TypeCastsSniff.php b/WordPress/Sniffs/PHP/TypeCastsSniff.php index c35afac4df..6c411bb9b9 100644 --- a/WordPress/Sniffs/PHP/TypeCastsSniff.php +++ b/WordPress/Sniffs/PHP/TypeCastsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/PHP/YodaConditionsSniff.php b/WordPress/Sniffs/PHP/YodaConditionsSniff.php index cd1f2997db..554c3446fa 100644 --- a/WordPress/Sniffs/PHP/YodaConditionsSniff.php +++ b/WordPress/Sniffs/PHP/YodaConditionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/Security/EscapeOutputSniff.php b/WordPress/Sniffs/Security/EscapeOutputSniff.php index abb66540d0..9f29183341 100644 --- a/WordPress/Sniffs/Security/EscapeOutputSniff.php +++ b/WordPress/Sniffs/Security/EscapeOutputSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Security; +namespace WordPressCS\WordPress\Sniffs\Security; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/Security/NonceVerificationSniff.php b/WordPress/Sniffs/Security/NonceVerificationSniff.php index 4909a01f99..d42e544290 100644 --- a/WordPress/Sniffs/Security/NonceVerificationSniff.php +++ b/WordPress/Sniffs/Security/NonceVerificationSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Security; +namespace WordPressCS\WordPress\Sniffs\Security; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; /** * Checks that nonce verification accompanies form processing. diff --git a/WordPress/Sniffs/Security/PluginMenuSlugSniff.php b/WordPress/Sniffs/Security/PluginMenuSlugSniff.php index 31b6447edb..65627ae624 100644 --- a/WordPress/Sniffs/Security/PluginMenuSlugSniff.php +++ b/WordPress/Sniffs/Security/PluginMenuSlugSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Security; +namespace WordPressCS\WordPress\Sniffs\Security; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; /** * Warn about __FILE__ for page registration. diff --git a/WordPress/Sniffs/Security/SafeRedirectSniff.php b/WordPress/Sniffs/Security/SafeRedirectSniff.php index d4cebdf567..4d14631356 100644 --- a/WordPress/Sniffs/Security/SafeRedirectSniff.php +++ b/WordPress/Sniffs/Security/SafeRedirectSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Security; +namespace WordPressCS\WordPress\Sniffs\Security; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Encourages use of wp_safe_redirect() to avoid open redirect vulnerabilities. diff --git a/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php b/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php index 25756ce294..b79e56f4b7 100644 --- a/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php +++ b/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Security; +namespace WordPressCS\WordPress\Sniffs\Security; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; /** * Flag any non-validated/sanitized input ( _GET / _POST / etc. ). diff --git a/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php b/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php index e243c3d82a..9f5663af18 100644 --- a/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php +++ b/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Utils; +namespace WordPressCS\WordPress\Sniffs\Utils; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php index e5d700c506..b5daef4f98 100644 --- a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php +++ b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Discourages the use of various functions and suggests (WordPress) alternatives. diff --git a/WordPress/Sniffs/WP/CapitalPDangitSniff.php b/WordPress/Sniffs/WP/CapitalPDangitSniff.php index fbe621bded..d29d721bcf 100644 --- a/WordPress/Sniffs/WP/CapitalPDangitSniff.php +++ b/WordPress/Sniffs/WP/CapitalPDangitSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WP/CronIntervalSniff.php b/WordPress/Sniffs/WP/CronIntervalSniff.php index 7cf2dd868d..0d9121dccb 100644 --- a/WordPress/Sniffs/WP/CronIntervalSniff.php +++ b/WordPress/Sniffs/WP/CronIntervalSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WP/DeprecatedClassesSniff.php b/WordPress/Sniffs/WP/DeprecatedClassesSniff.php index 9d46fddc70..a011d0fc3f 100644 --- a/WordPress/Sniffs/WP/DeprecatedClassesSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedClassesSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractClassRestrictionsSniff; +use WordPressCS\WordPress\AbstractClassRestrictionsSniff; /** * Restricts the use of deprecated WordPress classes and suggests alternatives. diff --git a/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php b/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php index df4ccdaeb4..15adbc5307 100644 --- a/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Restricts the use of various deprecated WordPress functions and suggests alternatives. diff --git a/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php b/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php index f49d7de011..32ca928cc7 100644 --- a/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WP/DeprecatedParametersSniff.php b/WordPress/Sniffs/WP/DeprecatedParametersSniff.php index 4772cb08e1..08980292d6 100644 --- a/WordPress/Sniffs/WP/DeprecatedParametersSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedParametersSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; /** * Check for usage of deprecated parameters in WP functions and suggest alternative based on the parameter passed. diff --git a/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php b/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php index 125b68a48a..7b6268a8b4 100644 --- a/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php +++ b/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WP/DiscouragedFunctionsSniff.php b/WordPress/Sniffs/WP/DiscouragedFunctionsSniff.php index 92b3797b92..ba640858f6 100644 --- a/WordPress/Sniffs/WP/DiscouragedFunctionsSniff.php +++ b/WordPress/Sniffs/WP/DiscouragedFunctionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Discourages the use of various WordPress functions and suggests alternatives. diff --git a/WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php b/WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php index a2bbe39b7c..93007651f9 100644 --- a/WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php +++ b/WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php index d3fa7861aa..900a10ba7a 100644 --- a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php +++ b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php index 1d628bbab3..9aae552517 100644 --- a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php +++ b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WP/I18nSniff.php b/WordPress/Sniffs/WP/I18nSniff.php index 427846d52e..0628a10b2f 100644 --- a/WordPress/Sniffs/WP/I18nSniff.php +++ b/WordPress/Sniffs/WP/I18nSniff.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractFunctionRestrictionsSniff; -use WordPress\PHPCSHelper; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\PHPCSHelper; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WP/PostsPerPageSniff.php b/WordPress/Sniffs/WP/PostsPerPageSniff.php index 22f7ef04f7..8e45afe78d 100644 --- a/WordPress/Sniffs/WP/PostsPerPageSniff.php +++ b/WordPress/Sniffs/WP/PostsPerPageSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractArrayAssignmentRestrictionsSniff; +use WordPressCS\WordPress\AbstractArrayAssignmentRestrictionsSniff; /** * Flag returning high or infinite posts_per_page. diff --git a/WordPress/Sniffs/WP/TimezoneChangeSniff.php b/WordPress/Sniffs/WP/TimezoneChangeSniff.php index 1755c7497f..5970e19b1c 100644 --- a/WordPress/Sniffs/WP/TimezoneChangeSniff.php +++ b/WordPress/Sniffs/WP/TimezoneChangeSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Disallow the changing of timezone. diff --git a/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php index 41df4a33c8..2a139f5f5a 100644 --- a/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WhiteSpace; +namespace WordPressCS\WordPress\Sniffs\WhiteSpace; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php index a239cb4d13..a71b7a7663 100755 --- a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WhiteSpace; +namespace WordPressCS\WordPress\Sniffs\WhiteSpace; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php index 4f8317c774..0d46e52853 100644 --- a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WhiteSpace; +namespace WordPressCS\WordPress\Sniffs\WhiteSpace; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php b/WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php index 7d2411721b..6539def540 100644 --- a/WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php +++ b/WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WhiteSpace; +namespace WordPressCS\WordPress\Sniffs\WhiteSpace; -use WordPress\Sniff; -use WordPress\PHPCSHelper; +use WordPressCS\WordPress\Sniff; +use WordPressCS\WordPress\PHPCSHelper; /** * Enforces using spaces for mid-line alignment. diff --git a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php index 71e1e332b8..3b6499e012 100644 --- a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WhiteSpace; +namespace WordPressCS\WordPress\Sniffs\WhiteSpace; use Squiz_Sniffs_WhiteSpace_OperatorSpacingSniff as PHPCS_Squiz_OperatorSpacingSniff; use PHP_CodeSniffer_Tokens as Tokens; diff --git a/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php b/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php index b287d4a12b..646690cade 100644 --- a/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php +++ b/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WhiteSpace; +namespace WordPressCS\WordPress\Sniffs\WhiteSpace; -use WordPress\Sniff; -use WordPress\PHPCSHelper; +use WordPressCS\WordPress\Sniff; +use WordPressCS\WordPress\PHPCSHelper; /** * Warn on line indentation ending with spaces for precision alignment. diff --git a/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php index 6dfe818784..5a9b6511a0 100644 --- a/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WhiteSpace; +namespace WordPressCS\WordPress\Sniffs\WhiteSpace; use Squiz_Sniffs_WhiteSpace_SemicolonSpacingSniff as PHPCS_Squiz_SemicolonSpacingSniff; use PHP_CodeSniffer_File as File; diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php index ff6d212ae0..3114e175bf 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Arrays; +namespace WordPressCS\WordPress\Tests\Arrays; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Arrays/ArrayIndentationUnitTest.php b/WordPress/Tests/Arrays/ArrayIndentationUnitTest.php index 2d8987ea6d..91cbb4ce78 100644 --- a/WordPress/Tests/Arrays/ArrayIndentationUnitTest.php +++ b/WordPress/Tests/Arrays/ArrayIndentationUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Arrays; +namespace WordPressCS\WordPress\Tests\Arrays; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Arrays/ArrayKeySpacingRestrictionsUnitTest.php b/WordPress/Tests/Arrays/ArrayKeySpacingRestrictionsUnitTest.php index b2f53dfcd1..a688f67ef1 100644 --- a/WordPress/Tests/Arrays/ArrayKeySpacingRestrictionsUnitTest.php +++ b/WordPress/Tests/Arrays/ArrayKeySpacingRestrictionsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Arrays; +namespace WordPressCS\WordPress\Tests\Arrays; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Arrays/CommaAfterArrayItemUnitTest.php b/WordPress/Tests/Arrays/CommaAfterArrayItemUnitTest.php index dab0c93dda..7763f55ee5 100644 --- a/WordPress/Tests/Arrays/CommaAfterArrayItemUnitTest.php +++ b/WordPress/Tests/Arrays/CommaAfterArrayItemUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Arrays; +namespace WordPressCS\WordPress\Tests\Arrays; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.php b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.php index 9342e9b413..58a0c04db7 100644 --- a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.php +++ b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Arrays; +namespace WordPressCS\WordPress\Tests\Arrays; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Classes/ClassInstantiationUnitTest.php b/WordPress/Tests/Classes/ClassInstantiationUnitTest.php index dfb13722e1..d06cb98de0 100644 --- a/WordPress/Tests/Classes/ClassInstantiationUnitTest.php +++ b/WordPress/Tests/Classes/ClassInstantiationUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Classes; +namespace WordPressCS\WordPress\Tests\Classes; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/CodeAnalysis/AssignmentInConditionUnitTest.php b/WordPress/Tests/CodeAnalysis/AssignmentInConditionUnitTest.php index 70cc630411..f92dcbeb02 100644 --- a/WordPress/Tests/CodeAnalysis/AssignmentInConditionUnitTest.php +++ b/WordPress/Tests/CodeAnalysis/AssignmentInConditionUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\CodeAnalysis; +namespace WordPressCS\WordPress\Tests\CodeAnalysis; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php b/WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php index 69b1e091c4..31e7bb55d4 100644 --- a/WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php +++ b/WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\CodeAnalysis; +namespace WordPressCS\WordPress\Tests\CodeAnalysis; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/DB/DirectDatabaseQueryUnitTest.php b/WordPress/Tests/DB/DirectDatabaseQueryUnitTest.php index e51571a0bb..bb527e39f1 100644 --- a/WordPress/Tests/DB/DirectDatabaseQueryUnitTest.php +++ b/WordPress/Tests/DB/DirectDatabaseQueryUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\DB; +namespace WordPressCS\WordPress\Tests\DB; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php b/WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php index f60e901a9b..87a35ea00a 100644 --- a/WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php +++ b/WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\DB; +namespace WordPressCS\WordPress\Tests\DB; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/DB/PreparedSQLUnitTest.php b/WordPress/Tests/DB/PreparedSQLUnitTest.php index d29beeb41b..d0ef7ec47d 100644 --- a/WordPress/Tests/DB/PreparedSQLUnitTest.php +++ b/WordPress/Tests/DB/PreparedSQLUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\DB; +namespace WordPressCS\WordPress\Tests\DB; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/DB/RestrictedClassesUnitTest.php b/WordPress/Tests/DB/RestrictedClassesUnitTest.php index 3db48852bb..c15d35543a 100644 --- a/WordPress/Tests/DB/RestrictedClassesUnitTest.php +++ b/WordPress/Tests/DB/RestrictedClassesUnitTest.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\DB; +namespace WordPressCS\WordPress\Tests\DB; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Unit test class for the DB_RestrictedClasses sniff. diff --git a/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php b/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php index fda5c14b8a..362500ecfc 100644 --- a/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php +++ b/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\DB; +namespace WordPressCS\WordPress\Tests\DB; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/DB/SlowDBQueryUnitTest.php b/WordPress/Tests/DB/SlowDBQueryUnitTest.php index d16dc09764..2c0d64d2ef 100644 --- a/WordPress/Tests/DB/SlowDBQueryUnitTest.php +++ b/WordPress/Tests/DB/SlowDBQueryUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\DB; +namespace WordPressCS\WordPress\Tests\DB; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Files/FileNameUnitTest.php b/WordPress/Tests/Files/FileNameUnitTest.php index aeb4e6a902..363c0fa353 100644 --- a/WordPress/Tests/Files/FileNameUnitTest.php +++ b/WordPress/Tests/Files/FileNameUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Files; +namespace WordPressCS\WordPress\Tests\Files; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Functions/FunctionCallSignatureNoParamsUnitTest.php b/WordPress/Tests/Functions/FunctionCallSignatureNoParamsUnitTest.php index 4cd24ee675..ac3a917a03 100644 --- a/WordPress/Tests/Functions/FunctionCallSignatureNoParamsUnitTest.php +++ b/WordPress/Tests/Functions/FunctionCallSignatureNoParamsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Functions; +namespace WordPressCS\WordPress\Tests\Functions; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php index a1cec251b2..80a4872014 100644 --- a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php +++ b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\NamingConventions; +namespace WordPressCS\WordPress\Tests\NamingConventions; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php index b07e588a85..dc239337bc 100644 --- a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php +++ b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\NamingConventions; +namespace WordPressCS\WordPress\Tests\NamingConventions; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php index eaa60ad06e..b128f1da7b 100644 --- a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php +++ b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\NamingConventions; +namespace WordPressCS\WordPress\Tests\NamingConventions; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php index 6f618af88a..792d62c3e6 100644 --- a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php +++ b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\NamingConventions; +namespace WordPressCS\WordPress\Tests\NamingConventions; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php b/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php index 32cb4129b2..aef75ef7e1 100644 --- a/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/DiscourageGotoUnitTest.php b/WordPress/Tests/PHP/DiscourageGotoUnitTest.php index 707e4ff71b..0caccfb4e9 100644 --- a/WordPress/Tests/PHP/DiscourageGotoUnitTest.php +++ b/WordPress/Tests/PHP/DiscourageGotoUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php b/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php index 13d0318de8..db73fe44bd 100644 --- a/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/DontExtractUnitTest.php b/WordPress/Tests/PHP/DontExtractUnitTest.php index e98d40a58b..c8862b6b7f 100644 --- a/WordPress/Tests/PHP/DontExtractUnitTest.php +++ b/WordPress/Tests/PHP/DontExtractUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.php b/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.php index aab38db9bd..b9db72b0f5 100644 --- a/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.php +++ b/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/POSIXFunctionsUnitTest.php b/WordPress/Tests/PHP/POSIXFunctionsUnitTest.php index f9d6f0826f..13dbdecc3c 100644 --- a/WordPress/Tests/PHP/POSIXFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/POSIXFunctionsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.php b/WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.php index 1ae222bc49..0615bbca22 100644 --- a/WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.php +++ b/WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php index f98c9b674d..e39e473eb5 100644 --- a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/StrictComparisonsUnitTest.php b/WordPress/Tests/PHP/StrictComparisonsUnitTest.php index 4868462cc5..2f4c95d19c 100644 --- a/WordPress/Tests/PHP/StrictComparisonsUnitTest.php +++ b/WordPress/Tests/PHP/StrictComparisonsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/StrictInArrayUnitTest.php b/WordPress/Tests/PHP/StrictInArrayUnitTest.php index 44a77f8ba7..66c9ed19b7 100644 --- a/WordPress/Tests/PHP/StrictInArrayUnitTest.php +++ b/WordPress/Tests/PHP/StrictInArrayUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/TypeCastsUnitTest.php b/WordPress/Tests/PHP/TypeCastsUnitTest.php index fbce6135c9..cdd88bbb68 100644 --- a/WordPress/Tests/PHP/TypeCastsUnitTest.php +++ b/WordPress/Tests/PHP/TypeCastsUnitTest.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -use WordPress\PHPCSHelper; +use WordPressCS\WordPress\PHPCSHelper; /** * Unit test class for the TypeCasts sniff. diff --git a/WordPress/Tests/PHP/YodaConditionsUnitTest.php b/WordPress/Tests/PHP/YodaConditionsUnitTest.php index 8630b11e28..9640da2b7d 100644 --- a/WordPress/Tests/PHP/YodaConditionsUnitTest.php +++ b/WordPress/Tests/PHP/YodaConditionsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Security/EscapeOutputUnitTest.php b/WordPress/Tests/Security/EscapeOutputUnitTest.php index be2ef97053..91a97215dc 100644 --- a/WordPress/Tests/Security/EscapeOutputUnitTest.php +++ b/WordPress/Tests/Security/EscapeOutputUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Security; +namespace WordPressCS\WordPress\Tests\Security; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Security/NonceVerificationUnitTest.php b/WordPress/Tests/Security/NonceVerificationUnitTest.php index 0e1281f213..a7935c9557 100644 --- a/WordPress/Tests/Security/NonceVerificationUnitTest.php +++ b/WordPress/Tests/Security/NonceVerificationUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Security; +namespace WordPressCS\WordPress\Tests\Security; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Security/PluginMenuSlugUnitTest.php b/WordPress/Tests/Security/PluginMenuSlugUnitTest.php index e3c56bb1c5..9141fa90a1 100644 --- a/WordPress/Tests/Security/PluginMenuSlugUnitTest.php +++ b/WordPress/Tests/Security/PluginMenuSlugUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Security; +namespace WordPressCS\WordPress\Tests\Security; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Security/SafeRedirectUnitTest.php b/WordPress/Tests/Security/SafeRedirectUnitTest.php index 18919d8f9f..14e4686f11 100644 --- a/WordPress/Tests/Security/SafeRedirectUnitTest.php +++ b/WordPress/Tests/Security/SafeRedirectUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Security; +namespace WordPressCS\WordPress\Tests\Security; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php index 5499dcf3e2..9eed79b4e8 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Security; +namespace WordPressCS\WordPress\Tests\Security; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php b/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php index 58d450a282..90e3df8ddd 100644 --- a/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php +++ b/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Utils; +namespace WordPressCS\WordPress\Tests\Utils; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php index 2373403f0d..36ea1bcb51 100644 --- a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php +++ b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/CapitalPDangitUnitTest.php b/WordPress/Tests/WP/CapitalPDangitUnitTest.php index 4024166a70..494b03a72b 100644 --- a/WordPress/Tests/WP/CapitalPDangitUnitTest.php +++ b/WordPress/Tests/WP/CapitalPDangitUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/CronIntervalUnitTest.php b/WordPress/Tests/WP/CronIntervalUnitTest.php index 2f3b5fcf6c..be5cc9f6b8 100644 --- a/WordPress/Tests/WP/CronIntervalUnitTest.php +++ b/WordPress/Tests/WP/CronIntervalUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/DeprecatedClassesUnitTest.php b/WordPress/Tests/WP/DeprecatedClassesUnitTest.php index 76768770f6..c70673deb2 100644 --- a/WordPress/Tests/WP/DeprecatedClassesUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedClassesUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php index f9bbc40a27..5fbce22ce0 100644 --- a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.php b/WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.php index 0eac82ec29..f128e6fb34 100644 --- a/WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/DeprecatedParametersUnitTest.php b/WordPress/Tests/WP/DeprecatedParametersUnitTest.php index d79572315d..ffbc573474 100644 --- a/WordPress/Tests/WP/DeprecatedParametersUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedParametersUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/DiscouragedConstantsUnitTest.php b/WordPress/Tests/WP/DiscouragedConstantsUnitTest.php index 05a607fc49..8437893bb0 100644 --- a/WordPress/Tests/WP/DiscouragedConstantsUnitTest.php +++ b/WordPress/Tests/WP/DiscouragedConstantsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.php b/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.php index 0aa80697fc..4491430637 100644 --- a/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.php +++ b/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/EnqueuedResourceParametersUnitTest.php b/WordPress/Tests/WP/EnqueuedResourceParametersUnitTest.php index bcfbb15f92..8e60e6b57d 100644 --- a/WordPress/Tests/WP/EnqueuedResourceParametersUnitTest.php +++ b/WordPress/Tests/WP/EnqueuedResourceParametersUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/EnqueuedResourcesUnitTest.php b/WordPress/Tests/WP/EnqueuedResourcesUnitTest.php index 77078c498a..2b0da6f255 100644 --- a/WordPress/Tests/WP/EnqueuedResourcesUnitTest.php +++ b/WordPress/Tests/WP/EnqueuedResourcesUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php b/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php index 28340d8b9a..9739e83258 100644 --- a/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php +++ b/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/I18nUnitTest.php b/WordPress/Tests/WP/I18nUnitTest.php index 6dc1c4a098..6f617b03cc 100644 --- a/WordPress/Tests/WP/I18nUnitTest.php +++ b/WordPress/Tests/WP/I18nUnitTest.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -use WordPress\PHPCSHelper; +use WordPressCS\WordPress\PHPCSHelper; /** * Unit test class for the I18n sniff. diff --git a/WordPress/Tests/WP/PostsPerPageUnitTest.php b/WordPress/Tests/WP/PostsPerPageUnitTest.php index 233609bd8a..22dd5c0715 100644 --- a/WordPress/Tests/WP/PostsPerPageUnitTest.php +++ b/WordPress/Tests/WP/PostsPerPageUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/TimezoneChangeUnitTest.php b/WordPress/Tests/WP/TimezoneChangeUnitTest.php index 6f16015319..2b623f644a 100644 --- a/WordPress/Tests/WP/TimezoneChangeUnitTest.php +++ b/WordPress/Tests/WP/TimezoneChangeUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.php index 66c2ddfcc3..e2c3ef9218 100644 --- a/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.php +++ b/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WhiteSpace; +namespace WordPressCS\WordPress\Tests\WhiteSpace; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.php index 9cf81858e0..b90f1c1148 100644 --- a/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.php +++ b/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WhiteSpace; +namespace WordPressCS\WordPress\Tests\WhiteSpace; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php index f8d50e74f1..93e58a47c1 100644 --- a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php +++ b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WhiteSpace; +namespace WordPressCS\WordPress\Tests\WhiteSpace; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -use WordPress\PHPCSHelper; +use WordPressCS\WordPress\PHPCSHelper; /** * Unit test class for the ControlStructureSpacing sniff. diff --git a/WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php b/WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php index fe446801d6..13ee511a2d 100644 --- a/WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php +++ b/WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WhiteSpace; +namespace WordPressCS\WordPress\Tests\WhiteSpace; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php index 801cb15f09..ff7325c071 100644 --- a/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php +++ b/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WhiteSpace; +namespace WordPressCS\WordPress\Tests\WhiteSpace; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php index 714ed194cf..e62352c2fa 100644 --- a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php +++ b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WhiteSpace; +namespace WordPressCS\WordPress\Tests\WhiteSpace; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -use WordPress\PHPCSHelper; +use WordPressCS\WordPress\PHPCSHelper; /** * Unit test class for the PrecisionAlignment sniff. diff --git a/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.php index 0dcd1950ef..1078620c1c 100644 --- a/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.php +++ b/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WhiteSpace; +namespace WordPressCS\WordPress\Tests\WhiteSpace; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/ruleset.xml b/WordPress/ruleset.xml index bdcbff4736..f1a13d3860 100644 --- a/WordPress/ruleset.xml +++ b/WordPress/ruleset.xml @@ -1,5 +1,5 @@ - + WordPress Coding Standards ./PHPCSAliases.php From 9b70e001d9b34a9baa8ee6dc44bec1b392ae29c6 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 16:20:45 +0100 Subject: [PATCH 016/241] WPCS 2.0.0: Adjust use statements to use PHPCS 3.x class names ... and remove the aliases. --- .../AbstractFunctionRestrictionsSniff.php | 2 +- WordPress/PHPCSAliases.php | 39 ------------------- WordPress/PHPCSHelper.php | 2 +- WordPress/Sniff.php | 6 +-- .../Arrays/ArrayDeclarationSpacingSniff.php | 2 +- .../Sniffs/Arrays/ArrayIndentationSniff.php | 2 +- .../Arrays/CommaAfterArrayItemSniff.php | 2 +- .../Classes/ClassInstantiationSniff.php | 2 +- .../AssignmentInConditionSniff.php | 2 +- .../CodeAnalysis/EmptyStatementSniff.php | 2 +- .../Sniffs/DB/DirectDatabaseQuerySniff.php | 2 +- .../DB/PreparedSQLPlaceholdersSniff.php | 2 +- WordPress/Sniffs/DB/PreparedSQLSniff.php | 2 +- .../FunctionCallSignatureNoParamsSniff.php | 2 +- .../PrefixAllGlobalsSniff.php | 2 +- .../ValidFunctionNameSniff.php | 4 +- .../ValidVariableNameSniff.php | 6 +-- .../Sniffs/PHP/NoSilencedErrorsSniff.php | 2 +- WordPress/Sniffs/PHP/TypeCastsSniff.php | 2 +- WordPress/Sniffs/PHP/YodaConditionsSniff.php | 2 +- .../Sniffs/Security/EscapeOutputSniff.php | 2 +- .../Sniffs/Utils/I18nTextDomainFixerSniff.php | 2 +- WordPress/Sniffs/WP/CapitalPDangitSniff.php | 2 +- WordPress/Sniffs/WP/CronIntervalSniff.php | 2 +- .../WP/DeprecatedParameterValuesSniff.php | 2 +- .../Sniffs/WP/DiscouragedConstantsSniff.php | 2 +- .../WP/EnqueuedResourceParametersSniff.php | 2 +- .../Sniffs/WP/EnqueuedResourcesSniff.php | 2 +- .../WP/GlobalVariablesOverrideSniff.php | 2 +- WordPress/Sniffs/WP/I18nSniff.php | 2 +- .../ArbitraryParenthesesSpacingSniff.php | 2 +- .../WhiteSpace/CastStructureSpacingSniff.php | 2 +- .../ControlStructureSpacingSniff.php | 2 +- .../WhiteSpace/OperatorSpacingSniff.php | 4 +- .../WhiteSpace/SemicolonSpacingSniff.php | 6 +-- 35 files changed, 42 insertions(+), 81 deletions(-) diff --git a/WordPress/AbstractFunctionRestrictionsSniff.php b/WordPress/AbstractFunctionRestrictionsSniff.php index 416cffe049..1fbc24a4bd 100644 --- a/WordPress/AbstractFunctionRestrictionsSniff.php +++ b/WordPress/AbstractFunctionRestrictionsSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Restricts usage of some functions. diff --git a/WordPress/PHPCSAliases.php b/WordPress/PHPCSAliases.php index ec2fead98e..a2e1daabe0 100644 --- a/WordPress/PHPCSAliases.php +++ b/WordPress/PHPCSAliases.php @@ -8,46 +8,7 @@ * @since 0.13.0 */ -/* - * Alias a number of PHPCS 3.x classes to their PHPCS 2.x equivalents. - * - * This file is auto-loaded by PHPCS 3.x before any sniffs are loaded - * through the PHPCS 3.x `` ruleset directive. - * - * {@internal The PHPCS files have been reorganized in PHPCS 3.x, quite - * a few "old" classes have been split and spread out over several "new" - * classes. In other words, this will only work for a limited number - * of classes.}} - * - * {@internal The `class_exists` wrappers are needed to play nice with other - * external PHPCS standards creating cross-version compatibility in the same - * manner.}} - */ if ( ! \defined( 'WPCS_PHPCS_ALIASES_SET' ) ) { - // PHPCS base classes/interface. - if ( ! interface_exists( '\PHP_CodeSniffer_Sniff' ) ) { - class_alias( 'PHP_CodeSniffer\Sniffs\Sniff', '\PHP_CodeSniffer_Sniff' ); - } - if ( ! class_exists( '\PHP_CodeSniffer_File' ) ) { - class_alias( 'PHP_CodeSniffer\Files\File', '\PHP_CodeSniffer_File' ); - } - if ( ! class_exists( '\PHP_CodeSniffer_Tokens' ) ) { - class_alias( 'PHP_CodeSniffer\Util\Tokens', '\PHP_CodeSniffer_Tokens' ); - } - - // PHPCS classes which are being extended by WPCS sniffs. - if ( ! class_exists( '\PHP_CodeSniffer_Standards_AbstractVariableSniff' ) ) { - class_alias( 'PHP_CodeSniffer\Sniffs\AbstractVariableSniff', '\PHP_CodeSniffer_Standards_AbstractVariableSniff' ); - } - if ( ! class_exists( '\PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff' ) ) { - class_alias( 'PHP_CodeSniffer\Standards\PEAR\Sniffs\NamingConventions\ValidFunctionNameSniff', '\PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff' ); - } - if ( ! class_exists( '\Squiz_Sniffs_WhiteSpace_OperatorSpacingSniff' ) ) { - class_alias( 'PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\OperatorSpacingSniff', '\Squiz_Sniffs_WhiteSpace_OperatorSpacingSniff' ); - } - if ( ! class_exists( '\Squiz_Sniffs_WhiteSpace_SemicolonSpacingSniff' ) ) { - class_alias( 'PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SemicolonSpacingSniff', '\Squiz_Sniffs_WhiteSpace_SemicolonSpacingSniff' ); - } define( 'WPCS_PHPCS_ALIASES_SET', true ); diff --git a/WordPress/PHPCSHelper.php b/WordPress/PHPCSHelper.php index 9602e3c61d..6e24f4a704 100644 --- a/WordPress/PHPCSHelper.php +++ b/WordPress/PHPCSHelper.php @@ -9,7 +9,7 @@ namespace WordPressCS\WordPress; -use PHP_CodeSniffer_File as File; +use PHP_CodeSniffer\Files\File; /** * PHPCSHelper diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 96fa9978e4..4f63d8a002 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -9,9 +9,9 @@ namespace WordPressCS\WordPress; -use PHP_CodeSniffer_Sniff as PHPCS_Sniff; -use PHP_CodeSniffer_File as File; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Sniffs\Sniff as PHPCS_Sniff; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Util\Tokens; use WordPressCS\WordPress\PHPCSHelper; /** diff --git a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php index 59cd9a8613..d417fe0ea8 100644 --- a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\Arrays; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Enforces WordPress array spacing format. diff --git a/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php b/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php index 35aa361606..2285a7cc79 100644 --- a/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php @@ -11,7 +11,7 @@ use WordPressCS\WordPress\Sniff; use WordPressCS\WordPress\PHPCSHelper; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Enforces WordPress array indentation for multi-line arrays. diff --git a/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php b/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php index 648fc687cb..a1b6626b6a 100644 --- a/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php +++ b/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\Arrays; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Enforces a comma after each array item and the spacing around it. diff --git a/WordPress/Sniffs/Classes/ClassInstantiationSniff.php b/WordPress/Sniffs/Classes/ClassInstantiationSniff.php index ca6c078de8..37b942f6f0 100644 --- a/WordPress/Sniffs/Classes/ClassInstantiationSniff.php +++ b/WordPress/Sniffs/Classes/ClassInstantiationSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\Classes; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Verifies object instantiation statements. diff --git a/WordPress/Sniffs/CodeAnalysis/AssignmentInConditionSniff.php b/WordPress/Sniffs/CodeAnalysis/AssignmentInConditionSniff.php index cf61fa6d86..fa3d9db7f5 100644 --- a/WordPress/Sniffs/CodeAnalysis/AssignmentInConditionSniff.php +++ b/WordPress/Sniffs/CodeAnalysis/AssignmentInConditionSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\CodeAnalysis; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Detects variable assignments being made within conditions. diff --git a/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php b/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php index 927e89d714..2b92e1c7a1 100644 --- a/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php +++ b/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\CodeAnalysis; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Checks against empty statements. diff --git a/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php b/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php index fcc9467628..eecb3e757e 100644 --- a/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php +++ b/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\DB; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Flag Database direct queries. diff --git a/WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php b/WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php index baf5f254e5..405eb094d0 100644 --- a/WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php +++ b/WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\DB; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Check for incorrect use of the $wpdb->prepare method. diff --git a/WordPress/Sniffs/DB/PreparedSQLSniff.php b/WordPress/Sniffs/DB/PreparedSQLSniff.php index 6084f1aabd..1f8fa9b3bc 100644 --- a/WordPress/Sniffs/DB/PreparedSQLSniff.php +++ b/WordPress/Sniffs/DB/PreparedSQLSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\DB; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Sniff for prepared SQL. diff --git a/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php b/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php index 39759683d4..0aefd0a8ab 100644 --- a/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php +++ b/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\Functions; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Enforces no whitespace between the parenthesis of a function call without parameters. diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index f915c671ec..437bc26923 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -11,7 +11,7 @@ use WordPressCS\WordPress\AbstractFunctionParameterSniff; use WordPressCS\WordPress\PHPCSHelper; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Verify that everything defined in the global namespace is prefixed with a theme/plugin specific prefix. diff --git a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php index 7b3c456aec..3ee7c2ab31 100644 --- a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -9,8 +9,8 @@ namespace WordPressCS\WordPress\Sniffs\NamingConventions; -use PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff as PHPCS_PEAR_ValidFunctionNameSniff; -use PHP_CodeSniffer_File as File; +use PHP_CodeSniffer\Standards\PEAR\Sniffs\NamingConventions\ValidFunctionNameSniff as PHPCS_PEAR_ValidFunctionNameSniff; +use PHP_CodeSniffer\Files\File; /** * Enforces WordPress function name and method name format, based upon Squiz code. diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index 67881d8cb3..4e321c929e 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -9,9 +9,9 @@ namespace WordPressCS\WordPress\Sniffs\NamingConventions; -use PHP_CodeSniffer_Standards_AbstractVariableSniff as PHPCS_AbstractVariableSniff; -use PHP_CodeSniffer_File as File; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Sniffs\AbstractVariableSniff as PHPCS_AbstractVariableSniff; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Util\Tokens; use WordPressCS\WordPress\Sniff; /** diff --git a/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php b/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php index d80653ccaf..cc7b5fcb0c 100644 --- a/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php +++ b/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\PHP; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Discourage the use of the PHP error silencing operator. diff --git a/WordPress/Sniffs/PHP/TypeCastsSniff.php b/WordPress/Sniffs/PHP/TypeCastsSniff.php index 6c411bb9b9..343ddf1785 100644 --- a/WordPress/Sniffs/PHP/TypeCastsSniff.php +++ b/WordPress/Sniffs/PHP/TypeCastsSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\PHP; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Verifies the correct usage of type cast keywords. diff --git a/WordPress/Sniffs/PHP/YodaConditionsSniff.php b/WordPress/Sniffs/PHP/YodaConditionsSniff.php index 554c3446fa..bd6738f69c 100644 --- a/WordPress/Sniffs/PHP/YodaConditionsSniff.php +++ b/WordPress/Sniffs/PHP/YodaConditionsSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\PHP; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Enforces Yoda conditional statements. diff --git a/WordPress/Sniffs/Security/EscapeOutputSniff.php b/WordPress/Sniffs/Security/EscapeOutputSniff.php index 9f29183341..05d9cbb5b5 100644 --- a/WordPress/Sniffs/Security/EscapeOutputSniff.php +++ b/WordPress/Sniffs/Security/EscapeOutputSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\Security; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Verifies that all outputted strings are escaped. diff --git a/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php b/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php index 9f5663af18..e61ef17b14 100644 --- a/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php +++ b/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\Utils; use WordPressCS\WordPress\AbstractFunctionParameterSniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Comprehensive I18n text domain fixer tool. diff --git a/WordPress/Sniffs/WP/CapitalPDangitSniff.php b/WordPress/Sniffs/WP/CapitalPDangitSniff.php index d29d721bcf..c1b18f0ba9 100644 --- a/WordPress/Sniffs/WP/CapitalPDangitSniff.php +++ b/WordPress/Sniffs/WP/CapitalPDangitSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\WP; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Capital P Dangit! diff --git a/WordPress/Sniffs/WP/CronIntervalSniff.php b/WordPress/Sniffs/WP/CronIntervalSniff.php index 0d9121dccb..56965e89fb 100644 --- a/WordPress/Sniffs/WP/CronIntervalSniff.php +++ b/WordPress/Sniffs/WP/CronIntervalSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\WP; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Flag cron schedules less than 15 minutes. diff --git a/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php b/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php index 32ca928cc7..7bbecee22f 100644 --- a/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\WP; use WordPressCS\WordPress\AbstractFunctionParameterSniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Check for usage of deprecated parameter values in WP functions and provide alternative based on the parameter passed. diff --git a/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php b/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php index 7b6268a8b4..e55254b749 100644 --- a/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php +++ b/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\WP; use WordPressCS\WordPress\AbstractFunctionParameterSniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Warns against usage of discouraged WP CONSTANTS and recommends alternatives. diff --git a/WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php b/WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php index 93007651f9..0a0d0a6245 100644 --- a/WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php +++ b/WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\WP; use WordPressCS\WordPress\AbstractFunctionParameterSniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * This checks the enqueued 4th and 5th parameters to make sure the version and in_footer are set. diff --git a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php index 900a10ba7a..05c642156f 100644 --- a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php +++ b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\WP; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Makes sure scripts and styles are enqueued and not explicitly echo'd. diff --git a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php index 9aae552517..434fc1a8db 100644 --- a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php +++ b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\WP; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Warns about overwriting WordPress native global variables. diff --git a/WordPress/Sniffs/WP/I18nSniff.php b/WordPress/Sniffs/WP/I18nSniff.php index 0628a10b2f..c5dab418a9 100644 --- a/WordPress/Sniffs/WP/I18nSniff.php +++ b/WordPress/Sniffs/WP/I18nSniff.php @@ -11,7 +11,7 @@ use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; use WordPressCS\WordPress\PHPCSHelper; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Makes sure WP internationalization functions are used properly. diff --git a/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php index 2a139f5f5a..fedb947ddc 100644 --- a/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\WhiteSpace; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Check & fix whitespace on the inside of arbitrary parentheses. diff --git a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php index a71b7a7663..af87a7d634 100755 --- a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\WhiteSpace; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Ensure cast statements don't contain whitespace, but *are* surrounded by whitespace, based upon Squiz code. diff --git a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php index 0d46e52853..379424e171 100644 --- a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\WhiteSpace; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Enforces spacing around logical operators and assignments, based upon Squiz code. diff --git a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php index 3b6499e012..4dedca618a 100644 --- a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php @@ -9,8 +9,8 @@ namespace WordPressCS\WordPress\Sniffs\WhiteSpace; -use Squiz_Sniffs_WhiteSpace_OperatorSpacingSniff as PHPCS_Squiz_OperatorSpacingSniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\OperatorSpacingSniff as PHPCS_Squiz_OperatorSpacingSniff; +use PHP_CodeSniffer\Util\Tokens; /** * Verify operator spacing, uses the Squiz sniff, but additionally also sniffs for the `!` (boolean not) operator. diff --git a/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php index 5a9b6511a0..d4a4ce787f 100644 --- a/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php @@ -9,9 +9,9 @@ namespace WordPressCS\WordPress\Sniffs\WhiteSpace; -use Squiz_Sniffs_WhiteSpace_SemicolonSpacingSniff as PHPCS_Squiz_SemicolonSpacingSniff; -use PHP_CodeSniffer_File as File; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SemicolonSpacingSniff as PHPCS_Squiz_SemicolonSpacingSniff; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Util\Tokens; /** * Ensure there is no whitespace before a semicolon, while allowing for empty conditions in a `for`. From a71cd17f8c7e6553898ea1b64cea97a93df29afd Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 18:15:47 +0100 Subject: [PATCH 017/241] WPCS 2.0.0: Remove unit test work-arounds for PHPCS 2.x The duplicates of the PHPCS 2.x test controller files can now be removed. We also no longer need to load our `PHPCSAliases` file, not even for the autoloading of the abstract classes as PHPCS 3.1.0+handles this without problem. For PHPUnit 7.x support, PHPCS does need a bootstrap file, but that is included with PHPCS, so all we need to do is reference that file in the command send to PHPUnit. --- .gitattributes | 1 - .github/CONTRIBUTING.md | 25 +- .phpcs.xml.dist | 4 - .travis.yml | 2 +- Test/AllTests.php | 72 ---- Test/Standards/AbstractSniffUnitTest.php | 460 ----------------------- Test/Standards/AllSniffs.php | 157 -------- Test/bootstrap.php | 42 --- Test/phpcs2-bootstrap.php | 53 --- Test/phpcs3-bootstrap.php | 61 --- bin/pre-commit | 2 +- phpunit.xml.dist | 1 - 12 files changed, 11 insertions(+), 869 deletions(-) delete mode 100644 Test/AllTests.php delete mode 100644 Test/Standards/AbstractSniffUnitTest.php delete mode 100644 Test/Standards/AllSniffs.php delete mode 100644 Test/bootstrap.php delete mode 100644 Test/phpcs2-bootstrap.php delete mode 100644 Test/phpcs3-bootstrap.php diff --git a/.gitattributes b/.gitattributes index 5e6e2b7903..c12f94cfb3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9,7 +9,6 @@ /phpunit.xml.dist export-ignore /.github export-ignore /bin export-ignore -/Test export-ignore /WordPress/Tests export-ignore # diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 861f5a6c56..2693701a61 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -89,7 +89,7 @@ N.B.: If you installed WPCS using Composer, make sure you used `--prefer-source` If you already have PHPUnit installed on your system: Congrats, you're all set. If not, you can navigate to the directory where the `PHP_CodeSniffer` repo is checked out and do `composer install` to install the `dev` dependencies. -Alternatively, you can [install PHPUnit](https://phpunit.de/manual/5.7/en/installation.html) as a PHAR file. +Alternatively, you can [install PHPUnit](https://phpunit.readthedocs.io/en/7.4/installation.html) as a PHAR file. ## Before running the unit tests @@ -111,37 +111,30 @@ The easiest way to do this is to add a `phpunit.xml` file to the root of your WP ## Running the unit tests -The WordPress Coding Standards are compatible with both PHPCS 2.x as well as 3.x. This has some implications for running the unit tests. - * Make sure you have registered the directory in which you installed WPCS with PHPCS using; ```sh phpcs --config-set installed_paths path/to/WPCS ``` * Navigate to the directory in which you installed WPCS. -* To run the unit tests with PHPCS 3.x: - ```sh - phpunit --bootstrap="./Test/phpcs3-bootstrap.php" --filter WordPress /path/to/PHP_CodeSniffer/tests/AllTests.php - ``` -* To run the unit tests with PHPCS 2.x: +* To run the unit tests: ```sh - phpunit --bootstrap="./Test/phpcs2-bootstrap.php" --filter WordPress ./Test/AllTests.php + phpunit --filter WordPress --bootstrap="/path/to/PHP_CodeSniffer/tests/bootstrap.php" /path/to/PHP_CodeSniffer/tests/AllTests.php ``` Expected output: ``` -PHPUnit 6.5.8 by Sebastian Bergmann and contributors. +PHPUnit 7.5.0 by Sebastian Bergmann and contributors. -Runtime: PHP 7.2.7 with Xdebug 2.6.0 +Runtime: PHP 7.2.13 Configuration: /WordPressCS/phpunit.xml -................................................................. 65 / 77 ( 84%) -............ 77 / 77 (100%) +............................................................ 60 / 60 (100%) -Tests generated 576 unique error codes; 51 were fixable (8.85%) +156 sniff test files generated 490 unique error codes; 59 were fixable (12.04%) -Time: 22.93 seconds, Memory: 40.00MB +Time: 18.02 seconds, Memory: 22.00MB -OK (77 tests, 0 assertions) +OK (60 tests, 0 assertions) ``` [![asciicast](https://asciinema.org/a/98078.png)](https://asciinema.org/a/98078) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 4bb6850731..84af17ae8a 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -7,11 +7,7 @@ - - /Test/AllTests.php - /Test/Standards/*.php /bin/class-ruleset-test.php - */vendor/* diff --git a/.travis.yml b/.travis.yml index 18cc71e459..e22e12dc6c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -65,7 +65,7 @@ script: # Lint the PHP files against parse errors. - if [[ "$LINT" == "1" ]]; then if find . -path ./vendor -prune -o -path ./bin -prune -o -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi; fi # Run the unit tests. - - phpunit --filter WordPress $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php + - phpunit --filter WordPress --bootstrap="$(pwd)/vendor/squizlabs/php_codesniffer/tests/bootstrap.php" $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php # Test for fixer conflicts by running the auto-fixers of the complete WPCS over the test case files. # This is not an exhaustive test, but should give an early indication for typical fixer conflicts. # For the first run, the exit code will be 1 (= all fixable errors fixed). diff --git a/Test/AllTests.php b/Test/AllTests.php deleted file mode 100644 index de70f8ee19..0000000000 --- a/Test/AllTests.php +++ /dev/null @@ -1,72 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/* Start of WPCS adjustment */ -namespace WordPressCS\Test; - -use WordPressCS\Test\AllSniffs; -use PHP_CodeSniffer_AllTests; -use PHP_CodeSniffer_TestSuite; -/* End of WPCS adjustment */ - -/** - * A test class for running all PHP_CodeSniffer unit tests. - * - * Usage: phpunit AllTests.php - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class AllTests extends PHP_CodeSniffer_AllTests { - - /** - * Add all PHP_CodeSniffer test suites into a single test suite. - * - * @return PHPUnit_Framework_TestSuite - */ - public static function suite() - { - $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'] = array(); - - // Use a special PHP_CodeSniffer test suite so that we can - // unset our autoload function after the run. - $suite = new PHP_CodeSniffer_TestSuite('PHP CodeSniffer'); - - /* Start of WPCS adjustment */ - // We need to point to the WPCS version of the referenced class - // and we may as well bypass the loading of the PHPCS core unit tests - // while we're at it too. - $suite->addTest(AllSniffs::suite()); - /* End of WPCS adjustment */ - - // Unregister this here because the PEAR tester loads - // all package suites before running then, so our autoloader - // will cause problems for the packages included after us. - spl_autoload_unregister(array('PHP_CodeSniffer', 'autoload')); - - return $suite; - - }//end suite() - - -}//end class diff --git a/Test/Standards/AbstractSniffUnitTest.php b/Test/Standards/AbstractSniffUnitTest.php deleted file mode 100644 index b92b81386d..0000000000 --- a/Test/Standards/AbstractSniffUnitTest.php +++ /dev/null @@ -1,460 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/* Start of WPCS adjustment */ -namespace WordPressCS\Test; - -use PHP_CodeSniffer; -use PHP_CodeSniffer_File; -use PHP_CodeSniffer_Exception; -use PHPUnit_Framework_TestCase; -use DirectoryIterator; -/* End of WPCS adjustment */ - -/** - * An abstract class that all sniff unit tests must extend. - * - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings that are not found, or - * warnings and errors that are not expected, are considered test failures. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -abstract class AbstractSniffUnitTest extends PHPUnit_Framework_TestCase { - - /** - * Enable or disable the backup and restoration of the $GLOBALS array. - * Overwrite this attribute in a child class of TestCase. - * Setting this attribute in setUp() has no effect! - * - * @var boolean - */ - protected $backupGlobals = false; - - /** - * The PHP_CodeSniffer object used for testing. - * - * @var PHP_CodeSniffer - */ - protected static $phpcs = null; - - /** - * The path to the directory under which the sniff's standard lives. - * - * @var string - */ - public $standardsDir = null; - - - /** - * Sets up this unit test. - * - * @return void - */ - protected function setUp() - { - if (self::$phpcs === null) { - self::$phpcs = new PHP_CodeSniffer(); - } - - $class = \get_class($this); - $this->standardsDir = $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'][$class]; - - }//end setUp() - - - /** - * Get a list of all test files to check. - * - * These will have the same base as the sniff name but different extensions. - * We ignore the .php file as it is the class. - * - * @param string $testFileBase The base path that the unit tests files will have. - * - * @return string[] - */ - protected function getTestFiles($testFileBase) - { - $testFiles = array(); - - $dir = substr($testFileBase, 0, strrpos($testFileBase, \DIRECTORY_SEPARATOR)); - $di = new DirectoryIterator($dir); - - foreach ($di as $file) { - $path = $file->getPathname(); - if (substr($path, 0, \strlen($testFileBase)) === $testFileBase) { - - /* Start of WPCS adjustment */ - // If we're changing things anyway, we may as well exclude backup files - // from the test runs ;-) - if ($path !== $testFileBase.'php' && substr($path, -5) !== 'fixed' - && substr($path, -3) !== 'bak' && substr($path, -4) !== 'orig' - ) { - $testFiles[] = $path; - } - /* End of WPCS adjustment */ - } - } - - // Put them in order. - sort($testFiles); - - return $testFiles; - - }//end getTestFiles() - - - /** - * Should this test be skipped for some reason. - * - * @return void - */ - protected function shouldSkipTest() - { - return false; - - }//end shouldSkipTest() - - - /** - * Tests the extending classes Sniff class. - * - * @return void - * @throws PHPUnit_Framework_Error - */ - public final function testSniff() - { - // Skip this test if we can't run in this environment. - if ($this->shouldSkipTest() === true) { - $this->markTestSkipped(); - } - - // The basis for determining file locations. - $basename = substr(\get_class($this), 0, -8); - - /* Start of WPCS adjustment */ - // Support the use of PHP namespaces. - if (strpos($basename, '\\') !== false) { - $basename = str_replace('\\', '_', $basename); - } - /* End of WPCS adjustment */ - - // The name of the coding standard we are testing. - $standardName = substr($basename, 0, strpos($basename, '_')); - - // The code of the sniff we are testing. - $parts = explode('_', $basename); - $sniffCode = $parts[0].'.'.$parts[2].'.'.$parts[3]; - - $testFileBase = $this->standardsDir.\DIRECTORY_SEPARATOR.str_replace('_', \DIRECTORY_SEPARATOR, $basename).'UnitTest.'; - - // Get a list of all test files to check. - $testFiles = $this->getTestFiles($testFileBase); - - self::$phpcs->initStandard($standardName, array($sniffCode)); - self::$phpcs->setIgnorePatterns(array()); - - $failureMessages = array(); - foreach ($testFiles as $testFile) { - $filename = basename($testFile); - - try { - $cliValues = $this->getCliValues($filename); - self::$phpcs->cli->setCommandLineValues($cliValues); - $phpcsFile = self::$phpcs->processFile($testFile); - } catch (\Exception $e) { - $this->fail('An unexpected exception has been caught: '.$e->getMessage()); - } - - $failures = $this->generateFailureMessages($phpcsFile); - $failureMessages = array_merge($failureMessages, $failures); - - if ($phpcsFile->getFixableCount() > 0) { - // Attempt to fix the errors. - $phpcsFile->fixer->fixFile(); - $fixable = $phpcsFile->getFixableCount(); - if ($fixable > 0) { - $failureMessages[] = "Failed to fix $fixable fixable violations in $filename"; - } - - // Check for a .fixed file to check for accuracy of fixes. - $fixedFile = $testFile.'.fixed'; - if (file_exists($fixedFile) === true) { - $diff = $phpcsFile->fixer->generateDiff($fixedFile); - if (trim($diff) !== '') { - $filename = basename($testFile); - $fixedFilename = basename($fixedFile); - $failureMessages[] = "Fixed version of $filename does not match expected version in $fixedFilename; the diff is\n$diff"; - } - } - } - }//end foreach - - if (empty($failureMessages) === false) { - $this->fail(implode(\PHP_EOL, $failureMessages)); - } - - }//end runTest() - - - /** - * Generate a list of test failures for a given sniffed file. - * - * @param PHP_CodeSniffer_File $file The file being tested. - * - * @return array - * @throws PHP_CodeSniffer_Exception - */ - public function generateFailureMessages(PHP_CodeSniffer_File $file) - { - $testFile = $file->getFilename(); - - $foundErrors = $file->getErrors(); - $foundWarnings = $file->getWarnings(); - $expectedErrors = $this->getErrorList(basename($testFile)); - $expectedWarnings = $this->getWarningList(basename($testFile)); - - if (\is_array($expectedErrors) === false) { - throw new PHP_CodeSniffer_Exception('getErrorList() must return an array'); - } - - if (\is_array($expectedWarnings) === false) { - throw new PHP_CodeSniffer_Exception('getWarningList() must return an array'); - } - - /* - We merge errors and warnings together to make it easier - to iterate over them and produce the errors string. In this way, - we can report on errors and warnings in the same line even though - it's not really structured to allow that. - */ - - $allProblems = array(); - $failureMessages = array(); - - foreach ($foundErrors as $line => $lineErrors) { - foreach ($lineErrors as $column => $errors) { - if (isset($allProblems[$line]) === false) { - $allProblems[$line] = array( - 'expected_errors' => 0, - 'expected_warnings' => 0, - 'found_errors' => array(), - 'found_warnings' => array(), - ); - } - - $foundErrorsTemp = array(); - foreach ($allProblems[$line]['found_errors'] as $foundError) { - $foundErrorsTemp[] = $foundError; - } - - $errorsTemp = array(); - foreach ($errors as $foundError) { - $errorsTemp[] = $foundError['message'].' ('.$foundError['source'].')'; - - $source = $foundError['source']; - if (\in_array($source, $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES']) === false) { - $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'][] = $source; - } - - if ($foundError['fixable'] === true - && \in_array($source, $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES']) === false - ) { - $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'][] = $source; - } - } - - $allProblems[$line]['found_errors'] = array_merge($foundErrorsTemp, $errorsTemp); - }//end foreach - - if (isset($expectedErrors[$line]) === true) { - $allProblems[$line]['expected_errors'] = $expectedErrors[$line]; - } else { - $allProblems[$line]['expected_errors'] = 0; - } - - unset($expectedErrors[$line]); - }//end foreach - - foreach ($expectedErrors as $line => $numErrors) { - if (isset($allProblems[$line]) === false) { - $allProblems[$line] = array( - 'expected_errors' => 0, - 'expected_warnings' => 0, - 'found_errors' => array(), - 'found_warnings' => array(), - ); - } - - $allProblems[$line]['expected_errors'] = $numErrors; - } - - foreach ($foundWarnings as $line => $lineWarnings) { - foreach ($lineWarnings as $column => $warnings) { - if (isset($allProblems[$line]) === false) { - $allProblems[$line] = array( - 'expected_errors' => 0, - 'expected_warnings' => 0, - 'found_errors' => array(), - 'found_warnings' => array(), - ); - } - - $foundWarningsTemp = array(); - foreach ($allProblems[$line]['found_warnings'] as $foundWarning) { - $foundWarningsTemp[] = $foundWarning; - } - - $warningsTemp = array(); - foreach ($warnings as $warning) { - $warningsTemp[] = $warning['message'].' ('.$warning['source'].')'; - } - - $allProblems[$line]['found_warnings'] = array_merge($foundWarningsTemp, $warningsTemp); - }//end foreach - - if (isset($expectedWarnings[$line]) === true) { - $allProblems[$line]['expected_warnings'] = $expectedWarnings[$line]; - } else { - $allProblems[$line]['expected_warnings'] = 0; - } - - unset($expectedWarnings[$line]); - }//end foreach - - foreach ($expectedWarnings as $line => $numWarnings) { - if (isset($allProblems[$line]) === false) { - $allProblems[$line] = array( - 'expected_errors' => 0, - 'expected_warnings' => 0, - 'found_errors' => array(), - 'found_warnings' => array(), - ); - } - - $allProblems[$line]['expected_warnings'] = $numWarnings; - } - - // Order the messages by line number. - ksort($allProblems); - - foreach ($allProblems as $line => $problems) { - $numErrors = \count($problems['found_errors']); - $numWarnings = \count($problems['found_warnings']); - $expectedErrors = $problems['expected_errors']; - $expectedWarnings = $problems['expected_warnings']; - - $errors = ''; - $foundString = ''; - - if ($expectedErrors !== $numErrors || $expectedWarnings !== $numWarnings) { - $lineMessage = "[LINE $line]"; - $expectedMessage = 'Expected '; - $foundMessage = 'in '.basename($testFile).' but found '; - - if ($expectedErrors !== $numErrors) { - $expectedMessage .= "$expectedErrors error(s)"; - $foundMessage .= "$numErrors error(s)"; - if ($numErrors !== 0) { - $foundString .= 'error(s)'; - $errors .= implode(\PHP_EOL.' -> ', $problems['found_errors']); - } - - if ($expectedWarnings !== $numWarnings) { - $expectedMessage .= ' and '; - $foundMessage .= ' and '; - if ($numWarnings !== 0) { - if ($foundString !== '') { - $foundString .= ' and '; - } - } - } - } - - if ($expectedWarnings !== $numWarnings) { - $expectedMessage .= "$expectedWarnings warning(s)"; - $foundMessage .= "$numWarnings warning(s)"; - if ($numWarnings !== 0) { - $foundString .= 'warning(s)'; - if (empty($errors) === false) { - $errors .= \PHP_EOL.' -> '; - } - - $errors .= implode(\PHP_EOL.' -> ', $problems['found_warnings']); - } - } - - $fullMessage = "$lineMessage $expectedMessage $foundMessage."; - if ($errors !== '') { - $fullMessage .= " The $foundString found were:".\PHP_EOL." -> $errors"; - } - - $failureMessages[] = $fullMessage; - }//end if - }//end foreach - - return $failureMessages; - - }//end generateFailureMessages() - - - /** - * Get a list of CLI values to set before the file is tested. - * - * @param string $filename The name of the file being tested. - * - * @return array - */ - public function getCliValues($filename) - { - return array(); - - }//end getCliValues() - - - /** - * Returns the lines where errors should occur. - * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) - */ - protected abstract function getErrorList(); - - - /** - * Returns the lines where warnings should occur. - * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) - */ - protected abstract function getWarningList(); - - -}//end class diff --git a/Test/Standards/AllSniffs.php b/Test/Standards/AllSniffs.php deleted file mode 100644 index c3768adfca..0000000000 --- a/Test/Standards/AllSniffs.php +++ /dev/null @@ -1,157 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/* Start of WPCS adjustment */ -namespace WordPressCS\Test; - -use PHP_CodeSniffer_Standards_AllSniffs; -use PHP_CodeSniffer; -use PHPUnit_Framework_TestSuite; -use RecursiveIteratorIterator; -use RecursiveDirectoryIterator; -/* End of WPCS adjustment */ - -/** - * A test class for testing all sniffs for installed standards. - * - * Usage: phpunit AllSniffs.php - * - * This test class loads all unit tests for all installed standards into a - * single test suite and runs them. Errors are reported on the command line. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class AllSniffs extends PHP_CodeSniffer_Standards_AllSniffs -{ - - /** - * Add all sniff unit tests into a test suite. - * - * Sniff unit tests are found by recursing through the 'Tests' directory - * of each installed coding standard. - * - * @return PHPUnit_Framework_TestSuite - */ - public static function suite() - { - $suite = new PHPUnit_Framework_TestSuite('PHP CodeSniffer Standards'); - - /* Start of WPCS adjustment */ - // Set the correct path to PHPCS. - $isInstalled = !is_file(\PHPCS_DIR.'/CodeSniffer.php'); - /* End of WPCS adjustment */ - - // Optionally allow for ignoring the tests for one or more standards. - $ignoreTestsForStandards = getenv('PHPCS_IGNORE_TESTS'); - if ($ignoreTestsForStandards === false) { - $ignoreTestsForStandards = array(); - } else { - $ignoreTestsForStandards = explode(',', $ignoreTestsForStandards); - } - - $installedPaths = PHP_CodeSniffer::getInstalledStandardPaths(); - foreach ($installedPaths as $path) { - $path = realpath($path); - $origPath = $path; - $standards = PHP_CodeSniffer::getInstalledStandards(true, $path); - - // If the test is running PEAR installed, the built-in standards - // are split into different directories; one for the sniffs and - // a different file system location for tests. - if ($isInstalled === true - && is_dir($path.\DIRECTORY_SEPARATOR.'Generic') === true - ) { - $path = dirname(__FILE__); - } - - foreach ($standards as $standard) { - if (\in_array($standard, $ignoreTestsForStandards, true)) { - continue; - } - - $testsDir = $path.\DIRECTORY_SEPARATOR.$standard.\DIRECTORY_SEPARATOR.'Tests'.\DIRECTORY_SEPARATOR; - - if (is_dir($testsDir) === false) { - // No tests for this standard. - continue; - } - - $di = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($testsDir)); - - foreach ($di as $file) { - // Skip hidden files. - if (substr($file->getFilename(), 0, 1) === '.') { - continue; - } - - // Tests must have the extension 'php'. - $parts = explode('.', $file); - $ext = array_pop($parts); - if ($ext !== 'php') { - continue; - } - - $filePath = $file->getPathname(); - $className = str_replace($path.\DIRECTORY_SEPARATOR, '', $filePath); - $className = substr($className, 0, -4); - $className = str_replace(\DIRECTORY_SEPARATOR, '_', $className); - - // Include the sniff here so tests can use it in their setup() methods. - $parts = explode('_', $className); - if (isset($parts[0],$parts[2],$parts[3]) === true) { - $sniffPath = $origPath.\DIRECTORY_SEPARATOR.$parts[0].\DIRECTORY_SEPARATOR.'Sniffs'.\DIRECTORY_SEPARATOR.$parts[2].\DIRECTORY_SEPARATOR.$parts[3]; - $sniffPath = substr($sniffPath, 0, -8).'Sniff.php'; - - if (file_exists($sniffPath) === true) { - include_once $sniffPath; - include_once $filePath; - - /* Start of WPCS adjustment */ - // Support the use of PHP namespaces. If the class name we included - // contains namespace separators instead of underscores, use this as the - // class name from now on. - $classNameNS = str_replace('_', '\\', $className); - if (class_exists($classNameNS, false) === true) { - $className = $classNameNS; - } - /* End of WPCS adjustment */ - - $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'][$className] = $path; - $suite->addTestSuite($className); - } else { - self::$orphanedTests[] = $filePath; - } - } else { - self::$orphanedTests[] = $filePath; - } - }//end foreach - }//end foreach - }//end foreach - - return $suite; - - }//end suite() - - -}//end class diff --git a/Test/bootstrap.php b/Test/bootstrap.php deleted file mode 100644 index 996c887ce3..0000000000 --- a/Test/bootstrap.php +++ /dev/null @@ -1,42 +0,0 @@ - From b79eb6428d65cb637f241317b42b0fb9f526a13f Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 05:02:42 +0100 Subject: [PATCH 018/241] WPCS 2.0.0: Remove work-arounds for PHP < 5.4 and PHPCS < 3.3.1 --- .../Sniffs/Security/EscapeOutputSniff.php | 30 ------- .../ArbitraryParenthesesSpacingSniff.php | 5 -- .../Tests/Arrays/ArrayIndentationUnitTest.php | 20 ----- .../MultipleStatementAlignmentUnitTest.php | 20 ----- .../CodeAnalysis/EmptyStatementUnitTest.php | 2 +- WordPress/Tests/Files/FileNameUnitTest.php | 30 +------ .../Utils/I18nTextDomainFixerUnitTest.php | 20 ----- WordPress/Tests/WP/I18nUnitTest.php | 21 ----- .../ControlStructureSpacingUnitTest.php | 28 ------- .../WhiteSpace/DisallowInlineTabsUnitTest.php | 15 ---- .../WhiteSpace/PrecisionAlignmentUnitTest.php | 82 +++---------------- 11 files changed, 14 insertions(+), 259 deletions(-) diff --git a/WordPress/Sniffs/Security/EscapeOutputSniff.php b/WordPress/Sniffs/Security/EscapeOutputSniff.php index 9de62c0e4c..2458ddcef0 100644 --- a/WordPress/Sniffs/Security/EscapeOutputSniff.php +++ b/WordPress/Sniffs/Security/EscapeOutputSniff.php @@ -177,18 +177,6 @@ public function register() { \T_OPEN_TAG_WITH_ECHO, ); - /* - * Check whether short open echo tags are disabled and if so, register the - * T_INLINE_HTML token which is how short open tags are being handled in that case. - * - * In PHP < 5.4, support for short open echo tags depended on whether the - * `short_open_tag` ini directive was set to `true`. - * For PHP >= 5.4, the `short_open_tag` no longer affects the short open - * echo tags and these are now always enabled. - */ - if ( \PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) { - $tokens[] = \T_INLINE_HTML; - } return $tokens; } @@ -226,24 +214,6 @@ public function process_token( $stackPtr ) { $end_of_statement = ( $first_param['end'] + 1 ); unset( $first_param ); } - } elseif ( \T_INLINE_HTML === $this->tokens[ $stackPtr ]['code'] ) { - // Skip if no PHP short_open_tag is found in the string. - if ( false === strpos( $this->tokens[ $stackPtr ]['content'], '\S+|\[[^\]]+\]))*)[\s]*;?[\s]*\?\>`', $this->tokens[ $stackPtr ]['content'], $matches ) > 0 ) { - $this->phpcsFile->addError( - "All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '%s'.", - $stackPtr, - 'OutputNotEscapedShortEcho', - array( $matches[1] ) - ); - return; - } - - return; } // Checking for the ignore comment, ex: //xss ok. diff --git a/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php index fedb947ddc..89c58ba60c 100644 --- a/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php @@ -77,11 +77,6 @@ public function register() { $this->ignoreTokens[ \T_LIST ] = \T_LIST; $this->ignoreTokens[ \T_DECLARE ] = \T_DECLARE; - // The below two tokens have been added to the Tokens::$functionNameTokens array in PHPCS 3.1.0, - // so they can be removed once the minimum PHPCS requirement of WPCS has gone up. - $this->ignoreTokens[ \T_SELF ] = \T_SELF; - $this->ignoreTokens[ \T_STATIC ] = \T_STATIC; - // Language constructs where the use of parentheses should be discouraged instead. $this->ignoreTokens[ \T_THROW ] = \T_THROW; $this->ignoreTokens[ \T_YIELD ] = \T_YIELD; diff --git a/WordPress/Tests/Arrays/ArrayIndentationUnitTest.php b/WordPress/Tests/Arrays/ArrayIndentationUnitTest.php index 91cbb4ce78..3b6983ff21 100644 --- a/WordPress/Tests/Arrays/ArrayIndentationUnitTest.php +++ b/WordPress/Tests/Arrays/ArrayIndentationUnitTest.php @@ -28,29 +28,9 @@ class ArrayIndentationUnitTest extends AbstractSniffUnitTest { */ private $tab_width = 4; - /** - * Get a list of CLI values to set before the file is tested. - * - * Used by PHPCS 2.x. - * - * @param string $testFile The name of the file being tested. - * - * @return array - */ - public function getCliValues( $testFile ) { - // Tab width setting is only needed for the tabbed file. - if ( 'ArrayIndentationUnitTest.1.inc' === $testFile ) { - return array( '--tab-width=' . $this->tab_width ); - } - - return array(); - } - /** * Set CLI values before the file is tested. * - * Used by PHPCS 3.x. - * * @param string $testFile The name of the file being tested. * @param \PHP_CodeSniffer\Config $config The config data for the test run. * diff --git a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.php b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.php index 58a0c04db7..bc6cc60268 100644 --- a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.php +++ b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.php @@ -31,29 +31,9 @@ class MultipleStatementAlignmentUnitTest extends AbstractSniffUnitTest { */ private $tab_width = 4; - /** - * Get a list of CLI values to set before the file is tested. - * - * Used by PHPCS 2.x. - * - * @param string $testFile The name of the file being tested. - * - * @return array - */ - public function getCliValues( $testFile ) { - // Tab width setting is only needed for the tabbed file. - if ( 'MultipleStatementAlignmentUnitTest.1.inc' === $testFile ) { - return array( '--tab-width=' . $this->tab_width ); - } - - return array(); - } - /** * Set CLI values before the file is tested. * - * Used by PHPCS 3.x. - * * @param string $testFile The name of the file being tested. * @param \PHP_CodeSniffer\Config $config The config data for the test run. * diff --git a/WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php b/WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php index 31e7bb55d4..22ca38d56c 100644 --- a/WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php +++ b/WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php @@ -56,7 +56,7 @@ public function getWarningList( $testFile = '' ) { case 'EmptyStatementUnitTest.2.inc': return array( 1 => 1, // Internal.NoCode warning when short open tags is off, otherwise EmptyStatement warning. - 2 => ( \PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) ? 0 : 1, + 2 => 1, ); default: diff --git a/WordPress/Tests/Files/FileNameUnitTest.php b/WordPress/Tests/Files/FileNameUnitTest.php index 363c0fa353..af0a46c2f2 100644 --- a/WordPress/Tests/Files/FileNameUnitTest.php +++ b/WordPress/Tests/Files/FileNameUnitTest.php @@ -119,18 +119,6 @@ class FileNameUnitTest extends AbstractSniffUnitTest { */ protected function getTestFiles( $testFileBase ) { - // Work around for PHP 5.3/PHPCS 2.x. - if ( \PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) { - unset( $this->expected_results['SomeView.inc'] ); - } - - // Work around for PHPCS < 3.2.0. The disables will be diregarded. - if ( ! \defined( '\T_PHPCS_DISABLE' ) && ! \defined( '\T_PHPCS_ENABLE' ) ) { - $this->expected_results['blanket-disable.inc'] = 1; - $this->expected_results['rule-disable.inc'] = 1; - $this->expected_results['wordpress-disable.inc'] = 1; - } - $sep = \DIRECTORY_SEPARATOR; $test_files = glob( dirname( $testFileBase ) . $sep . 'FileNameUnitTests{' . $sep . ',' . $sep . '*' . $sep . '}*.inc', \GLOB_BRACE ); @@ -161,24 +149,10 @@ public function getErrorList( $testFile = '' ) { /** * Returns the lines where warnings should occur. * - * @param string $testFile The name of the file being tested. - * * @return array => */ - public function getWarningList( $testFile = '' ) { - switch ( $testFile ) { - case 'SomeView.inc': - case 'some-view.inc': - $expected = array(); - if ( \PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) { - $expected[1] = 1; // Internal.NoCode warning on PHP 5.3 icw short open tags off. - } - - return $expected; - - default: - return array(); - } + public function getWarningList() { + return array(); } } diff --git a/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php b/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php index 90e3df8ddd..7f13fe3e88 100644 --- a/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php +++ b/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php @@ -27,29 +27,9 @@ class I18nTextDomainFixerUnitTest extends AbstractSniffUnitTest { */ private $tab_width = 4; - /** - * Get a list of CLI values to set before the file is tested. - * - * Used by PHPCS 2.x. - * - * @param string $testFile The name of the file being tested. - * - * @return array - */ - public function getCliValues( $testFile ) { - // Tab width setting is only needed for the file with the function calls. - if ( 'I18nTextDomainFixerUnitTest.4.inc' === $testFile ) { - return array( '--tab-width=' . $this->tab_width ); - } - - return array(); - } - /** * Set CLI values before the file is tested. * - * Used by PHPCS 3.x. - * * @param string $testFile The name of the file being tested. * @param \PHP_CodeSniffer\Config $config The config data for the test run. * diff --git a/WordPress/Tests/WP/I18nUnitTest.php b/WordPress/Tests/WP/I18nUnitTest.php index 6f617b03cc..bab594676f 100644 --- a/WordPress/Tests/WP/I18nUnitTest.php +++ b/WordPress/Tests/WP/I18nUnitTest.php @@ -10,7 +10,6 @@ namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -use WordPressCS\WordPress\PHPCSHelper; /** * Unit test class for the I18n sniff. @@ -22,29 +21,9 @@ */ class I18nUnitTest extends AbstractSniffUnitTest { - /** - * Get a list of CLI values to set before the file is tested. - * - * Used by PHPCS 2.x. - * - * @param string $testFile The name of the file being tested. - * - * @return array - */ - public function getCliValues( $testFile ) { - // Test overruling the text domain from the command line for one test file. - if ( 'I18nUnitTest.3.inc' === $testFile ) { - PHPCSHelper::set_config_data( 'text_domain', 'something', true ); - } - - return array(); - } - /** * Set CLI values before the file is tested. * - * Used by PHPCS 3.x. - * * @param string $testFile The name of the file being tested. * @param \PHP_CodeSniffer\Config $config The config data for the test run. * diff --git a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php index 93e58a47c1..e295978e2b 100644 --- a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php +++ b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php @@ -10,7 +10,6 @@ namespace WordPressCS\WordPress\Tests\WhiteSpace; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -use WordPressCS\WordPress\PHPCSHelper; /** * Unit test class for the ControlStructureSpacing sniff. @@ -22,33 +21,6 @@ */ class ControlStructureSpacingUnitTest extends AbstractSniffUnitTest { - /** - * Get a list of all test files to check. - * - * @param string $testFileBase The base path that the unit tests files will have. - * - * @return string[] - */ - protected function getTestFiles( $testFileBase ) { - - $testFiles = parent::getTestFiles( $testFileBase ); - - /* - * Testing whether the PHPCS annotations are properly handled is only useful on - * PHPCS versions which support the PHPCS annotations. - * Prior to PHPCS 3.2.0 they would be treated the same as ordinary comments - * for the purposes of this sniff. - */ - if ( version_compare( PHPCSHelper::get_version(), '3.2.0', '<' ) === true ) { - $key = array_search( $testFileBase . '2.inc', $testFiles, true ); - if ( false !== $key ) { - unset( $testFiles[ $key ] ); - } - } - - return $testFiles; - } - /** * Returns the lines where errors should occur. * diff --git a/WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php b/WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php index 13ee511a2d..5f360ca429 100644 --- a/WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php +++ b/WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php @@ -28,24 +28,9 @@ class DisallowInlineTabsUnitTest extends AbstractSniffUnitTest { */ private $tab_width = 4; - /** - * Get a list of CLI values to set before the file is tested. - * - * Used by PHPCS 2.x. - * - * @param string $testFile The name of the file being tested. - * - * @return array - */ - public function getCliValues( $testFile ) { - return array( '--tab-width=' . $this->tab_width ); - } - /** * Set CLI values before the file is tested. * - * Used by PHPCS 3.x. - * * @param string $testFile The name of the file being tested. * @param \PHP_CodeSniffer\Config $config The config data for the test run. * diff --git a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php index e62352c2fa..7b600c1729 100644 --- a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php +++ b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php @@ -10,7 +10,6 @@ namespace WordPressCS\WordPress\Tests\WhiteSpace; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -use WordPressCS\WordPress\PHPCSHelper; /** * Unit test class for the PrecisionAlignment sniff. @@ -28,24 +27,9 @@ class PrecisionAlignmentUnitTest extends AbstractSniffUnitTest { */ private $tab_width = 4; - /** - * Get a list of CLI values to set before the file is tested. - * - * Used by PHPCS 2.x. - * - * @param string $testFile The name of the file being tested. - * - * @return array - */ - public function getCliValues( $testFile ) { - return array( '--tab-width=' . $this->tab_width ); - } - /** * Set CLI values before the file is tested. * - * Used by PHPCS 3.x. - * * @param string $testFile The name of the file being tested. * @param \PHP_CodeSniffer\Config $config The config data for the test run. * @@ -54,37 +38,12 @@ public function getCliValues( $testFile ) { public function setCliValues( $testFile, $config ) { $config->tabWidth = $this->tab_width; - // Setting "--ignore-annotations" is only possible since PHPCS 3.0. + // Testing a file with "--ignore-annotations". if ( 'PrecisionAlignmentUnitTest.6.inc' === $testFile ) { $config->annotations = false; } } - /** - * Get a list of all test files to check. - * - * @param string $testFileBase The base path that the unit tests files will have. - * - * @return string[] - */ - protected function getTestFiles( $testFileBase ) { - - $testFiles = parent::getTestFiles( $testFileBase ); - - /* - * Testing whether the PHPCS annotations are properly respected is only useful on - * PHPCS versions which support the PHPCS annotations. - */ - if ( version_compare( PHPCSHelper::get_version(), '3.2.0', '<' ) === true ) { - $key = array_search( $testFileBase . '5.inc', $testFiles, true ); - if ( false !== $key ) { - unset( $testFiles[ $key ] ); - } - } - - return $testFiles; - } - /** * Returns the lines where errors should occur. * @@ -116,11 +75,11 @@ public function getWarningList( $testFile = '' ) { case 'PrecisionAlignmentUnitTest.4.inc': return array( - 1 => 1, // Will show a `Internal.NoCodeFound` warning in PHP 5.3 with short open tags off. - 2 => ( \PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) ? 0 : 1, - 3 => ( \PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) ? 0 : 1, - 4 => ( \PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) ? 0 : 1, - 5 => ( \PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) ? 0 : 1, + 1 => 1, + 2 => 1, + 3 => 1, + 4 => 1, + 5 => 1, ); case 'PrecisionAlignmentUnitTest.5.inc': @@ -128,38 +87,19 @@ public function getWarningList( $testFile = '' ) { 9 => 1, 14 => 1, 19 => 1, - 24 => 0, - 29 => 0, + 24 => 1, + 29 => 1, 34 => 1, 39 => 1, 44 => 1, - 54 => 0, - 56 => 0, - 58 => 0, + 54 => 1, + 56 => 1, + 58 => 1, ); - /* - * The PHPCS 3.2.x versions contained a bug in the selective disable/enable logic - * compared to the intended behaviour as documented, which prevented the particular - * messages being tested on these lines from being thrown. See upstream issue #1986. - */ - if ( version_compare( PHPCSHelper::get_version(), '3.3.0', '>=' ) === true ) { - $warnings[24] = 1; - $warnings[29] = 1; - $warnings[54] = 1; - $warnings[56] = 1; - $warnings[58] = 1; - } - return $warnings; case 'PrecisionAlignmentUnitTest.6.inc': - /* - * {@internal Always returns 1 warning, as for PHPCS < 3.2.0, the PHPCS annotation - * will be seen as a "normal" comment with precision alignment. - * For PHPCS 3.2.0+, it will be seen as a PHPCS annotation, but annotations are ignored - * for this test file, so the precision alignment will be reported.}} - */ return array( 4 => 1, ); From 0a080dd9951a9488c36d3bae2fdd6c6bd888d600 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 17:31:21 +0100 Subject: [PATCH 019/241] WPCS 2.0.0: Remove PHPCS 2.x code from PHPCSHelper class While strictly speaking the `PHPCSHelper` class is no longer needed at this moment, PHPCS 4.x may again contain breaking changes, so leaving it in place as a cross-version compatibility layer makes sense. All the same, the PHPCS 2.x specific code can now be removed. --- WordPress/PHPCSHelper.php | 55 ++++++++------------------------------- 1 file changed, 11 insertions(+), 44 deletions(-) diff --git a/WordPress/PHPCSHelper.php b/WordPress/PHPCSHelper.php index 6e24f4a704..bdabb35bf1 100644 --- a/WordPress/PHPCSHelper.php +++ b/WordPress/PHPCSHelper.php @@ -33,13 +33,7 @@ class PHPCSHelper { * @return string */ public static function get_version() { - if ( \defined( '\PHP_CodeSniffer\Config::VERSION' ) ) { - // PHPCS 3.x. - return \PHP_CodeSniffer\Config::VERSION; - } else { - // PHPCS 2.x. - return \PHP_CodeSniffer::VERSION; - } + return \PHP_CodeSniffer\Config::VERSION; } /** @@ -56,13 +50,7 @@ public static function get_version() { * This will not write the config data to the config file. */ public static function set_config_data( $key, $value, $temp = false ) { - if ( method_exists( '\PHP_CodeSniffer\Config', 'setConfigData' ) ) { - // PHPCS 3.x. - \PHP_CodeSniffer\Config::setConfigData( $key, $value, $temp ); - } else { - // PHPCS 2.x. - \PHP_CodeSniffer::setConfigData( $key, $value, $temp ); - } + \PHP_CodeSniffer\Config::setConfigData( $key, $value, $temp ); } /** @@ -75,13 +63,7 @@ public static function set_config_data( $key, $value, $temp = false ) { * @return string|null */ public static function get_config_data( $key ) { - if ( method_exists( '\PHP_CodeSniffer\Config', 'getConfigData' ) ) { - // PHPCS 3.x. - return \PHP_CodeSniffer\Config::getConfigData( $key ); - } else { - // PHPCS 2.x. - return \PHP_CodeSniffer::getConfigData( $key ); - } + return \PHP_CodeSniffer\Config::getConfigData( $key ); } /** @@ -96,17 +78,8 @@ public static function get_config_data( $key ) { public static function get_tab_width( File $phpcsFile ) { $tab_width = 4; - if ( class_exists( '\PHP_CodeSniffer\Config' ) ) { - // PHPCS 3.x. - if ( isset( $phpcsFile->config->tabWidth ) && $phpcsFile->config->tabWidth > 0 ) { - $tab_width = $phpcsFile->config->tabWidth; - } - } else { - // PHPCS 2.x. - $cli_values = $phpcsFile->phpcs->cli->getCommandLineValues(); - if ( isset( $cli_values['tabWidth'] ) && $cli_values['tabWidth'] > 0 ) { - $tab_width = $cli_values['tabWidth']; - } + if ( isset( $phpcsFile->config->tabWidth ) && $phpcsFile->config->tabWidth > 0 ) { + $tab_width = $phpcsFile->config->tabWidth; } return $tab_width; @@ -122,20 +95,14 @@ public static function get_tab_width( File $phpcsFile ) { * @return bool True if annotations should be ignored, false otherwise. */ public static function ignore_annotations( File $phpcsFile = null ) { - if ( class_exists( '\PHP_CodeSniffer\Config' ) ) { - // PHPCS 3.x. - if ( isset( $phpcsFile, $phpcsFile->config->annotations ) ) { - return ! $phpcsFile->config->annotations; - } else { - $annotations = \PHP_CodeSniffer\Config::getConfigData( 'annotations' ); - if ( isset( $annotations ) ) { - return ! $annotations; - } + if ( isset( $phpcsFile, $phpcsFile->config->annotations ) ) { + return ! $phpcsFile->config->annotations; + } else { + $annotations = \PHP_CodeSniffer\Config::getConfigData( 'annotations' ); + if ( isset( $annotations ) ) { + return ! $annotations; } } - - // PHPCS 2.x does not support `--ignore-annotations`. - return false; } } From d22aca8fb0fb361c14477ae961ce29e7915fbc53 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 22 Aug 2018 02:54:45 +0200 Subject: [PATCH 020/241] ValidFunctionName: Add additional unit test for interfaces extending multiple interfaces Interfaces can extend multiple other interfaces. Looking at the sniff code, no changes are needed in the sniff to account for this, however, adding an additional unit test to warrant against sniff changes in the future which may not take this into account. N.B.: I've verified all other usages of the `T_INTERFACE` token in the whole of WPCS and this was the only one which looked at `extends/implements`, so the only one for which interfaces extending multiple other interfaces could be problematic. See: * http://php.net/manual/en/language.oop5.interfaces.php#example-208 Loosely related to: * https://github.com/squizlabs/PHP_CodeSniffer/pull/2128 --- .../Tests/NamingConventions/ValidFunctionNameUnitTest.inc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc index a1b567c210..228d4348d0 100644 --- a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc +++ b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc @@ -104,3 +104,8 @@ class My_Soap extends somethingElse { } function __MyTemplateTags() {} // Bad x 2. + +// Verify that interfaces which extend multiple other interfaces do not throw unnecessary errors. +interface MyInterface extends InterfaceA, InterfaceB { + function __MyTemplateTags(); // OK. +} From b1a3ec7ca9d5363ed431cc791fa7d7d6ae4d1543 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 16 Dec 2018 16:00:49 +0100 Subject: [PATCH 021/241] Rulesets: minor simplifications (PHPCS 3.0+) As of PHPCS 3.0.0, you can include individual error codes, not just complete sniffs. Where WPCS rulesets included sniffs, but excluded more than 50% of the error codes from that sniff, it makes sense to switch them over to include individual error codes instead. This also means that where previously, if the `type` and/or `message` of an individual error code was adjusted via the ruleset, the sniff needed to be included first and only after that, the details could be adjusted. Now, the inclusion can just be done based on error code, providing all error codes in the sniff are adjusted. To explain it better: * If a sniff contained five error codes and we adjusted the message for one, there is no real advantage to changing over. * If a sniff contained three error codes and we excluded one, and adjusted another, there is no real advantage to changing over. * However, if a sniff contained only one error code and we'd adjust that one anyway, the new way of including just the error code gets rid of some superfluous configuration. * Similarly, if a sniff contained five error codes, we'd exclude two and adjusted the details for the other three, changing over, again, is to our benefit. --- WordPress-Core/ruleset.xml | 6 +----- WordPress-Extra/ruleset.xml | 7 ------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index b9cd23a91f..98be047a62 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -18,10 +18,7 @@ --> - - - 0 - + @@ -408,7 +405,6 @@ - error eval() is a security risk so not allowed. diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index 2e6a412f59..db44250893 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -42,13 +42,6 @@ - - - 0 - - - 0 - warning From efce48ae5a85d709a4967a1de3684916315c6c85 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 16 Dec 2018 15:03:45 +0100 Subject: [PATCH 022/241] Rulesets: Start using the new XML array format (PHPCS 3.3+) A new format for passing array elements to PHPCS properties was added in PHPCS 3.3.0. This new array format is far more readable and less error prone than the old format. This commit implements using this new array format throughout WPCS, wherever relevant, including in property setting examples in the documentation. Ref: * squizlabs/PHP_CodeSniffer 1665 --- WordPress-Core/ruleset.xml | 6 +++++- WordPress/Sniff.php | 5 ++++- WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php | 6 ++++-- phpcs.xml.dist.sample | 9 +++++++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index b9cd23a91f..189532f2db 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -39,7 +39,11 @@ - + + + + + diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 4f63d8a002..68f1e3c8cb 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -96,7 +96,10 @@ abstract class Sniff implements PHPCS_Sniff { * Example usage: * * - * + * + * + * + * * * * diff --git a/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php b/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php index 646690cade..adef2d4d2d 100644 --- a/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php +++ b/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php @@ -50,8 +50,10 @@ class PrecisionAlignmentSniff extends Sniff { * * * - * + * + * + * + * * * * diff --git a/phpcs.xml.dist.sample b/phpcs.xml.dist.sample index d0fe264fe3..7c074a5173 100644 --- a/phpcs.xml.dist.sample +++ b/phpcs.xml.dist.sample @@ -73,13 +73,18 @@ - + + + + - + + + From 71aed7ae23216e529a38dee4bf7df9b2254473b4 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 16 Dec 2018 14:49:45 +0100 Subject: [PATCH 023/241] Rulesets: Add XSD schema tags and validate rulesets against schema (PHPCS 3.2+/3.3.2+) As of PHPCS 3.2.0, PHPCS includes an XSD schema for rulesets which defines what can be used in the XML ruleset file. In PHPCS 3.3.0 a new array format for properties was introduced and as of PHPCS 3.3.2, the new array format is now also covered by this schema. This commit: * Adds the schema tags to the `ruleset.xml` files, the WPCS native `.phpcs.xml.dist` file, as well as to the example ruleset. * Adds validation against the schema for the `ruleset.xml` files and the example ruleset to the Travis build. Note: The schema used in the tags points to the online schema in PHPCS `master` for two reasons: 1. While WPCS now has a minimum requirement of PHPCS 3.3.1, the schema in PHPCS `master` contains the changes which were made in PHPCS 3.3.2, so we can safely validate the rulesets against the schema. 2. While installation via Composer is supported for WPCS, it is **not** the _only_ supported installation method, so pointing to the version of the XSD schema in the `vendor` directory would be presumptuous. At the same time, using the URL in the Travis script appears to be problematic and as we're doing a composer install there anyway, we may as well use the version in the `vendor` directory for the actual validation. As the validation is done on a build with PHPCS `master`, there will be no difference anyway. Fixes 1477 --- .phpcs.xml.dist | 3 ++- .travis.yml | 4 ++-- WordPress-Core/ruleset.xml | 3 ++- WordPress-Docs/ruleset.xml | 3 ++- WordPress-Extra/ruleset.xml | 3 ++- WordPress/ruleset.xml | 3 ++- phpcs.xml.dist.sample | 3 ++- 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 84af17ae8a..504fdf6c44 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -1,5 +1,6 @@ - + + The Coding standard for the WordPress Coding Standards itself. . diff --git a/.travis.yml b/.travis.yml index e22e12dc6c..b97e957b4e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -85,8 +85,8 @@ script: - if [[ "$SNIFF" == "1" ]]; then $(pwd)/vendor/bin/phpcs --runtime-set ignore_warnings_on_exit 1; fi # Validate the xml files. # @link http://xmlsoft.org/xmllint.html - - if [[ "$SNIFF" == "1" ]]; then xmllint --noout ./*/ruleset.xml; fi - - if [[ "$SNIFF" == "1" ]]; then xmllint --noout ./phpcs.xml.dist.sample; fi + - if [[ "$SNIFF" == "1" ]]; then xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./*/ruleset.xml; fi + - if [[ "$SNIFF" == "1" ]]; then xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./phpcs.xml.dist.sample; fi # Check the code-style consistency of the xml files. - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress/ruleset.xml <(xmllint --format "./WordPress/ruleset.xml"); fi - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-Core/ruleset.xml <(xmllint --format "./WordPress-Core/ruleset.xml"); fi diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index b9cd23a91f..659481ac6f 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -1,5 +1,6 @@ - + + Non-controversial generally-agreed upon WordPress Coding Standards ./../WordPress/PHPCSAliases.php diff --git a/WordPress-Docs/ruleset.xml b/WordPress-Docs/ruleset.xml index 02abd0e73d..fb74597d76 100644 --- a/WordPress-Docs/ruleset.xml +++ b/WordPress-Docs/ruleset.xml @@ -1,5 +1,6 @@ - + + WordPress Coding Standards for Inline Documentation and Comments From 06cec32de85a7630751073322d4a3c136bf979b9 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 18:24:59 +0100 Subject: [PATCH 024/241] PHPUnit: add Composer script to run the tests A `dev` requirement of `phpunit/phpunit` has been added to the `composer.json` file, as well as a script to run the unit tests. While PHPUnit is not strictly speaking a dependency of WPCS (but of PHPCS), this just makes life easier on WPCS developers who use the Composer install for development. If - as a WPCS sniff developer - you've installed WPCS using Composer, you can now run the unit tests, like so: ```bash composer run-tests ``` A note to this effect has been added to the `CONTRIBUTING.MD` file as well. Additionally: * While not strictly necessary, a `testsuite` directive has been added to the `phpunit.xml.dist` file to document where the tests are located and how they are named. * As `PHPCompatibility` will also be installed when using Composer to install WPCS and PHPCompatibility uses its own test setup, we need to prevent PHPCS from trying to load the test files for PHPCompatibility. The `PHPCS_IGNORE_TEST` environment variable in the `phpunit.xml.dist` file does just that. For more information about this, see squizlabs/PHP_CodeSniffer 1146 --- .github/CONTRIBUTING.md | 10 ++++------ composer.json | 6 ++++-- phpunit.xml.dist | 13 +++++++++++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 2693701a61..d763055c2b 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -97,16 +97,11 @@ N.B.: _If you used Composer to install the WordPress Coding Standards, you can s For the unit tests to work, you need to make sure PHPUnit can find your `PHP_CodeSniffer` install. -The easiest way to do this is to add a `phpunit.xml` file to the root of your WPCS installation and set a `PHPCS_DIR` environment variable from within this file. Make sure to adjust the path to reflect your local setup. +The easiest way to do this is to add a `phpunit.xml` file to the root of your WPCS installation and set a `PHPCS_DIR` environment variable from within this file. Copy the existing `phpunit.xml.dist` file and add the below `` directive within the `` section. Make sure to adjust the path to reflect your local setup. ```xml - - ``` ## Running the unit tests @@ -119,6 +114,9 @@ The easiest way to do this is to add a `phpunit.xml` file to the root of your WP * To run the unit tests: ```sh phpunit --filter WordPress --bootstrap="/path/to/PHP_CodeSniffer/tests/bootstrap.php" /path/to/PHP_CodeSniffer/tests/AllTests.php + + # Or if you've installed WPCS with Composer: + composer run-tests ``` Expected output: diff --git a/composer.json b/composer.json index f7511b0fb3..3b1adc8457 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,8 @@ "squizlabs/php_codesniffer": "^3.3.1" }, "require-dev": { - "phpcompatibility/php-compatibility": "^9.0" + "phpcompatibility/php-compatibility": "^9.0", + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, "suggest": { "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." @@ -30,7 +31,8 @@ "post-update-cmd": "@install-codestandards", "check-cs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs", "fix-cs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf", - "install-codestandards": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --config-set installed_paths ../../..,../../phpcompatibility/php-compatibility" + "install-codestandards": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --config-set installed_paths ../../..,../../phpcompatibility/php-compatibility", + "run-tests": "@php ./vendor/phpunit/phpunit/phpunit --filter WordPress --bootstrap=\"./vendor/squizlabs/php_codesniffer/tests/bootstrap.php\" ./vendor/squizlabs/php_codesniffer/tests/AllTests.php" }, "support": { "issues": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 71a1537d3c..ccacc14806 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,4 +5,17 @@ backupGlobals="true" beStrictAboutTestsThatDoNotTestAnything="false" colors="true"> + + + + ./WordPress/Tests/ + + + + + + + From 5dec0aa5e112acfbd163f053cbd18cb3000d8d2b Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 17:59:29 +0100 Subject: [PATCH 025/241] PHPCS 3.1+: Start using the new Tokens::$ooScopeTokens array This new token array was introduced in PHPCS 3.1.0 via squizlabs/PHP_CodeSniffer 1415 and contains `T_CLASS`, `T_ANON_CLASS`, `T_INTERFACE` and `T_TRAIT`. --- WordPress/Sniff.php | 18 ++---------- .../PrefixAllGlobalsSniff.php | 23 ++++++--------- WordPress/Sniffs/WP/CapitalPDangitSniff.php | 17 ++--------- .../WP/GlobalVariablesOverrideSniff.php | 29 ++++++++----------- .../ControlStructureSpacingSniff.php | 7 ++--- 5 files changed, 27 insertions(+), 67 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 68f1e3c8cb..e8572b0bd3 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1171,26 +1171,14 @@ protected function is_token_in_test_method( $stackPtr ) { return false; } - /* - * Is this a method inside of a class or a trait ? If so, it is a test class/trait ? - * - * {@internal Once the minimum supported PHPCS version has gone up to 3.1.0, the - * local array here can be replace with Tokens::$ooScopeTokens.}} - */ - $oo_tokens = array( - \T_CLASS => true, - \T_TRAIT => true, - \T_ANON_CLASS => true, - ); $conditions = $this->tokens[ $stackPtr ]['conditions']; - foreach ( $conditions as $token => $condition ) { if ( $token === $functionToken ) { // Only examine the conditions the function is nested in, not those nested within the function. break; } - if ( isset( $oo_tokens[ $condition ] ) ) { + if ( isset( Tokens::$ooScopeTokens[ $condition ] ) ) { $is_test_class = $this->is_test_class( $token ); if ( true === $is_test_class ) { return true; @@ -1218,9 +1206,7 @@ protected function is_token_in_test_method( $stackPtr ) { */ protected function is_test_class( $stackPtr ) { - if ( ! isset( $this->tokens[ $stackPtr ] ) - || \in_array( $this->tokens[ $stackPtr ]['type'], array( 'T_CLASS', 'T_ANON_CLASS', 'T_TRAIT' ), true ) === false - ) { + if ( isset( $this->tokens[ $stackPtr ], Tokens::$ooScopeTokens[ $this->tokens[ $stackPtr ]['code'] ] ) === false ) { return false; } diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index 6ee6b1418b..8994e57130 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -181,17 +181,14 @@ class PrefixAllGlobalsSniff extends AbstractFunctionParameterSniff { * @return array */ public function register() { - $targets = array( - \T_NAMESPACE => \T_NAMESPACE, - \T_FUNCTION => \T_FUNCTION, - \T_CLASS => \T_CLASS, - \T_INTERFACE => \T_INTERFACE, - \T_TRAIT => \T_TRAIT, - \T_CONST => \T_CONST, - \T_VARIABLE => \T_VARIABLE, - \T_DOLLAR => \T_DOLLAR, // Variable variables. - \T_ANON_CLASS => \T_ANON_CLASS, // Only used for skipping over test classes. + $targets = array( + \T_NAMESPACE => \T_NAMESPACE, + \T_FUNCTION => \T_FUNCTION, + \T_CONST => \T_CONST, + \T_VARIABLE => \T_VARIABLE, + \T_DOLLAR => \T_DOLLAR, // Variable variables. ); + $targets += Tokens::$ooScopeTokens; // T_ANON_CLASS is only used for skipping over test classes. // Add function call target for hook names and constants defined using define(). $parent = parent::register(); @@ -259,9 +256,7 @@ public function process_token( $stackPtr ) { } // Ignore test classes. - if ( ( \T_CLASS === $this->tokens[ $stackPtr ]['code'] - || \T_TRAIT === $this->tokens[ $stackPtr ]['code'] - || \T_ANON_CLASS === $this->tokens[ $stackPtr ]['code'] ) + if ( isset( Tokens::$ooScopeTokens[ $this->tokens[ $stackPtr ]['code'] ] ) && true === $this->is_test_class( $stackPtr ) ) { if ( $this->tokens[ $stackPtr ]['scope_condition'] === $stackPtr && isset( $this->tokens[ $stackPtr ]['scope_closer'] ) ) { @@ -345,7 +340,7 @@ public function process_token( $stackPtr ) { switch ( $this->tokens[ $stackPtr ]['type'] ) { case 'T_FUNCTION': // Methods in a class do not need to be prefixed. - if ( $this->phpcsFile->hasCondition( $stackPtr, array( \T_CLASS, \T_ANON_CLASS, \T_INTERFACE, \T_TRAIT ) ) === true ) { + if ( $this->phpcsFile->hasCondition( $stackPtr, Tokens::$ooScopeTokens ) === true ) { return; } diff --git a/WordPress/Sniffs/WP/CapitalPDangitSniff.php b/WordPress/Sniffs/WP/CapitalPDangitSniff.php index c1b18f0ba9..908e5d6cc8 100644 --- a/WordPress/Sniffs/WP/CapitalPDangitSniff.php +++ b/WordPress/Sniffs/WP/CapitalPDangitSniff.php @@ -75,19 +75,6 @@ class CapitalPDangitSniff extends Sniff { \T_COMMENT => \T_COMMENT, ); - /** - * Class-like structure tokens to listen for. - * - * Using proper spelling in class, interface and trait names does not conflict with the naming conventions. - * - * @var array - */ - private $class_tokens = array( - \T_CLASS => \T_CLASS, - \T_INTERFACE => \T_INTERFACE, - \T_TRAIT => \T_TRAIT, - ); - /** * Combined text string and comment tokens array. * @@ -108,7 +95,7 @@ public function register() { // Union the arrays - keeps the array keys. $this->text_and_comment_tokens = ( $this->text_string_tokens + $this->comment_text_tokens ); - $targets = ( $this->text_and_comment_tokens + $this->class_tokens ); + $targets = ( $this->text_and_comment_tokens + Tokens::$ooScopeTokens ); // Also sniff for array tokens to make skipping anything within those more efficient. $targets[ \T_ARRAY ] = \T_ARRAY; @@ -149,7 +136,7 @@ public function process_token( $stackPtr ) { * Deal with misspellings in class/interface/trait names. * These are not auto-fixable, but need the attention of a developer. */ - if ( isset( $this->class_tokens[ $this->tokens[ $stackPtr ]['code'] ] ) ) { + if ( isset( Tokens::$ooScopeTokens[ $this->tokens[ $stackPtr ]['code'] ] ) ) { $classname = $this->phpcsFile->getDeclarationName( $stackPtr ); if ( empty( $classname ) ) { return; diff --git a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php index 434fc1a8db..aef39075de 100644 --- a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php +++ b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php @@ -49,21 +49,13 @@ class GlobalVariablesOverrideSniff extends Sniff { * Scoped object and function structures to skip over as * variables will have a different scope within those. * - * {@internal Once the minimum PHPCS version goes up to PHPCS 3.1.0, - * this array can be partially created in the register() method - * using the upstream `Tokens::$ooScopeTokens` array.}} - * * @since 1.1.0 * * @var array */ private $skip_over = array( - \T_FUNCTION => true, - \T_CLOSURE => true, - \T_CLASS => true, - \T_ANON_CLASS => true, - \T_INTERFACE => true, - \T_TRAIT => true, + \T_FUNCTION => true, + \T_CLOSURE => true, ); /** @@ -75,15 +67,18 @@ class GlobalVariablesOverrideSniff extends Sniff { * @return array */ public function register() { - return array( + // Add the OO scope tokens to the $skip_over property. + $this->skip_over += Tokens::$ooScopeTokens; + + $targets = array( \T_GLOBAL, \T_VARIABLE, - - // Only used to skip over test classes. - \T_CLASS, - \T_TRAIT, - \T_ANON_CLASS, ); + + // Only used to skip over test classes. + $targets += Tokens::$ooScopeTokens; + + return $targets; } /** @@ -102,7 +97,7 @@ public function process_token( $stackPtr ) { $token = $this->tokens[ $stackPtr ]; // Ignore variable overrides in test classes. - if ( \T_CLASS === $token['code'] || \T_TRAIT === $token['code'] || \T_ANON_CLASS === $token['code'] ) { + if ( isset( Tokens::$ooScopeTokens[ $token['code'] ] ) ) { if ( true === $this->is_test_class( $stackPtr ) && $token['scope_condition'] === $stackPtr diff --git a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php index 379424e171..24a5409c70 100644 --- a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php @@ -404,17 +404,14 @@ public function process_token( $stackPtr ) { $firstContent = $this->phpcsFile->findNext( \T_WHITESPACE, ( $scopeOpener + 1 ), null, true ); // We ignore spacing for some structures that tend to have their own rules. - $ignore = array( + $ignore = array( \T_FUNCTION => true, \T_CLOSURE => true, - \T_CLASS => true, - \T_ANON_CLASS => true, - \T_INTERFACE => true, - \T_TRAIT => true, \T_DOC_COMMENT_OPEN_TAG => true, \T_CLOSE_TAG => true, \T_COMMENT => true, ); + $ignore += Tokens::$ooScopeTokens; if ( ! isset( $ignore[ $this->tokens[ $firstContent ]['code'] ] ) && $this->tokens[ $firstContent ]['line'] > ( $this->tokens[ $scopeOpener ]['line'] + 1 ) From 9455213a250a4fac44decf78127110f267c627db Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 17:28:34 +0100 Subject: [PATCH 026/241] PHPCS 3.2.3+: Remove the Sniff::$phpcsCommentTokens property The (protected) `Sniff::$phpcsCommentTokens` property was a work-around for the `Tokens::$phpcsCommentTokens` array not being available prior to PHPCS 3.2.3. This work-around is no longer needed now the minimum PHPCS version is 3.3.1. Note: This is a BC-break for external standards extending the WordPressCS `Sniff` class which may be using this property. They should adjust their code to use the PHPCS native `Tokens::$phpcsCommentTokens` array instead. --- WordPress/Sniff.php | 34 +++---------------- .../Arrays/ArrayDeclarationSpacingSniff.php | 2 +- .../Arrays/CommaAfterArrayItemSniff.php | 6 ++-- .../ControlStructureSpacingSniff.php | 6 ++-- .../WhiteSpace/PrecisionAlignmentSniff.php | 13 +++---- 5 files changed, 18 insertions(+), 43 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 68f1e3c8cb..1523f812eb 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -781,32 +781,6 @@ abstract class Sniff implements PHPCS_Sniff { 'PHPUnit\Framework\TestCase' => true, ); - /** - * The token "type" values for the PHPCS 3.2+ whitelist comments. - * - * PHPCS cross-version compatibility layer to allow sniffs to - * allow for the new PHPCS annotation comments without breaking in older - * PHPCS versions. - * - * @internal Can be replaced with using the PHPCS native Token::$phpcsCommentTokens - * array once the minimum WPCS requirement for PHPCS has gone up - * to PHPCS 3.2.3. - * Note: The PHPCS native property uses the constants/ token "code", - * so code referring to this property will need to be adjusted when - * the property is removed. - * - * @since 1.0.0 - * - * @var array - */ - protected $phpcsCommentTokens = array( - 'T_PHPCS_ENABLE' => true, - 'T_PHPCS_DISABLE' => true, - 'T_PHPCS_SET' => true, - 'T_PHPCS_IGNORE' => true, - 'T_PHPCS_IGNORE_FILE' => true, - ); - /** * The current file being sniffed. * @@ -1122,8 +1096,8 @@ protected function has_whitelist_comment( $comment, $stackPtr ) { if ( ( ( \T_COMMENT === $this->tokens[ $lastPtr ]['code'] && strpos( $this->tokens[ $lastPtr ]['content'], '@codingStandardsChangeSetting' ) === false ) - || ( isset( $this->phpcsCommentTokens[ $this->tokens[ $lastPtr ]['type'] ] ) - && 'T_PHPCS_SET' !== $this->tokens[ $lastPtr ]['type'] ) ) + || ( isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ]['code'] ] ) + && \T_PHPCS_SET !== $this->tokens[ $lastPtr ]['code'] ) ) && $this->tokens[ $lastPtr ]['line'] === $this->tokens[ $end_of_statement ]['line'] && preg_match( $regex, $this->tokens[ $lastPtr ]['content'] ) === 1 ) { @@ -1138,8 +1112,8 @@ protected function has_whitelist_comment( $comment, $stackPtr ) { if ( ( ( \T_COMMENT === $this->tokens[ $lastPtr ]['code'] && strpos( $this->tokens[ $lastPtr ]['content'], '@codingStandardsChangeSetting' ) === false ) - || ( isset( $this->phpcsCommentTokens[ $this->tokens[ $lastPtr ]['type'] ] ) - && 'T_PHPCS_SET' !== $this->tokens[ $lastPtr ]['type'] ) ) + || ( isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ]['code'] ] ) + && \T_PHPCS_SET !== $this->tokens[ $lastPtr ]['code'] ) ) && $this->tokens[ $lastPtr ]['line'] === $this->tokens[ $stackPtr ]['line'] && preg_match( $regex, $this->tokens[ $lastPtr ]['content'] ) === 1 ) { diff --git a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php index d417fe0ea8..c46769d89f 100644 --- a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php @@ -384,7 +384,7 @@ protected function process_multi_line_array( $stackPtr, $opener, $closer ) { // Ignore comments after array items if the next real content starts on a new line. if ( \T_COMMENT === $this->tokens[ $first_content ]['code'] - || isset( $this->phpcsCommentTokens[ $this->tokens[ $first_content ]['type'] ] ) + || isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $first_content ]['code'] ] ) ) { $next = $this->phpcsFile->findNext( array( \T_WHITESPACE, \T_DOC_COMMENT_WHITESPACE ), diff --git a/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php b/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php index a1b6626b6a..296a406105 100644 --- a/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php +++ b/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php @@ -169,7 +169,7 @@ public function process_token( $stackPtr ) { $spaces += $this->tokens[ $i ]['length']; } } elseif ( \T_COMMENT === $this->tokens[ $i ]['code'] - || isset( $this->phpcsCommentTokens[ $this->tokens[ $i ]['type'] ] ) + || isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $i ]['code'] ] ) ) { break; } @@ -202,7 +202,7 @@ public function process_token( $stackPtr ) { $this->phpcsFile->fixer->replaceToken( $i, '' ); } elseif ( \T_COMMENT === $this->tokens[ $i ]['code'] - || isset( $this->phpcsCommentTokens[ $this->tokens[ $i ]['type'] ] ) + || isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $i ]['code'] ] ) ) { // We need to move the comma to before the comment. $this->phpcsFile->fixer->addContent( $last_content, ',' ); @@ -248,7 +248,7 @@ public function process_token( $stackPtr ) { || ( false === $single_line && $this->tokens[ $next_non_whitespace ]['line'] === $this->tokens[ $maybe_comma ]['line'] && ( \T_COMMENT === $this->tokens[ $next_non_whitespace ]['code'] - || isset( $this->phpcsCommentTokens[ $this->tokens[ $next_non_whitespace ]['type'] ] ) ) ) + || isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $next_non_whitespace ]['code'] ] ) ) ) ) { continue; } diff --git a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php index 379424e171..1388a59608 100644 --- a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php @@ -474,7 +474,7 @@ public function process_token( $stackPtr ) { * conflict. */ if ( \T_COMMENT !== $this->tokens[ $lastContent ]['code'] - && ! isset( $this->phpcsCommentTokens[ $this->tokens[ $lastContent ]['type'] ] ) ) { + && ! isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastContent ]['code'] ] ) ) { $this->phpcsFile->fixer->addNewlineBefore( $j ); } @@ -500,7 +500,7 @@ public function process_token( $stackPtr ) { } if ( \T_COMMENT === $this->tokens[ $trailingContent ]['code'] - || isset( $this->phpcsCommentTokens[ $this->tokens[ $trailingContent ]['type'] ] ) + || isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $trailingContent ]['code'] ] ) ) { // Special exception for code where the comment about // an ELSE or ELSEIF is written between the control structures. @@ -561,7 +561,7 @@ public function process_token( $stackPtr ) { // TODO: Instead a separate error should be triggered when content comes right after closing brace. if ( \T_COMMENT !== $this->tokens[ $scopeCloser ]['code'] - && isset( $this->phpcsCommentTokens[ $this->tokens[ $scopeCloser ]['type'] ] ) === false + && isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $scopeCloser ]['code'] ] ) === false ) { $this->phpcsFile->fixer->addNewlineBefore( $trailingContent ); } diff --git a/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php b/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php index adef2d4d2d..5df4a72fea 100644 --- a/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php +++ b/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php @@ -11,6 +11,7 @@ use WordPressCS\WordPress\Sniff; use WordPressCS\WordPress\PHPCSHelper; +use PHP_CodeSniffer\Util\Tokens; /** * Warn on line indentation ending with spaces for precision alignment. @@ -96,18 +97,18 @@ public function process_token( $stackPtr ) { $ignoreAlignmentTokens = $this->merge_custom_array( $this->ignoreAlignmentTokens ); $check_tokens = array( - 'T_WHITESPACE' => true, - 'T_INLINE_HTML' => true, - 'T_DOC_COMMENT_WHITESPACE' => true, - 'T_COMMENT' => true, + \T_WHITESPACE => true, + \T_INLINE_HTML => true, + \T_DOC_COMMENT_WHITESPACE => true, + \T_COMMENT => true, ); - $check_tokens += $this->phpcsCommentTokens; + $check_tokens += Tokens::$phpcsCommentTokens; for ( $i = 0; $i < $this->phpcsFile->numTokens; $i++ ) { if ( 1 !== $this->tokens[ $i ]['column'] ) { continue; - } elseif ( isset( $check_tokens[ $this->tokens[ $i ]['type'] ] ) === false + } elseif ( isset( $check_tokens[ $this->tokens[ $i ]['code'] ] ) === false || ( isset( $this->tokens[ ( $i + 1 ) ] ) && \T_WHITESPACE === $this->tokens[ ( $i + 1 ) ]['code'] ) || $this->tokens[ $i ]['content'] === $this->phpcsFile->eolChar From 4503f13614ca1298219f9f6d8126ac94aef33e56 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 20:20:49 +0100 Subject: [PATCH 027/241] PHPCS 3.2+: Update inline annotations to PHPCS 3.2+ format --- WordPress/Sniff.php | 1 + WordPress/Sniffs/WP/CronIntervalSniff.php | 2 +- bin/class-ruleset-test.php | 10 +++++----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 68f1e3c8cb..41c3ce02fd 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1756,6 +1756,7 @@ protected function is_validated( $stackPtr, $array_key = null, $in_condition_onl $bare_array_key = $this->strip_quotes( $array_key ); + // phpcs:ignore Generic.CodeAnalysis.JumbledIncrementer.Found -- On purpose, see below. for ( $i = ( $scope_start + 1 ); $i < $scope_end; $i++ ) { if ( ! \in_array( $this->tokens[ $i ]['code'], array( \T_ISSET, \T_EMPTY, \T_UNSET ), true ) ) { diff --git a/WordPress/Sniffs/WP/CronIntervalSniff.php b/WordPress/Sniffs/WP/CronIntervalSniff.php index 56965e89fb..ae7efe50e9 100644 --- a/WordPress/Sniffs/WP/CronIntervalSniff.php +++ b/WordPress/Sniffs/WP/CronIntervalSniff.php @@ -178,7 +178,7 @@ public function process_token( $stackPtr ) { // If all digits and operators, eval! if ( preg_match( '#^[\s\d+*/-]+$#', $value ) > 0 ) { - $interval = eval( "return ( $value );" ); // @codingStandardsIgnoreLine - No harm here. + $interval = eval( "return ( $value );" ); // phpcs:ignore Squiz.PHP.Eval -- No harm here. break; } diff --git a/bin/class-ruleset-test.php b/bin/class-ruleset-test.php index 7d0d7a82c4..df174759bc 100644 --- a/bin/class-ruleset-test.php +++ b/bin/class-ruleset-test.php @@ -72,11 +72,11 @@ public function testing( $param_a, ?bool $param_b = false ): void { $d = new self(); $e = apply_filter( 'filter_name', $d, $c ); - if ( $a == $b ) { // WPCS: loose comparison OK. - $f = isset( $_GET['nonce'] ) ? 1 : 2; // WPCS: CSRF ok, input var ok. + if ( $a == $b ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison + $f = isset( $_GET['nonce'] ) ? 1 : 2; // phpcs:ignore WordPress.Security.NonceVerification.Recommended } - // @codingStandardsIgnoreLine + // phpcs:ignore Squiz.PHP.Eval,WordPress.PHP.NoSilencedErrors $g = @eval( 'return true;' ); switch ( $param_a ) { @@ -100,13 +100,13 @@ public function test_goto() { for ( ; $i < 100; $i++ ) { while ( $j-- ) { if ( 17 === $j ) { - // @codingStandardsIgnoreLine + // phpcs:ignore WordPress.PHP.DiscourageGoto.Found goto end; } } } - // @codingStandardsIgnoreLine + // phpcs:ignore WordPress.PHP.DiscourageGoto.Found end: echo 'This is a goto - it needs to be here to prevent parse errors'; } From bf7ff69baa73bb2edd7161e338806ca6008e0617 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 21:39:33 +0100 Subject: [PATCH 028/241] PHPCS 3.2+: Update unit test case annotations [1] Change `@codingStandardsChangeSetting` to `phpcs:set` (PHPCS 3.2.0) for non-array properties. --- .../ArrayDeclarationSpacingUnitTest.1.inc | 4 +- ...rrayDeclarationSpacingUnitTest.1.inc.fixed | 4 +- .../ArrayDeclarationSpacingUnitTest.2.inc | 4 +- ...rrayDeclarationSpacingUnitTest.2.inc.fixed | 4 +- .../Arrays/ArrayIndentationUnitTest.2.inc | 4 +- .../ArrayIndentationUnitTest.2.inc.fixed | 4 +- .../MultipleStatementAlignmentUnitTest.1.inc | 56 +++++++++---------- ...ipleStatementAlignmentUnitTest.1.inc.fixed | 56 +++++++++---------- .../MultipleStatementAlignmentUnitTest.2.inc | 56 +++++++++---------- ...ipleStatementAlignmentUnitTest.2.inc.fixed | 56 +++++++++---------- .../ValidHookNameUnitTest.2.inc | 4 +- .../ValidHookNameUnitTest.3.inc | 4 +- .../Tests/PHP/NoSilencedErrorsUnitTest.inc | 4 +- .../Utils/I18nTextDomainFixerUnitTest.1.inc | 4 +- .../Utils/I18nTextDomainFixerUnitTest.2.inc | 4 +- .../Utils/I18nTextDomainFixerUnitTest.3.inc | 6 +- .../I18nTextDomainFixerUnitTest.3.inc.fixed | 6 +- .../Utils/I18nTextDomainFixerUnitTest.4.inc | 4 +- .../I18nTextDomainFixerUnitTest.4.inc.fixed | 4 +- .../Utils/I18nTextDomainFixerUnitTest.css | 8 +-- .../I18nTextDomainFixerUnitTest.css.fixed | 8 +-- .../Tests/WP/AlternativeFunctionsUnitTest.inc | 10 ++-- WordPress/Tests/WP/CronIntervalUnitTest.inc | 6 +- .../WP/GlobalVariablesOverrideUnitTest.3.inc | 4 +- WordPress/Tests/WP/I18nUnitTest.1.inc | 4 +- WordPress/Tests/WP/I18nUnitTest.1.inc.fixed | 4 +- WordPress/Tests/WP/PostsPerPageUnitTest.inc | 6 +- .../ArbitraryParenthesesSpacingUnitTest.inc | 12 ++-- ...itraryParenthesesSpacingUnitTest.inc.fixed | 12 ++-- .../ControlStructureSpacingUnitTest.1.inc | 16 +++--- ...ontrolStructureSpacingUnitTest.1.inc.fixed | 16 +++--- .../ControlStructureSpacingUnitTest.2.inc | 4 +- ...ontrolStructureSpacingUnitTest.2.inc.fixed | 4 +- 33 files changed, 201 insertions(+), 201 deletions(-) diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc index e3120a8816..c5e1eb35d3 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc @@ -103,12 +103,12 @@ $fields = array( $bad = array('key' => 'value'); // Bad, spacing around parenthesis. $bad = array( 'key' => 'value' ); // Bad, spacing around parenthesis. -// @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays false +// phpcs:set WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays false $bad = array( 'key' => 'value' ); // Bad. $bad = array( 'key1' => 'value1', 'key2' => 'value2' ); // Bad. -// @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true +// phpcs:set WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true $foo = array( 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed index 71b8d9c8f3..53e935b11f 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed @@ -153,7 +153,7 @@ $fields = array( $bad = array( 'key' => 'value' ); // Bad, spacing around parenthesis. $bad = array( 'key' => 'value' ); // Bad, spacing around parenthesis. -// @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays false +// phpcs:set WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays false $bad = array( 'key' => 'value' @@ -163,7 +163,7 @@ $bad = array( 'key2' => 'value2' ); // Bad. -// @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true +// phpcs:set WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true $foo = array( 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc index ff971e9177..e9157b7981 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc @@ -86,12 +86,12 @@ $fields = [ $bad = ['key' => 'value']; // Bad, spacing around parenthesis. $bad = [ 'key' => 'value' ]; // Bad, spacing around parenthesis. -// @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays false +// phpcs:set WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays false $bad = [ 'key' => 'value' ]; // Bad. $bad = [ 'key1' => 'value1', 'key2' => 'value2' ]; // Bad. -// @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true +// phpcs:set WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true $foo = [ 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed index 23c25a07b2..1dfa3c8e9f 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed @@ -137,7 +137,7 @@ $fields = [ $bad = [ 'key' => 'value' ]; // Bad, spacing around parenthesis. $bad = [ 'key' => 'value' ]; // Bad, spacing around parenthesis. -// @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays false +// phpcs:set WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays false $bad = [ 'key' => 'value' @@ -147,7 +147,7 @@ $bad = [ 'key2' => 'value2' ]; // Bad. -// @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true +// phpcs:set WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true $foo = [ 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode diff --git a/WordPress/Tests/Arrays/ArrayIndentationUnitTest.2.inc b/WordPress/Tests/Arrays/ArrayIndentationUnitTest.2.inc index f6dd726bdc..ec646ebcbc 100644 --- a/WordPress/Tests/Arrays/ArrayIndentationUnitTest.2.inc +++ b/WordPress/Tests/Arrays/ArrayIndentationUnitTest.2.inc @@ -1,5 +1,5 @@ 'h', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false $array = array( 'a' => 'b', ); @@ -95,7 +95,7 @@ $array = array( 'g' => 'h', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true /* @@ -107,17 +107,17 @@ $array = array( 'ccc' => 'd', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false $array = array( 'a' => 'b', // Bad. 'ccc' => 'd', // Bad. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false // Test combined ignore new lines false + exact false. $array = array( 'a' => 'b', @@ -147,14 +147,14 @@ $array = array( 'g' => 'h', // Bad. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true /* * Test with maxColumn value set. */ -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 $array = array( 'a' => 'b', 'ccc' => 'd', @@ -177,10 +177,10 @@ $array = array( 'ee' => 'f', // Bad. 'gggggggggg' => 'h', // Bad - too much space before. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 // Test combined maxColumn value set + exact false. $array = array( 'a' => 'b', @@ -220,12 +220,12 @@ $array = array( 'ee' => 'f', // Bad. 'gggggggggg' => 'h', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false // Test combined maxColumn value set + exact false + ignore new lines false. $array = array( 'a' => 'b', @@ -267,9 +267,9 @@ $array = array( 'kkkkkkkkkkkk' => 'l', // Bad. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true /* @@ -330,7 +330,7 @@ $deprecated_functions = array( ), ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems never +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems never // OK - alignments to the expected column. $deprecated_functions = array( @@ -381,24 +381,24 @@ $deprecated_functions = array( string', // Bad. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems sometimes +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems sometimes // Test invalid property value error. $array = array( 'a' => 'b', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems =103 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems =103 // Test invalid property value error. $array = array( 'a' => 'b', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !50 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !50 // Test invalid property value error. $array = array( 'a' => 'b', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <25 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <25 // OK - alignments to the expected column. $deprecated_functions = array( @@ -462,7 +462,7 @@ $deprecated_functions = array( string', // Bad - no space. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <=50% +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <=50% // Test with value 50 and test validation for incorrectly passed % sign. $deprecated_functions = array( @@ -523,7 +523,7 @@ $deprecated_functions = array( string', // Bad - no space. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !=100 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !=100 $deprecated_functions = array( 'single1' => 'something', // Bad. @@ -571,4 +571,4 @@ $deprecated_functions = array( string', // Bad. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems always +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems always diff --git a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.1.inc.fixed b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.1.inc.fixed index 7169de6e9a..969373f2b1 100644 --- a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.1.inc.fixed +++ b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.1.inc.fixed @@ -70,7 +70,7 @@ $array = array( => 'h', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false $array = array( 'a' => 'b', ); @@ -95,7 +95,7 @@ $array = array( 'g' => 'h', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true /* @@ -107,15 +107,15 @@ $array = array( 'ccc' => 'd', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false $array = array( 'a' => 'b', // Bad. 'ccc' => 'd', // Bad. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false // Test combined ignore new lines false + exact false. $array = array( 'a' => 'b', @@ -141,14 +141,14 @@ $array = array( 'ee' => 'f', 'g' => 'h', // Bad. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true /* * Test with maxColumn value set. */ -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 $array = array( 'a' => 'b', 'ccc' => 'd', @@ -171,10 +171,10 @@ $array = array( 'ee' => 'f', // Bad. 'gggggggggg' => 'h', // Bad - too much space before. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 // Test combined maxColumn value set + exact false. $array = array( 'a' => 'b', @@ -214,12 +214,12 @@ $array = array( 'ee' => 'f', // Bad. 'gggggggggg' => 'h', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false // Test combined maxColumn value set + exact false + ignore new lines false. $array = array( 'a' => 'b', @@ -253,9 +253,9 @@ $array = array( 'i' => 'j', // Bad. 'kkkkkkkkkkkk' => 'l', // Bad. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true /* @@ -316,7 +316,7 @@ $deprecated_functions = array( ), ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems never +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems never // OK - alignments to the expected column. $deprecated_functions = array( @@ -367,24 +367,24 @@ $deprecated_functions = array( string', // Bad. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems sometimes +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems sometimes // Test invalid property value error. $array = array( 'a' => 'b', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems =103 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems =103 // Test invalid property value error. $array = array( 'a' => 'b', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !50 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !50 // Test invalid property value error. $array = array( 'a' => 'b', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <25 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <25 // OK - alignments to the expected column. $deprecated_functions = array( @@ -448,7 +448,7 @@ $deprecated_functions = array( string', // Bad - no space. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <=50% +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <=50% // Test with value 50 and test validation for incorrectly passed % sign. $deprecated_functions = array( @@ -509,7 +509,7 @@ $deprecated_functions = array( string', // Bad - no space. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !=100 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !=100 $deprecated_functions = array( 'single1' => 'something', // Bad. @@ -557,4 +557,4 @@ $deprecated_functions = array( string', // Bad. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems always +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems always diff --git a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.2.inc b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.2.inc index d26927cd41..66507e4342 100644 --- a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.2.inc +++ b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.2.inc @@ -70,7 +70,7 @@ $array = [ => 'h', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false $array = [ 'a' => 'b', ]; @@ -95,7 +95,7 @@ $array = [ 'g' => 'h', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true /* @@ -107,17 +107,17 @@ $array = [ 'ccc' => 'd', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false $array = [ 'a' => 'b', // Bad. 'ccc' => 'd', // Bad. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false // Test combined ignore new lines false + exact false. $array = [ 'a' => 'b', @@ -147,14 +147,14 @@ $array = [ 'g' => 'h', // Bad. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true /* * Test with maxColumn value set. */ -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 $array = [ 'a' => 'b', 'ccc' => 'd', @@ -177,10 +177,10 @@ $array = [ 'ee' => 'f', // Bad. 'gggggggggg' => 'h', // Bad - too much space before. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 // Test combined maxColumn value set + exact false. $array = [ 'a' => 'b', @@ -220,12 +220,12 @@ $array = [ 'ee' => 'f', // Bad. 'gggggggggg' => 'h', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false // Test combined maxColumn value set + exact false + ignore new lines false. $array = [ 'a' => 'b', @@ -267,9 +267,9 @@ $array = [ 'kkkkkkkkkkkk' => 'l', // Bad. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true /* @@ -330,7 +330,7 @@ $deprecated_functions = [ ), ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems never +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems never // OK - alignments to the expected column. $deprecated_functions = [ @@ -381,24 +381,24 @@ $deprecated_functions = [ string', // Bad. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems sometimes +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems sometimes // Test invalid property value error. $array = [ 'a' => 'b', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems =103 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems =103 // Test invalid property value error. $array = [ 'a' => 'b', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !50 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !50 // Test invalid property value error. $array = [ 'a' => 'b', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <25 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <25 // OK - alignments to the expected column. $deprecated_functions = [ @@ -462,7 +462,7 @@ $deprecated_functions = [ string', // Bad - no space. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <=50% +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <=50% // Test with value 50 and test validation for incorrectly passed % sign. $deprecated_functions = [ @@ -523,7 +523,7 @@ $deprecated_functions = [ string', // Bad - no space. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !=100 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !=100 $deprecated_functions = [ 'single1' => 'something', // Bad. @@ -571,4 +571,4 @@ $deprecated_functions = [ string', // Bad. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems always +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems always diff --git a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.2.inc.fixed b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.2.inc.fixed index ccd188dcb7..f171336722 100644 --- a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.2.inc.fixed +++ b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.2.inc.fixed @@ -70,7 +70,7 @@ $array = [ => 'h', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false $array = [ 'a' => 'b', ]; @@ -95,7 +95,7 @@ $array = [ 'g' => 'h', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true /* @@ -107,15 +107,15 @@ $array = [ 'ccc' => 'd', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false $array = [ 'a' => 'b', // Bad. 'ccc' => 'd', // Bad. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false // Test combined ignore new lines false + exact false. $array = [ 'a' => 'b', @@ -141,14 +141,14 @@ $array = [ 'ee' => 'f', 'g' => 'h', // Bad. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true /* * Test with maxColumn value set. */ -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 $array = [ 'a' => 'b', 'ccc' => 'd', @@ -171,10 +171,10 @@ $array = [ 'ee' => 'f', // Bad. 'gggggggggg' => 'h', // Bad - too much space before. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 // Test combined maxColumn value set + exact false. $array = [ 'a' => 'b', @@ -214,12 +214,12 @@ $array = [ 'ee' => 'f', // Bad. 'gggggggggg' => 'h', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false // Test combined maxColumn value set + exact false + ignore new lines false. $array = [ 'a' => 'b', @@ -253,9 +253,9 @@ $array = [ 'i' => 'j', // Bad. 'kkkkkkkkkkkk' => 'l', // Bad. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true /* @@ -316,7 +316,7 @@ $deprecated_functions = [ ), ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems never +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems never // OK - alignments to the expected column. $deprecated_functions = [ @@ -367,24 +367,24 @@ $deprecated_functions = [ string', // Bad. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems sometimes +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems sometimes // Test invalid property value error. $array = [ 'a' => 'b', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems =103 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems =103 // Test invalid property value error. $array = [ 'a' => 'b', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !50 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !50 // Test invalid property value error. $array = [ 'a' => 'b', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <25 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <25 // OK - alignments to the expected column. $deprecated_functions = [ @@ -448,7 +448,7 @@ $deprecated_functions = [ string', // Bad - no space. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <=50% +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <=50% // Test with value 50 and test validation for incorrectly passed % sign. $deprecated_functions = [ @@ -509,7 +509,7 @@ $deprecated_functions = [ string', // Bad - no space. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !=100 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !=100 $deprecated_functions = [ 'single1' => 'something', // Bad. @@ -557,4 +557,4 @@ $deprecated_functions = [ string', // Bad. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems always +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems always diff --git a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.2.inc b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.2.inc index 084a176612..99b42d3b2b 100644 --- a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.2.inc +++ b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.2.inc @@ -1,6 +1,6 @@ screen->id}", $this->_actions ); // Warning - use underscore. apply_filters( "current_theme/supports-{$feature}", true, $args, $_wp_theme_features[$feature] ); // Warning - use underscore. -// @codingStandardsChangeSetting WordPress.NamingConventions.ValidHookName additionalWordDelimiters _ +// phpcs:set WordPress.NamingConventions.ValidHookName additionalWordDelimiters _ diff --git a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.3.inc b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.3.inc index e58cc75781..61b854c582 100644 --- a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.3.inc +++ b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.3.inc @@ -1,6 +1,6 @@ screen->id}", $this->_actions ); // Warning - use underscore. apply_filters( "current_theme#supports-{$feature}", true, $args, $_wp_theme_features[$feature] ); // Warning - use underscore. -// @codingStandardsChangeSetting WordPress.NamingConventions.ValidHookName additionalWordDelimiters _ +// phpcs:set WordPress.NamingConventions.ValidHookName additionalWordDelimiters _ diff --git a/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.inc b/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.inc index 18b0faaa77..38869c11f9 100644 --- a/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.inc +++ b/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.inc @@ -52,7 +52,7 @@ $unserialized = @unserialize( $str ); /* * ... and test the same principle again, but now without using the whitelist. */ -// @codingStandardsChangeSetting WordPress.PHP.NoSilencedErrors use_default_whitelist false +// phpcs:set WordPress.PHP.NoSilencedErrors use_default_whitelist false // File extension. if ( @&file_exists( $filename ) && @ /*comment*/ is_readable( $filename ) ) { // Bad x2. @@ -79,4 +79,4 @@ echo @some_userland_function( $param ); // Bad. $decoded = @hex2bin( $data ); // @codingStandardsChangeSetting WordPress.PHP.NoSilencedErrors custom_whitelist false -// @codingStandardsChangeSetting WordPress.PHP.NoSilencedErrors use_default_whitelist true +// phpcs:set WordPress.PHP.NoSilencedErrors use_default_whitelist true diff --git a/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.1.inc b/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.1.inc index 08665c16f5..02526739e9 100644 --- a/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.1.inc +++ b/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.1.inc @@ -1,6 +1,6 @@ ' ); // OK. -// @codingStandardsChangeSetting WordPress.WP.AlternativeFunctions minimum_supported_version 4.0 +// phpcs:set WordPress.WP.AlternativeFunctions minimum_supported_version 4.0 parse_url($url, PHP_URL_QUERY); // OK. -// @codingStandardsChangeSetting WordPress.WP.AlternativeFunctions minimum_supported_version 4.7 +// phpcs:set WordPress.WP.AlternativeFunctions minimum_supported_version 4.7 parse_url($url, PHP_URL_SCHEME); // Warning. -// @codingStandardsChangeSetting WordPress.WP.AlternativeFunctions minimum_supported_version 4.6 +// phpcs:set WordPress.WP.AlternativeFunctions minimum_supported_version 4.6 file_get_contents( $local_file, true ); // OK. file_get_contents( $url, false ); // Warning. diff --git a/WordPress/Tests/WP/CronIntervalUnitTest.inc b/WordPress/Tests/WP/CronIntervalUnitTest.inc index 78da5bb0bb..712eb64072 100644 --- a/WordPress/Tests/WP/CronIntervalUnitTest.inc +++ b/WordPress/Tests/WP/CronIntervalUnitTest.inc @@ -81,7 +81,7 @@ add_filter( 'cron_schedules', function ( $schedules ) { return $schedules; } ); // Warning: time undetermined. -// @codingStandardsChangeSetting WordPress.WP.CronInterval min_interval 600 +// phpcs:set WordPress.WP.CronInterval min_interval 600 add_filter( 'cron_schedules', function ( $schedules ) { $schedules['every_2_mins'] = array( 'interval' => 2 * 60, @@ -104,7 +104,7 @@ add_filter( 'cron_schedules', function ( $schedules ) { return $schedules; } ); // OK: > 10 min. -// @codingStandardsChangeSetting WordPress.WP.CronInterval min_interval 1800 +// phpcs:set WordPress.WP.CronInterval min_interval 1800 add_filter( 'cron_schedules', function ( $schedules ) { $schedules['every_2_mins'] = array( 'interval' => 2 * 60, @@ -127,7 +127,7 @@ add_filter( 'cron_schedules', function ( $schedules ) { return $schedules; } ); // Ok: > 30 min. -// @codingStandardsChangeSetting WordPress.WP.CronInterval min_interval 900 +// phpcs:set WordPress.WP.CronInterval min_interval 900 add_filter( 'cron_schedules', function ( $schedules ) { diff --git a/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.3.inc b/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.3.inc index 9dd7f6c876..c6cf922415 100644 --- a/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.3.inc +++ b/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.3.inc @@ -6,7 +6,7 @@ * For this file, none of the variables overrides should throw errors, for the sister-file they all should. */ -// @codingStandardsChangeSetting WordPress.WP.GlobalVariablesOverride treat_files_as_scoped true +// phpcs:set WordPress.WP.GlobalVariablesOverride treat_files_as_scoped true // Overrides in the global namespace should be detected no matter what. No need for a `global` statement. $pagenow = 'abc'; // OK. @@ -28,4 +28,4 @@ $domain['subkey'] = 'something else'; // OK. $GLOBALS['domain']['subkey'] = 'something else'; // Still bad. -// @codingStandardsChangeSetting WordPress.WP.GlobalVariablesOverride treat_files_as_scoped false +// phpcs:set WordPress.WP.GlobalVariablesOverride treat_files_as_scoped false diff --git a/WordPress/Tests/WP/I18nUnitTest.1.inc b/WordPress/Tests/WP/I18nUnitTest.1.inc index 249e902c37..fc2abd2547 100644 --- a/WordPress/Tests/WP/I18nUnitTest.1.inc +++ b/WordPress/Tests/WP/I18nUnitTest.1.inc @@ -1,6 +1,6 @@ extra !== $extra)) {} // Bad x 4. if (( null !== $extra ) && ( $row->extra !== $extra )) {} @@ -114,7 +114,7 @@ if ( $success && ('nothumb' == $target || 'all' == $target) ) {} // Bad x 2. $directory = ('/' == $file[ strlen($file)-1 ]); // Bad x 2. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 /* * Test handling of ignoreNewlines. @@ -132,7 +132,7 @@ $a = ( null !== $extra ); // Bad x 2, 1 x line 131, 1 x line 133. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 1 +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 1 if ( ( null !== $extra @@ -144,9 +144,9 @@ if ( $a = ( null !== $extra ); // Bad x 2, 1 x line 144, 1 x line 146. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines true +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines true if ( ( null !== $extra @@ -158,4 +158,4 @@ if ( $a = ( null !== $extra ); -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines false +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines false diff --git a/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed b/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed index 64c9edd4a7..c75771237c 100644 --- a/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed +++ b/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed @@ -86,7 +86,7 @@ if ( $success && ('nothumb' == $target || 'all' == $target) ) {} $directory = ('/' == $file[ strlen($file)-1 ]); -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 1 +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 1 if (( null !== $extra ) && ( $row->extra !== $extra )) {} // Bad x 4. if (( null !== $extra ) && ( $row->extra !== $extra )) {} @@ -114,7 +114,7 @@ if ( $success && ( 'nothumb' == $target || 'all' == $target ) ) {} // Bad x 2. $directory = ( '/' == $file[ strlen($file)-1 ] ); // Bad x 2. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 /* * Test handling of ignoreNewlines. @@ -126,15 +126,15 @@ if ( $a = (null !== $extra); // Bad x 2, 1 x line 131, 1 x line 133. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 1 +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 1 if ( ( null !== $extra ) && ( $row->extra !== $extra ) ) {} // Bad x 4, 1 x line 137, 2 x line 139, 1 x line 141. $a = ( null !== $extra ); // Bad x 2, 1 x line 144, 1 x line 146. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines true +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines true if ( ( null !== $extra @@ -146,4 +146,4 @@ if ( $a = ( null !== $extra ); -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines false +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines false diff --git a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc index c8cede58b7..ab0d8568b6 100644 --- a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc +++ b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc @@ -45,7 +45,7 @@ endif; if ( false ) : else : endif; -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 1 +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 1 $a = function($arg){}; // Bad. $a = function ( $arg ) { // Ok. @@ -74,7 +74,7 @@ function testA() function &return_by_ref() {} // Ok. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 0 +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 0 $a = function() {}; // Ok. $a = function( $arg ) {}; // Ok. @@ -84,7 +84,7 @@ $a = function () {}; // Bad. $closureWithArgsAndVars = function( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Ok. $closureWithArgsAndVars = function ( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Bad. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 1 +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 1 $closureWithArgsAndVars = function ( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Ok. @@ -100,7 +100,7 @@ $closureWithArgsAndVars = function ( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // // Namespaces. use Foo\Admin; -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren -1 +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren -1 $a = function( $arg ) {}; // Ok. $a = function ( $arg ) {}; // Ok. @@ -139,12 +139,12 @@ try{ // Bad. } // Upstream bug PEAR #20248. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing blank_line_check true +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing blank_line_check true // Bad. if ( $one ) { } -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing blank_line_check false +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing blank_line_check false // Upstream bug PEAR #20247. do { @@ -152,7 +152,7 @@ do { } while ($blah); // Bad. // Upstream bug GH #782 -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing blank_line_check true +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing blank_line_check true if ( $foo ) { @@ -173,7 +173,7 @@ if ( $foo ) { } -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing blank_line_check false +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing blank_line_check false // Check for too many spaces as long as the next non-blank token is on the same line. function test( $blah ) {} // Bad. diff --git a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc.fixed b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc.fixed index bed9205f68..ef625e6362 100644 --- a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc.fixed +++ b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc.fixed @@ -43,7 +43,7 @@ endif; if ( false ) : else : endif; -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 1 +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 1 $a = function ( $arg ) {}; // Bad. $a = function ( $arg ) { // Ok. @@ -70,7 +70,7 @@ function testA() {} // Bad. function &return_by_ref() {} // Ok. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 0 +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 0 $a = function() {}; // Ok. $a = function( $arg ) {}; // Ok. @@ -80,7 +80,7 @@ $a = function() {}; // Bad. $closureWithArgsAndVars = function( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Ok. $closureWithArgsAndVars = function( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Bad. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 1 +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 1 $closureWithArgsAndVars = function ( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Ok. @@ -96,7 +96,7 @@ $closureWithArgsAndVars = function ( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // // Namespaces. use Foo\Admin; -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren -1 +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren -1 $a = function( $arg ) {}; // Ok. $a = function ( $arg ) {}; // Ok. @@ -135,11 +135,11 @@ try { // Bad. } // Upstream bug PEAR #20248. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing blank_line_check true +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing blank_line_check true // Bad. if ( $one ) { } -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing blank_line_check false +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing blank_line_check false // Upstream bug PEAR #20247. do { @@ -147,7 +147,7 @@ do { } while ( $blah ); // Bad. // Upstream bug GH #782 -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing blank_line_check true +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing blank_line_check true if ( $foo ) { @@ -168,7 +168,7 @@ if ( $foo ) { } -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing blank_line_check false +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing blank_line_check false // Check for too many spaces as long as the next non-blank token is on the same line. function test( $blah ) {} // Bad. diff --git a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.2.inc b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.2.inc index 44f7bd2b95..f35ba950bb 100644 --- a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.2.inc +++ b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.2.inc @@ -1,7 +1,7 @@ Date: Sat, 15 Dec 2018 21:42:40 +0100 Subject: [PATCH 029/241] PHPCS 3.2+/3.3+: Update unit test case annotations [2] * Change `@codingStandardsChangeSetting` to `phpcs:set` (PHPCS 3.2.0) for array properties. * Change properties to use the new array format (PHPCS 3.3.0). --- .../Tests/DB/DirectDatabaseQueryUnitTest.inc | 14 ++++++------ .../Tests/DB/RestrictedClassesUnitTest.1.inc | 6 ++--- .../PrefixAllGlobalsUnitTest.1.inc | 22 +++++++++---------- .../PrefixAllGlobalsUnitTest.2.inc | 4 ++-- .../PrefixAllGlobalsUnitTest.3.inc | 4 ++-- .../PrefixAllGlobalsUnitTest.4.inc | 8 +++---- .../ValidVariableNameUnitTest.inc | 4 ++-- .../PHP/DevelopmentFunctionsUnitTest.inc | 6 ++--- .../Tests/PHP/NoSilencedErrorsUnitTest.inc | 8 +++---- .../Tests/Security/EscapeOutputUnitTest.inc | 12 +++++----- .../Security/NonceVerificationUnitTest.inc | 14 ++++++------ .../ValidatedSanitizedInputUnitTest.inc | 10 ++++----- .../Utils/I18nTextDomainFixerUnitTest.3.inc | 12 +++++----- .../I18nTextDomainFixerUnitTest.3.inc.fixed | 12 +++++----- .../Utils/I18nTextDomainFixerUnitTest.4.inc | 4 ++-- .../I18nTextDomainFixerUnitTest.4.inc.fixed | 4 ++-- .../Utils/I18nTextDomainFixerUnitTest.css | 6 ++--- .../I18nTextDomainFixerUnitTest.css.fixed | 6 ++--- .../WP/GlobalVariablesOverrideUnitTest.1.inc | 4 ++-- .../WP/GlobalVariablesOverrideUnitTest.4.inc | 4 ++-- WordPress/Tests/WP/I18nUnitTest.1.inc | 10 ++++----- WordPress/Tests/WP/I18nUnitTest.1.inc.fixed | 10 ++++----- WordPress/Tests/WP/I18nUnitTest.2.inc | 4 ++-- .../PrecisionAlignmentUnitTest.2.inc | 4 ++-- .../PrecisionAlignmentUnitTest.7a.inc | 2 +- .../PrecisionAlignmentUnitTest.7c.inc | 2 +- 26 files changed, 98 insertions(+), 98 deletions(-) diff --git a/WordPress/Tests/DB/DirectDatabaseQueryUnitTest.inc b/WordPress/Tests/DB/DirectDatabaseQueryUnitTest.inc index a6cb54414a..2f735dd7f5 100644 --- a/WordPress/Tests/DB/DirectDatabaseQueryUnitTest.inc +++ b/WordPress/Tests/DB/DirectDatabaseQueryUnitTest.inc @@ -119,9 +119,9 @@ $b = function () { /* * Test using custom properties, setting & unsetting (resetting). */ -// @codingStandardsChangeSetting WordPress.DB.DirectDatabaseQuery customCacheGetFunctions my_cacheget -// @codingStandardsChangeSetting WordPress.DB.DirectDatabaseQuery customCacheSetFunctions my_cacheset,my_other_cacheset -// @codingStandardsChangeSetting WordPress.DB.DirectDatabaseQuery customCacheDeleteFunctions my_cachedel +// phpcs:set WordPress.DB.DirectDatabaseQuery customCacheGetFunctions[] my_cacheget +// phpcs:set WordPress.DB.DirectDatabaseQuery customCacheSetFunctions[] my_cacheset,my_other_cacheset +// phpcs:set WordPress.DB.DirectDatabaseQuery customCacheDeleteFunctions[] my_cachedel function cache_customA() { global $wpdb; @@ -149,8 +149,8 @@ function cache_customC() { my_cachedel( 'key', 'group' ); } -// @codingStandardsChangeSetting WordPress.DB.DirectDatabaseQuery customCacheSetFunctions my_cacheset -// @codingStandardsChangeSetting WordPress.DB.DirectDatabaseQuery customCacheDeleteFunctions false +// phpcs:set WordPress.DB.DirectDatabaseQuery customCacheSetFunctions[] my_cacheset +// phpcs:set WordPress.DB.DirectDatabaseQuery customCacheDeleteFunctions[] function cache_customD() { global $wpdb; @@ -179,8 +179,8 @@ function cache_customF() { my_cachedel( 'key', 'group' ); } -// @codingStandardsChangeSetting WordPress.DB.DirectDatabaseQuery customCacheGetFunctions false -// @codingStandardsChangeSetting WordPress.DB.DirectDatabaseQuery customCacheSetFunctions false +// phpcs:set WordPress.DB.DirectDatabaseQuery customCacheGetFunctions[] +// phpcs:set WordPress.DB.DirectDatabaseQuery customCacheSetFunctions[] function cache_customG() { global $wpdb; diff --git a/WordPress/Tests/DB/RestrictedClassesUnitTest.1.inc b/WordPress/Tests/DB/RestrictedClassesUnitTest.1.inc index c5dbdc3897..60d70609bb 100644 --- a/WordPress/Tests/DB/RestrictedClassesUnitTest.1.inc +++ b/WordPress/Tests/DB/RestrictedClassesUnitTest.1.inc @@ -45,21 +45,21 @@ $db9 = new \My\DBlayer; * Test exclude property. */ // Exclude one group: -// @codingStandardsChangeSetting WordPress.DB.RestrictedClasses exclude test +// phpcs:set WordPress.DB.RestrictedClasses exclude[] test $db9 = new \My\DBlayer; // Ok - within excluded group. echo mysqli::$affected_rows; // Error. class YourMysqliA extends \mysqli {} // Error. // Exclude all groups: -// @codingStandardsChangeSetting WordPress.DB.RestrictedClasses exclude test,mysql +// phpcs:set WordPress.DB.RestrictedClasses exclude[] test,mysql $db9 = new \My\DBlayer; // Ok - within excluded group. echo mysqli::$affected_rows; // Ok - within excluded group. class YourMysqliB extends \mysqli {} // Ok - within excluded group. // Reset group exclusions. -// @codingStandardsChangeSetting WordPress.DB.RestrictedClasses exclude false +// phpcs:set WordPress.DB.RestrictedClasses exclude[] $db9 = new \My\DBlayer; // Error. echo mysqli::$affected_rows; // Error. diff --git a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc index 4098a17e94..10b79f3a86 100644 --- a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc +++ b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc @@ -3,14 +3,14 @@ /* * Bad: invalid prefix passed */ -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes wp +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] wp function wp_do_something() {} -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes ^%& +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] ^%& function ^%&_do_something() {} // Now let's set the real prefixes we want to test for. -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes acronym,tgmpa +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] acronym,tgmpa /* * Bad - not prefixed. @@ -181,7 +181,7 @@ class Example extends WP_UnitTestCase { function do_something() {} } -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals custom_test_class_whitelist My_TestClass +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals custom_test_class_whitelist[] My_TestClass class Test_Class_D extends My_TestClass { const SOME_CONSTANT = 'value'; @@ -190,7 +190,7 @@ class Test_Class_D extends My_TestClass { function do_something() {} } -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals custom_test_class_whitelist false +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals custom_test_class_whitelist[] /* @@ -379,7 +379,7 @@ define( 'FORCE_SSL_ADMIN', true ); const SCRIPT_DEBUG = $develop_src; // Allow for hook name prefixes with less conventional separators. -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes test-this,myplugin\ +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] test-this,myplugin\ do_action( 'test-this-hookname' ); // OK. apply_filters( 'myplugin\filtername', $var ); // OK. @@ -398,18 +398,18 @@ class Some_Test_Class extends NonTestClass { // Bad. } } -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes wordpress,somethingelse +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] wordpress,somethingelse // The above line adds an issue to line 1 about a blacklisted prefix. function wordpress_do_something() {} // Bad. function somethingelse_do_something() {} // OK. -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes my_wordpress_plugin +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] my_wordpress_plugin apply_filters( 'my_wordpress_plugin_filtername', $var ); // OK. -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes test-this +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] test-this do_action( 'Test-THIS-hookname' ); // OK. -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes acronym,tgmpa +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] acronym,tgmpa // Issue #1495 - throw the error on the line with the non-prefixed name. $acronym = apply_filters( 'content-types-post-types', // Bad. @@ -424,4 +424,4 @@ define( [ 1, 2, 3 ] ); -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes false +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] diff --git a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.2.inc b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.2.inc index d83f0564fc..7a9193871a 100644 --- a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.2.inc +++ b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.2.inc @@ -1,5 +1,5 @@ DOMProperty; // Ok, whitelisted. echo $object->varName; // Ok, whitelisted. -// @codingStandardsChangeSetting WordPress.NamingConventions.ValidVariableName customPropertiesWhitelist false +// phpcs:set WordPress.NamingConventions.ValidVariableName customPropertiesWhitelist[] echo $object->varName; // Bad, no longer whitelisted. diff --git a/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc b/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc index ab9fa0bfc5..5039be590e 100644 --- a/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc +++ b/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc @@ -19,16 +19,16 @@ error_reporting(); // Error. * Test exclude property. */ // Exclude one group: -// @codingStandardsChangeSetting WordPress.PHP.DevelopmentFunctions exclude error_log +// phpcs:set WordPress.PHP.DevelopmentFunctions exclude[] error_log trigger_error(); // Ok - within excluded group. phpinfo(); // Error. // Exclude all groups: -// @codingStandardsChangeSetting WordPress.PHP.DevelopmentFunctions exclude error_log,prevent_path_disclosure +// phpcs:set WordPress.PHP.DevelopmentFunctions exclude[] error_log,prevent_path_disclosure trigger_error(); // Ok - within excluded group. phpinfo(); // Ok - within excluded group. // Reset group exclusions. -// @codingStandardsChangeSetting WordPress.PHP.DevelopmentFunctions exclude false +// phpcs:set WordPress.PHP.DevelopmentFunctions exclude[] trigger_error(); // Error. phpinfo(); // Error. diff --git a/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.inc b/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.inc index 38869c11f9..3e52794bc9 100644 --- a/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.inc +++ b/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.inc @@ -39,11 +39,11 @@ if ( @ftp_fget($conn_id, $handle, $remote_file, FTP_ASCII, 0 ) ) { // Bad. } @ftp_close($conn_id); // Bad. -// @codingStandardsChangeSetting WordPress.PHP.NoSilencedErrors custom_whitelist fgetcsv,hex2bin +// phpcs:set WordPress.PHP.NoSilencedErrors custom_whitelist[] fgetcsv,hex2bin while ( ( $csvdata = @fgetcsv( $handle, 2000, $separator ) ) !== false ) {} echo @some_userland_function( $param ); // Bad. $decoded = @hex2bin( $data ); -// @codingStandardsChangeSetting WordPress.PHP.NoSilencedErrors custom_whitelist false +// phpcs:set WordPress.PHP.NoSilencedErrors custom_whitelist[] $decoded = @hex2bin( $data ); // Bad. @@ -73,10 +73,10 @@ $files1 = @ & scandir($dir); // Bad. /* * Custom whitelist will be respected even when `use_default_whitelist` is set to false. */ -// @codingStandardsChangeSetting WordPress.PHP.NoSilencedErrors custom_whitelist fgetcsv,hex2bin +// phpcs:set WordPress.PHP.NoSilencedErrors custom_whitelist[] fgetcsv,hex2bin while ( ( $csvdata = @fgetcsv( $handle, 2000, $separator ) ) !== false ) {} echo @some_userland_function( $param ); // Bad. $decoded = @hex2bin( $data ); -// @codingStandardsChangeSetting WordPress.PHP.NoSilencedErrors custom_whitelist false +// phpcs:set WordPress.PHP.NoSilencedErrors custom_whitelist[] // phpcs:set WordPress.PHP.NoSilencedErrors use_default_whitelist true diff --git a/WordPress/Tests/Security/EscapeOutputUnitTest.inc b/WordPress/Tests/Security/EscapeOutputUnitTest.inc index d27ec631f1..bd7adb3930 100644 --- a/WordPress/Tests/Security/EscapeOutputUnitTest.inc +++ b/WordPress/Tests/Security/EscapeOutputUnitTest.inc @@ -186,21 +186,21 @@ echo add_filter( get_the_excerpt( get_the_ID() ) ; // Bad, but ignored as code c /* * Test using custom properties, setting & unsetting (resetting). */ -// @codingStandardsChangeSetting WordPress.Security.EscapeOutput customPrintingFunctions to_screen,my_print +// phpcs:set WordPress.Security.EscapeOutput customPrintingFunctions[] to_screen,my_print to_screen( $var1, esc_attr( $var2 ) ); // Bad x 1. my_print( $var1, $var2 ); // Bad x 2. -// @codingStandardsChangeSetting WordPress.Security.EscapeOutput customEscapingFunctions esc_form_field -// @codingStandardsChangeSetting WordPress.Security.EscapeOutput customAutoEscapedFunctions post_info,cpt_info +// phpcs:set WordPress.Security.EscapeOutput customEscapingFunctions[] esc_form_field +// phpcs:set WordPress.Security.EscapeOutput customAutoEscapedFunctions[] post_info,cpt_info echo esc_form_field( $var ); // Ok. echo post_info( $post_id, 'field' ); // Ok. echo cpt_info( $post_type, 'query' ); // Ok. to_screen( esc_form_field( $var1), esc_attr( $var2 ) ); // Ok. -// @codingStandardsChangeSetting WordPress.Security.EscapeOutput customPrintingFunctions false -// @codingStandardsChangeSetting WordPress.Security.EscapeOutput customEscapingFunctions false -// @codingStandardsChangeSetting WordPress.Security.EscapeOutput customAutoEscapedFunctions false +// phpcs:set WordPress.Security.EscapeOutput customPrintingFunctions[] +// phpcs:set WordPress.Security.EscapeOutput customEscapingFunctions[] +// phpcs:set WordPress.Security.EscapeOutput customAutoEscapedFunctions[] echo esc_form_field( $var ); // Bad. echo post_info( $post_id, 'field' ); // Bad. diff --git a/WordPress/Tests/Security/NonceVerificationUnitTest.inc b/WordPress/Tests/Security/NonceVerificationUnitTest.inc index 953ef4a134..b5387355de 100644 --- a/WordPress/Tests/Security/NonceVerificationUnitTest.inc +++ b/WordPress/Tests/Security/NonceVerificationUnitTest.inc @@ -129,9 +129,9 @@ $b = function () { /* * Test using custom properties, setting & unsetting (resetting). */ -// @codingStandardsChangeSetting WordPress.Security.NonceVerification customNonceVerificationFunctions my_nonce_check -// @codingStandardsChangeSetting WordPress.Security.NonceVerification customSanitizingFunctions sanitize_pc,sanitize_twitter -// @codingStandardsChangeSetting WordPress.Security.NonceVerification customUnslashingSanitizingFunctions do_something +// phpcs:set WordPress.Security.NonceVerification customNonceVerificationFunctions[] my_nonce_check +// phpcs:set WordPress.Security.NonceVerification customSanitizingFunctions[] sanitize_pc,sanitize_twitter +// phpcs:set WordPress.Security.NonceVerification customUnslashingSanitizingFunctions[] do_something function foo_6() { @@ -140,8 +140,8 @@ function foo_6() { my_nonce_check( do_something( $_POST['tweet'] ) ); // OK. } -// @codingStandardsChangeSetting WordPress.Security.NonceVerification customSanitizingFunctions sanitize_pc -// @codingStandardsChangeSetting WordPress.Security.NonceVerification customUnslashingSanitizingFunctions false +// phpcs:set WordPress.Security.NonceVerification customSanitizingFunctions[] sanitize_pc +// phpcs:set WordPress.Security.NonceVerification customUnslashingSanitizingFunctions[] function foo_7() { @@ -151,8 +151,8 @@ function foo_7() { my_nonce_check( sanitize_twitter( $_POST['tweet'] ) ); // OK. } -// @codingStandardsChangeSetting WordPress.Security.NonceVerification customNonceVerificationFunctions false -// @codingStandardsChangeSetting WordPress.Security.NonceVerification customSanitizingFunctions false +// phpcs:set WordPress.Security.NonceVerification customNonceVerificationFunctions[] +// phpcs:set WordPress.Security.NonceVerification customSanitizingFunctions[] function foo_8() { diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc index 3e99770deb..9a8e6c4844 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc @@ -131,21 +131,21 @@ function test_this() { $abc = sanitize_color( wp_unslash( $_POST['abc_field'] ) ); // Bad x1 - sanitize. - // @codingStandardsChangeSetting WordPress.Security.ValidatedSanitizedInput customSanitizingFunctions sanitize_color,sanitize_twitter_handle + // phpcs:set WordPress.Security.ValidatedSanitizedInput customSanitizingFunctions[] sanitize_color,sanitize_twitter_handle $abc = sanitize_color( wp_unslash( $_POST['abc_field'] ) ); // OK. $abc = sanitize_facebook_id( wp_unslash( $_POST['abc_field'] ) ); // Bad x1 - sanitize. $abc = sanitize_twitter_handle( $_POST['abc_field'] ); // Bad x1 - unslash. - // @codingStandardsChangeSetting WordPress.Security.ValidatedSanitizedInput customSanitizingFunctions sanitize_color,sanitize_facebook_id - // @codingStandardsChangeSetting WordPress.Security.ValidatedSanitizedInput customUnslashingSanitizingFunctions sanitize_twitter_handle + // phpcs:set WordPress.Security.ValidatedSanitizedInput customSanitizingFunctions[] sanitize_color,sanitize_facebook_id + // phpcs:set WordPress.Security.ValidatedSanitizedInput customUnslashingSanitizingFunctions[] sanitize_twitter_handle $abc = sanitize_color( wp_unslash( $_POST['abc_field'] ) ); // OK. $abc = sanitize_facebook_id( wp_unslash( $_POST['abc_field'] ) ); // OK. $abc = sanitize_twitter_handle( $_POST['abc_field'] ); // OK. - // @codingStandardsChangeSetting WordPress.Security.ValidatedSanitizedInput customSanitizingFunctions false - // @codingStandardsChangeSetting WordPress.Security.ValidatedSanitizedInput customUnslashingSanitizingFunctions false + // phpcs:set WordPress.Security.ValidatedSanitizedInput customSanitizingFunctions[] + // phpcs:set WordPress.Security.ValidatedSanitizedInput customUnslashingSanitizingFunctions[] $abc = sanitize_twitter_handle( $_POST['abc_field'] ); // Bad x2, sanitize + unslash. } diff --git a/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.3.inc b/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.3.inc index 780315e84f..adf61b3332 100644 --- a/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.3.inc +++ b/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.3.inc @@ -1,5 +1,5 @@ translate( $string ); // OK, not a function, but a method call. Something\esc_html_e( $string ); // OK, not the WP function, but namespaced function call. @@ -177,5 +177,5 @@ $offset_or_tz = _x( '0', 'default GMT offset or timezone string', 'my-slug' ); $test = __( '%1$s %2$s', 'my-slug' ); // OK(ish), placeholder order may change depending on language. $test = __( ' %s ', 'my-slug' ); // Bad, no translatable content. -// @codingStandardsChangeSetting WordPress.WP.I18n text_domain false +// phpcs:set WordPress.WP.I18n text_domain[] // phpcs:set WordPress.WP.I18n check_translator_comments true diff --git a/WordPress/Tests/WP/I18nUnitTest.1.inc.fixed b/WordPress/Tests/WP/I18nUnitTest.1.inc.fixed index 42c5132505..7689308bcd 100644 --- a/WordPress/Tests/WP/I18nUnitTest.1.inc.fixed +++ b/WordPress/Tests/WP/I18nUnitTest.1.inc.fixed @@ -5,7 +5,7 @@ __( 'string' ); // OK - no text domain known, so not checked. __( 'string', 'something' ); // OK - no text domain known, so not checked. -// @codingStandardsChangeSetting WordPress.WP.I18n text_domain my-slug +// phpcs:set WordPress.WP.I18n text_domain[] my-slug __( 'string' ); // Bad - no text domain passed. __( 'string', 'something' ); // Bad - text domain mismatch. @@ -147,20 +147,20 @@ really. EOD , 'my-slug' ); // OK. -// @codingStandardsChangeSetting WordPress.WP.I18n text_domain my-slug,default +// phpcs:set WordPress.WP.I18n text_domain[] my-slug,default __( "String default text domain.", "my-slug" ); // Ok. __( "String default text domain.", "default" ); // Ok. __( "String default text domain.", 'something' ); // Bad, text domain mismatch. __( 'String default text domain.' ); // Warning, use default. -// @codingStandardsChangeSetting WordPress.WP.I18n text_domain default +// phpcs:set WordPress.WP.I18n text_domain[] default __( 'String default text domain.', 'my-slug' ); // Bad because text_domain is only 'default'. __( 'String default text domain.' ); // Warning, text domain can be omitted. __( 'String default text domain.', /* Explicitly set for reason. */ 'default' ); // Warning, text domain can be omitted (not auto-fixable). __( 'String default text domain.' ); // Ok because default domain is 'default' and it matches one of the supplied configured text domains. // Issue #1266. -// @codingStandardsChangeSetting WordPress.WP.I18n text_domain my-slug +// phpcs:set WordPress.WP.I18n text_domain[] my-slug $mo->translate( $string ); // OK, not a function, but a method call. Something\esc_html_e( $string ); // OK, not the WP function, but namespaced function call. @@ -177,5 +177,5 @@ $offset_or_tz = _x( '0', 'default GMT offset or timezone string', 'my-slug' ); $test = __( '%1$s %2$s', 'my-slug' ); // OK(ish), placeholder order may change depending on language. $test = __( ' %s ', 'my-slug' ); // Bad, no translatable content. -// @codingStandardsChangeSetting WordPress.WP.I18n text_domain false +// phpcs:set WordPress.WP.I18n text_domain[] // phpcs:set WordPress.WP.I18n check_translator_comments true diff --git a/WordPress/Tests/WP/I18nUnitTest.2.inc b/WordPress/Tests/WP/I18nUnitTest.2.inc index 4ad5e2895b..eac6892a4d 100644 --- a/WordPress/Tests/WP/I18nUnitTest.2.inc +++ b/WordPress/Tests/WP/I18nUnitTest.2.inc @@ -2,7 +2,7 @@ /* * Test sniffing for translator comments. */ -// @codingStandardsChangeSetting WordPress.WP.I18n text_domain my-slug +// phpcs:set WordPress.WP.I18n text_domain[] my-slug /* Basic test ****************************************************************/ __( 'No placeholders here.', 'my-slug' ); // Ok, no placeholders, so no translators comment needed. @@ -107,4 +107,4 @@ _e(); // Bad. // phpcs:ignore Standard.Category.Sniff -- testing that the PHPCS annotations are handled correctly. printf( __( 'There are %1$d monkeys in the %2$s', 'my-slug' ), intval( $number ), esc_html( $string ) ); // Bad. -// @codingStandardsChangeSetting WordPress.WP.I18n text_domain false +// phpcs:set WordPress.WP.I18n text_domain[] diff --git a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.2.inc b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.2.inc index ce007868ea..8ee264ae22 100644 --- a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.2.inc +++ b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.2.inc @@ -1,4 +1,4 @@ -@codingStandardsChangeSetting WordPress.WhiteSpace.PrecisionAlignment ignoreAlignmentTokens T_COMMENT,T_DOC_COMMENT_WHITESPACE,T_INLINE_HTML,T_FUNCTION +phpcs:set WordPress.WhiteSpace.PrecisionAlignment ignoreAlignmentTokens[] T_COMMENT,T_DOC_COMMENT_WHITESPACE,T_INLINE_HTML,T_FUNCTION Date: Sun, 16 Dec 2018 13:44:27 +0100 Subject: [PATCH 030/241] PHPCS 3.2+/3.3+: Update unit test case annotations [3] Change for the `FileName` sniff unit tests. * Change `@codingStandardsChangeSetting` to `phpcs:set` (PHPCS 3.2.0). * Change array properties to use the new array format (PHPCS 3.3.0). * Move the annotations away from line 1. If a line just and only contains a PHPCS annotation, no errors will be thrown on it. As the `FileName` sniff will always throw errors on line 1, this means that the settings change annotations _cannot_ be on line 1 for the tests to work correctly. --- .../NonStrictClassNames/ClassNonStrictClass.inc | 5 +++-- .../NonStrictClassNames/non-strict-class.inc | 5 +++-- .../NonStrictClassNames/unrelated-filename.inc | 5 +++-- .../FileNameUnitTests/TestFiles/test-sample-custom-unit.inc | 5 +++-- .../TestFiles/test-sample-global-namespace-extends.1.inc | 5 +++-- .../TestFiles/test-sample-global-namespace-extends.2.inc | 5 +++-- .../TestFiles/test-sample-namespaced-declaration.1.inc | 5 +++-- .../TestFiles/test-sample-namespaced-declaration.2.inc | 5 +++-- .../TestFiles/test-sample-namespaced-declaration.3.inc | 5 +++-- .../TestFiles/test-sample-namespaced-declaration.4.inc | 5 +++-- .../TestFiles/test-sample-namespaced-extends.1.inc | 5 +++-- .../TestFiles/test-sample-namespaced-extends.2.inc | 5 +++-- .../TestFiles/test-sample-namespaced-extends.3.inc | 5 +++-- .../TestFiles/test-sample-namespaced-extends.4.inc | 5 +++-- .../TestFiles/test-sample-namespaced-extends.5.inc | 5 +++-- .../Files/FileNameUnitTests/ThemeExceptions/FrontPage.inc | 5 +++-- .../FileNameUnitTests/ThemeExceptions/application_flash.inc | 5 +++-- .../FileNameUnitTests/ThemeExceptions/archive-post_type.inc | 5 +++-- .../FileNameUnitTests/ThemeExceptions/author-nice_name.inc | 5 +++-- .../ThemeExceptions/category-another_slug.inc | 5 +++-- .../FileNameUnitTests/ThemeExceptions/category-slug.inc | 5 +++-- .../ThemeExceptions/content-another_slug.inc | 5 +++-- .../Files/FileNameUnitTests/ThemeExceptions/content-slug.inc | 5 +++-- .../ThemeExceptions/embed-post_type-post_format.inc | 5 +++-- .../FileNameUnitTests/ThemeExceptions/embed-post_type.inc | 5 +++-- .../Files/FileNameUnitTests/ThemeExceptions/front-page.inc | 5 +++-- .../Files/FileNameUnitTests/ThemeExceptions/front_page.inc | 5 +++-- .../FileNameUnitTests/ThemeExceptions/page-slug_slug.inc | 5 +++-- .../FileNameUnitTests/ThemeExceptions/single-post-type.inc | 5 +++-- .../ThemeExceptions/single-post_type-slug.inc | 5 +++-- .../FileNameUnitTests/ThemeExceptions/single-post_type.inc | 5 +++-- .../FileNameUnitTests/ThemeExceptions/tag-another_slug.inc | 5 +++-- .../Files/FileNameUnitTests/ThemeExceptions/tag-slug.inc | 5 +++-- .../ThemeExceptions/taxonomy-my_taxonomy-term.inc | 5 +++-- .../ThemeExceptions/taxonomy-my_taxonomy.inc | 5 +++-- .../taxonomy-post_format-post-format-link.inc | 5 +++-- .../ThemeExceptions/taxonomy-post_format.inc | 5 +++-- .../Tests/Files/FileNameUnitTests/ThemeExceptions/text.inc | 5 +++-- .../Files/FileNameUnitTests/ThemeExceptions/text_plain.inc | 5 +++-- 39 files changed, 117 insertions(+), 78 deletions(-) diff --git a/WordPress/Tests/Files/FileNameUnitTests/NonStrictClassNames/ClassNonStrictClass.inc b/WordPress/Tests/Files/FileNameUnitTests/NonStrictClassNames/ClassNonStrictClass.inc index c4d4103a48..fb6d0ab14e 100644 --- a/WordPress/Tests/Files/FileNameUnitTests/NonStrictClassNames/ClassNonStrictClass.inc +++ b/WordPress/Tests/Files/FileNameUnitTests/NonStrictClassNames/ClassNonStrictClass.inc @@ -1,7 +1,8 @@ -@codingStandardsChangeSetting WordPress.Files.FileName strict_class_file_names false + +phpcs:set WordPress.Files.FileName strict_class_file_names false +phpcs:set WordPress.Files.FileName strict_class_file_names false +phpcs:set WordPress.Files.FileName strict_class_file_names false +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] My_TestClass +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] TestSample +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] Some\Name\TestSample +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] Some\Name\TestSample +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] TestSample +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] Some\Name\TestSample +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] Some\Name\TestSample +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] Some\Name\TestSample +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] Some\Name\TestSample +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] TestSample +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] Some\Name\TestSample +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] Some\Name\TestSample +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true Date: Mon, 17 Dec 2018 04:28:44 +0100 Subject: [PATCH 031/241] Core: Remove `encoding` (PHPCS 3.0.0) The default encoding as of PHPCS 3.0.0 is `utf-8`, so there is no need to set this anymore in the ruleset. --- WordPress-Core/ruleset.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index a01712e9c3..99483c11c6 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -5,9 +5,6 @@ ./../WordPress/PHPCSAliases.php - - - From 61b8ab424b2403c34f9fda20cf25d7c32d0e5f2c Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 29 Aug 2017 22:22:28 +0200 Subject: [PATCH 032/241] Extra: Defer to upstream `Generic.Files.OneObjectStructurePerFile` sniff (PHPCS 3.1.0) PHPCS 3.1.0 includes a new `Generic.Files.OneObjectStructurePerFile` sniff. We previously included the `Generic.Files.OneClassPerFile`, `Generic.Files.OneInterfacePerFile` and the `Generic.Files.OneTraitPerFile` sniffs. Each of those would only throw an error is a second object structure of the same kind was found in a file, i.e. two classes in one file, but would allow files which contained more than one object structure, but of different types, through without any errors being thrown, i.e. an interface and a class in the same file. The new `Generic.Files.OneObjectStructurePerFile` sniff fixes this and can effectively replace the previously included sniffs. Note: this is a BC-break for anyone using a custom ruleset or PHPCS annotations referencing the previously included sniffs. Refs: * squizlabs/PHP_CodeSniffer 1627 * squizlabs/PHP_CodeSniffer 1630 --- WordPress-Extra/ruleset.xml | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index f96cd4e977..87acba16a9 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -63,22 +63,9 @@ - - - + warning - Best practice suggestion: Declare only one class in a file. - - - - warning - Best practice suggestion: Declare only one interface in a file. - - - - warning - Best practice suggestion: Declare only one trait in a file. + Best practice suggestion: Declare only one class/interface/trait in a file. - diff --git a/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php b/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php deleted file mode 100644 index 0aefd0a8ab..0000000000 --- a/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php +++ /dev/null @@ -1,91 +0,0 @@ -phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); - - if ( \T_OPEN_PARENTHESIS !== $this->tokens[ $openParenthesis ]['code'] ) { - // Not a function call. - return; - } - - if ( ! isset( $this->tokens[ $openParenthesis ]['parenthesis_closer'] ) ) { - // Not a function call. - return; - } - - // Find the previous non-empty token. - $search = Tokens::$emptyTokens; - $search[] = \T_BITWISE_AND; - $previous = $this->phpcsFile->findPrevious( $search, ( $stackPtr - 1 ), null, true ); - if ( \T_FUNCTION === $this->tokens[ $previous ]['code'] ) { - // It's a function definition, not a function call. - return; - } - - $closer = $this->tokens[ $openParenthesis ]['parenthesis_closer']; - - if ( ( $closer - 1 ) === $openParenthesis ) { - return; - } - - $nextNonWhitespace = $this->phpcsFile->findNext( \T_WHITESPACE, ( $openParenthesis + 1 ), null, true ); - - if ( $nextNonWhitespace !== $closer ) { - // Function has params or comment between parenthesis. - return; - } - - $fix = $this->phpcsFile->addFixableError( - 'Function calls without parameters should have no spaces between the parenthesis.', - ( $openParenthesis + 1 ), - 'WhitespaceFound' - ); - if ( true === $fix ) { - // If there is only whitespace between the parenthesis, it will just be the one token. - $this->phpcsFile->fixer->replaceToken( ( $openParenthesis + 1 ), '' ); - } - } - -} diff --git a/WordPress/Tests/Functions/FunctionCallSignatureNoParamsUnitTest.inc b/WordPress/Tests/Functions/FunctionCallSignatureNoParamsUnitTest.inc deleted file mode 100644 index 788da75df0..0000000000 --- a/WordPress/Tests/Functions/FunctionCallSignatureNoParamsUnitTest.inc +++ /dev/null @@ -1,9 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 4 => 1, - 5 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array(); - } - -} From cf3205f7fdc8ce5f5d9706020a5e039bbd47e615 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 16 Dec 2018 22:15:27 +0100 Subject: [PATCH 035/241] Readme: Recommend/mention dot prefixed config files (PHPCS 3.1.1) Since PHPCS 3.1.0, the config file can be dot-prefixed, i.e. `.phpcs.xml` or `.phpcs.xml.dist`. Since PHPCS 3.1.1, the loading order has been corrected for the config files. So, as the minimum PHPCS version is now well passed those versions, let's mention this in the readme. Refs: * squizlabs/PHP_CodeSniffer 1566 * squizlabs/PHP_CodeSniffer 1693 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8e9fc04d31..c4b644d5d2 100644 --- a/README.md +++ b/README.md @@ -138,11 +138,11 @@ The `WordPress-VIP` ruleset was originally intended to aid with the [WordPress.c ### Using a custom ruleset -If you need to further customize the selection of sniffs for your project - you can create a custom ruleset file. When you name this file either `phpcs.xml` or `phpcs.xml.dist`, PHP_CodeSniffer will automatically locate it as long as it is placed in the directory from which you run the CodeSniffer or in a directory above it. If you follow these naming conventions you don't have to supply a `--standard` arg. For more info, read about [using a default configuration file](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-default-configuration-file). See also provided [`phpcs.xml.dist.sample`](phpcs.xml.dist.sample) file and [fully annotated example](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml) in the PHP_CodeSniffer documentation. +If you need to further customize the selection of sniffs for your project - you can create a custom ruleset file. When you name this file either `.phpcs.xml`, `phpcs.xml`, `.phpcs.xml.dist` or `phpcs.xml.dist`, PHP_CodeSniffer will automatically locate it as long as it is placed in the directory from which you run the CodeSniffer or in a directory above it. If you follow these naming conventions you don't have to supply a `--standard` arg. For more info, read about [using a default configuration file](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-default-configuration-file). See also provided [`phpcs.xml.dist.sample`](phpcs.xml.dist.sample) file and [fully annotated example](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml) in the PHP_CodeSniffer documentation. ### Customizing sniff behaviour -The WordPress Coding Standard contains a number of sniffs which are configurable. This means that you can turn parts of the sniff on or off, or change the behaviour by setting a property for the sniff in your custom `phpcs.xml` file. +The WordPress Coding Standard contains a number of sniffs which are configurable. This means that you can turn parts of the sniff on or off, or change the behaviour by setting a property for the sniff in your custom `.phpcs.xml.dist` file. You can find a complete list of all the properties you can change in the [wiki](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties). From 73a8cd1951b6b751e140289c8686463ab86078ca Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 16 Dec 2018 17:49:36 +0100 Subject: [PATCH 036/241] Core: Defer to upstream `Generic.PHP.DiscourageGoto` sniff (PHPCS 3.2.0) PHPCS 3.2.0 includes the same `DiscourageGoto` sniff as was previously pulled to WPCS. As the minimum PHPCS requirement has gone up to beyond 3.2.0 now, we can switch over to use the upstream version instead. Note: Deprecating the WPCS version of the sniff and letting it extend the upstream version and throwing a deprecation message would be useless in this case, as: * When doing so, the error codes for the normal messages would not change, so people would not be able to update their custom rulesets and/or inline annotations. * If both sniffs - the WPCS one and the PHPCS version - would be included in the ruleset, we'd need to silence the error codes from one or the other to prevent duplicate messages from being thrown. - If we'd silence the PHPCS messages, the net effect would be the same as just keeping the WPCS sniff and people would still not be able to adjust their rulesets/annotations. - If we'd silence the WPCS messages, the net effect would be the same as this PR minus the deprecation message. So, as this will be going into a major release anyway, we may as well get the change over with. Note: this is a BC-break for anyone using a custom ruleset or PHPCS annotations referencing the previously included sniff. Refs: * squizlabs/PHP_CodeSniffer 1662 * squizlabs/PHP_CodeSniffer 1664 --- WordPress-Core/ruleset.xml | 5 +- WordPress/Sniffs/PHP/DiscourageGotoSniff.php | 50 ------------------- .../Tests/PHP/DiscourageGotoUnitTest.inc | 18 ------- .../Tests/PHP/DiscourageGotoUnitTest.php | 46 ----------------- bin/class-ruleset-test.php | 4 +- 5 files changed, 3 insertions(+), 120 deletions(-) delete mode 100644 WordPress/Sniffs/PHP/DiscourageGotoSniff.php delete mode 100644 WordPress/Tests/PHP/DiscourageGotoUnitTest.inc delete mode 100644 WordPress/Tests/PHP/DiscourageGotoUnitTest.php diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index 99483c11c6..e32592ad3d 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -398,10 +398,7 @@ - - - + error The "goto" language construct should not be used. diff --git a/WordPress/Sniffs/PHP/DiscourageGotoSniff.php b/WordPress/Sniffs/PHP/DiscourageGotoSniff.php deleted file mode 100644 index 5e2ce7ede5..0000000000 --- a/WordPress/Sniffs/PHP/DiscourageGotoSniff.php +++ /dev/null @@ -1,50 +0,0 @@ -phpcsFile->addWarning( 'Using the "goto" language construct is discouraged', $stackPtr, 'Found' ); - } - -} diff --git a/WordPress/Tests/PHP/DiscourageGotoUnitTest.inc b/WordPress/Tests/PHP/DiscourageGotoUnitTest.inc deleted file mode 100644 index f564215b05..0000000000 --- a/WordPress/Tests/PHP/DiscourageGotoUnitTest.inc +++ /dev/null @@ -1,18 +0,0 @@ - => - */ - public function getErrorList() { - return array(); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 3 => 1, - 6 => 1, - 11 => 1, - 16 => 1, - ); - } - -} diff --git a/bin/class-ruleset-test.php b/bin/class-ruleset-test.php index df174759bc..e9a85899c4 100644 --- a/bin/class-ruleset-test.php +++ b/bin/class-ruleset-test.php @@ -100,13 +100,13 @@ public function test_goto() { for ( ; $i < 100; $i++ ) { while ( $j-- ) { if ( 17 === $j ) { - // phpcs:ignore WordPress.PHP.DiscourageGoto.Found + // phpcs:ignore Generic.PHP.DiscourageGoto.Found goto end; } } } - // phpcs:ignore WordPress.PHP.DiscourageGoto.Found + // phpcs:ignore Generic.PHP.DiscourageGoto.Found end: echo 'This is a goto - it needs to be here to prevent parse errors'; } From c7bc2f78b413e4079410cc0ab07287177b1272aa Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 16 Dec 2018 18:51:59 +0100 Subject: [PATCH 037/241] Core: Defer to upstream `Squiz.WhiteSpace.SemicolonSpacing` sniff (PHPCS 3.2.0) The WPCS native `SemicolonSpacing` sniff was only ever meant as a temporary solution to get round a bug in the upstream sniff. The bugfix was merged in PHPCS 3.2.0, so we as the minimum PHPCS requirement has gone up to beyond that now, we can defer to the upstream sniff instead. Note: Deprecating the WPCS version of the sniff and letting it extend the upstream version and throwing a deprecation message would be useless in this case, as: * When doing so, the error codes for the normal messages would not change, so people would not be able to update their custom rulesets and/or inline annotations. * If both sniffs - the WPCS one and the PHPCS version - would be included in the ruleset, we'd need to silence the error codes from one or the other to prevent duplicate messages from being thrown. - If we'd silence the PHPCS messages, the net effect would be the same as just keeping the WPCS sniff and people would still not be able to adjust their rulesets/annotations. - If we'd silence the WPCS messages, the net effect would be the same as this PR minus the deprecation message. So, as this will be going into a major release anyway, we may as well get the change over with. Note: this is a BC-break for anyone using a custom ruleset or PHPCS annotations referencing the previously included sniff. Refs: * 1163 * squizlabs/PHP_CodeSniffer 1690 * squizlabs/PHP_CodeSniffer 1691 --- WordPress-Core/ruleset.xml | 5 +- .../WhiteSpace/SemicolonSpacingSniff.php | 66 ------------------- .../WhiteSpace/SemicolonSpacingUnitTest.inc | 12 ---- .../SemicolonSpacingUnitTest.inc.fixed | 12 ---- .../WhiteSpace/SemicolonSpacingUnitTest.php | 46 ------------- 5 files changed, 1 insertion(+), 140 deletions(-) delete mode 100644 WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php delete mode 100644 WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.inc delete mode 100644 WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.inc.fixed delete mode 100644 WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.php diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index 99483c11c6..262c64eef8 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -456,10 +456,7 @@ - - + diff --git a/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php deleted file mode 100644 index d4a4ce787f..0000000000 --- a/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php +++ /dev/null @@ -1,66 +0,0 @@ -getTokens(); - - // Don't examine semi-colons for empty conditions in `for()` control structures. - if ( isset( $tokens[ $stackPtr ]['nested_parenthesis'] ) ) { - $nested_parenthesis = $tokens[ $stackPtr ]['nested_parenthesis']; - $close_parenthesis = end( $nested_parenthesis ); - - if ( isset( $tokens[ $close_parenthesis ]['parenthesis_owner'] ) ) { - $owner = $tokens[ $close_parenthesis ]['parenthesis_owner']; - - if ( \T_FOR === $tokens[ $owner ]['code'] ) { - $previous = $phpcsFile->findPrevious( - Tokens::$emptyTokens, - ( $stackPtr - 1 ), - $tokens[ $owner ]['parenthesis_opener'], - true - ); - - if ( false !== $previous - && ( $previous === $tokens[ $owner ]['parenthesis_opener'] - || \T_SEMICOLON === $tokens[ $previous ]['code'] ) - ) { - return; - } - } - } - } - - return parent::process( $phpcsFile, $stackPtr ); - } - -} diff --git a/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.inc b/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.inc deleted file mode 100644 index ec7f406707..0000000000 --- a/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.inc +++ /dev/null @@ -1,12 +0,0 @@ -= 0; $ptr-- ) {} -for ( ; ; ) {} - -// But it should when the whitespace is between a condition and a semi-colon. -for ( $i = 1 ; ; $i++ ) {} diff --git a/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.inc.fixed b/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.inc.fixed deleted file mode 100644 index 0a0820f150..0000000000 --- a/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.inc.fixed +++ /dev/null @@ -1,12 +0,0 @@ -= 0; $ptr-- ) {} -for ( ; ; ) {} - -// But it should when the whitespace is between a condition and a semi-colon. -for ( $i = 1; ; $i++ ) {} diff --git a/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.php deleted file mode 100644 index 1078620c1c..0000000000 --- a/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.php +++ /dev/null @@ -1,46 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 12 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array(); - } - -} From 90963b862cfe51d0d286194a3286cf74a8cd21df Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 17 Dec 2018 02:05:08 +0100 Subject: [PATCH 038/241] Sniff::has_whitelist_comment(): Deprecate use of the WPCS native whitelist comments (PHPCS 3.2.0) The WPCS native whitelist comments were introduced for lack of the ability to selectively ignore one or more sniffs for a piece of code. PHPCS 3.2.0 introduced native PHPCS annotations which allow for selective ignoring/disabling of sniffs and while those were originally a bit buggy, all known bugs have been fixed since, making the WPCS native whitelist comments redundant. This commit deprecates the method within WPCS which is used to check for the WPCS native whitelist comments. It also introduces a warning which will be thrown whenever a WPCS native whitelist comment is encountered to alert people to this change and encourage them to switch over to the PHPCS native annotations. Notes: * No deprecation notice will be thrown when a WPCS whitelist comment is combined with a PHPCS native annotation, i.e. `// phpcs:ignore WP.Security.EscapeOutput -- WPCS: XSS ok.` * As a sniff may be triggered several times for different tokens, a light weight (static) cache variable has been introduced to prevent the deprecation notice being thrown more than once for each WPCS whitelist comment encountered. The `Sniff::has_whitelist_comment()` method and all calls to it should be removed in WPCS 3.0.0. - [ ] References to the WPCS native whitelist comments need to be removed from the wiki and/or replaced with an upgrade guide. - [ ] Open an issue about removing the `Sniff::has_whitelist_comment()` method and calls to it in WPCS 3.0.0. Note: all unit tests testing that the WPCS native whitelist comments are being respected should also be removed at that time. Or alternatively, they can remain and it should be verified that the WPCS native whitelist comment makes no difference anymore. Refs: * squizlabs/PHP_CodeSniffer 604 --- .github/CONTRIBUTING.md | 35 ++--------------------------------- WordPress/Sniff.php | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index d763055c2b..babd323861 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -37,40 +37,9 @@ When you introduce new `public` sniff properties, or your sniff extends a class > **Important**: > PHPCS 3.2.0 introduced new selective ignore annotations, which can be considered an improved version of the whitelist mechanism which WPCS contains. > -> There is a [tentative intention to drop support for the WPCS native whitelist comments](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1048#issuecomment-340698249) in WPCS 2.0.0. -> -> Considering that, the introduction of new whitelist comments is discouraged. +> Support for the WPCS native whitelist comments has been deprecated in WPCS 2.0.0 and will be removed in WPCS 3.0.0. > -> The below information remains as guidance for exceptional cases and to aid in understanding the previous implementation. - -Sometimes, a sniff will flag code which upon further inspection by a human turns out to be OK. - -If the sniff you are writing is susceptible to this, please consider adding the ability to [whitelist lines of code](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Whitelisting-code-which-flags-errors). - -To this end, the `WordPress\Sniff::has_whitelist_comment()` method was introduced. - -Example usage: -```php -namespace WordPressCS\WordPress\Sniffs\Security; - -use WordPressCS\WordPress\Sniff; - -class NonceVerificationSniff extends Sniff { - - public function process_token( $stackPtr ) { - - // Check something. - - if ( $this->has_whitelist_comment( 'CSRF', $stackPtr ) ) { - return; - } - - $this->phpcsFile->addError( ... ); - } -} -``` - -When you introduce a new whitelist comment, please don't forget to update the [whitelisting code wiki page](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Whitelisting-code-which-flags-errors) with the relevant details once your PR has been merged into the `develop` branch. +> With that in mind, (new) sniffs should not introduce new WPCS native whitelist comments. # Unit Testing diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 75917a2c25..141f285b0e 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1066,6 +1066,8 @@ protected function get_wp_version_from_cl() { * @since 0.4.0 * @since 0.14.0 Whitelist comments at the end of the statement are now also accepted. * + * @deprecated 2.0.0 Use the PHPCS native `phpcs:ignore` annotations instead. + * * @param string $comment Comment to find. * @param integer $stackPtr The position of the current token in the stack passed * in $tokens. @@ -1079,6 +1081,12 @@ protected function has_whitelist_comment( $comment, $stackPtr ) { return false; } + static $thrown_notices = array(); + + $deprecation_notice = 'Using the WPCS native whitelist comments is deprecated. Please use the PHPCS native "phpcs:ignore Standard.Category.SniffName.ErrorCode" annotations instead. Found: %s'; + $deprecation_code = 'DeprecatedWhitelistCommentFound'; + $filename = $this->phpcsFile->getFileName(); + $regex = '#\b' . preg_quote( $comment, '#' ) . '\b#i'; // There is a findEndOfStatement() method, but it considers more tokens than @@ -1101,6 +1109,19 @@ protected function has_whitelist_comment( $comment, $stackPtr ) { && $this->tokens[ $lastPtr ]['line'] === $this->tokens[ $end_of_statement ]['line'] && preg_match( $regex, $this->tokens[ $lastPtr ]['content'] ) === 1 ) { + if ( isset( $thrown_notices[ $filename ][ $lastPtr ] ) === false + && isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ]['code'] ] ) === false + ) { + $this->phpcsFile->addWarning( + $deprecation_notice, + $lastPtr, + $deprecation_code, + array( $this->tokens[ $lastPtr ]['content'] ) + ); + + $thrown_notices[ $filename ][ $lastPtr ] = true; + } + return true; } } @@ -1117,6 +1138,19 @@ protected function has_whitelist_comment( $comment, $stackPtr ) { && $this->tokens[ $lastPtr ]['line'] === $this->tokens[ $stackPtr ]['line'] && preg_match( $regex, $this->tokens[ $lastPtr ]['content'] ) === 1 ) { + if ( isset( $thrown_notices[ $filename ][ $lastPtr ] ) === false + && isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ]['code'] ] ) === false + ) { + $this->phpcsFile->addWarning( + $deprecation_notice, + $lastPtr, + $deprecation_code, + array( $this->tokens[ $lastPtr ]['content'] ) + ); + + $thrown_notices[ $filename ][ $lastPtr ] = true; + } + return true; } From 18c6c7e6551adbeaba91db6ea3e6ef809143142b Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 17 Dec 2018 02:06:43 +0100 Subject: [PATCH 039/241] WPCS native PHPCS ruleset: ignore a whitelist deprecation notice The deprecation notice in this case is actually a false positive, however as the WPCS native whitelisting is now deprecated, fixing that false positive is a moot point. --- .phpcs.xml.dist | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 504fdf6c44..fd5ccc1510 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -46,4 +46,10 @@ + + + /WordPress/AbstractClassRestrictionsSniff\.php$ + + From a6dfef615bc9d852e3786302529ba9ea123961c5 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 17 Dec 2018 02:09:34 +0100 Subject: [PATCH 040/241] SlowDBQuery: remove the warning about the deprecated `tax_query` whitelist comment As the whole WPCS whitelist comment system is now deprecated, a notice will be thrown about that comment already. No need to also throw one about the comment using an old whitelist comment. --- WordPress/Sniffs/DB/SlowDBQuerySniff.php | 16 +--------------- WordPress/Tests/DB/SlowDBQueryUnitTest.php | 2 +- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/WordPress/Sniffs/DB/SlowDBQuerySniff.php b/WordPress/Sniffs/DB/SlowDBQuerySniff.php index 6935aae40c..d0e547d4a7 100644 --- a/WordPress/Sniffs/DB/SlowDBQuerySniff.php +++ b/WordPress/Sniffs/DB/SlowDBQuerySniff.php @@ -61,21 +61,7 @@ public function process_token( $stackPtr ) { if ( $this->has_whitelist_comment( 'slow query', $stackPtr ) ) { return; - } - - if ( $this->has_whitelist_comment( 'tax_query', $stackPtr ) ) { - /* - * Only throw the warning about a deprecated comment when the sniff would otherwise - * have been triggered on the array key. - */ - if ( \in_array( $this->tokens[ $stackPtr ]['code'], array( \T_CONSTANT_ENCAPSED_STRING, \T_DOUBLE_QUOTED_STRING ), true ) ) { - $this->phpcsFile->addWarning( - 'The "tax_query" whitelist comment is deprecated in favor of the "slow query" whitelist comment.', - $stackPtr, - 'DeprecatedWhitelistFlagFound' - ); - } - + } elseif ( $this->has_whitelist_comment( 'tax_query', $stackPtr ) ) { return; } diff --git a/WordPress/Tests/DB/SlowDBQueryUnitTest.php b/WordPress/Tests/DB/SlowDBQueryUnitTest.php index 2c0d64d2ef..6cc4a5763b 100644 --- a/WordPress/Tests/DB/SlowDBQueryUnitTest.php +++ b/WordPress/Tests/DB/SlowDBQueryUnitTest.php @@ -44,7 +44,7 @@ public function getWarningList() { 16 => 1, 19 => 2, 30 => 1, - 32 => 1, // Warning about deprecated whitelist comment. + 32 => 1, // Whitelist comment deprecation warning. ); } From bc44bf6145cdd88581e558e7ab0890a7718178ea Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 17 Dec 2018 02:11:45 +0100 Subject: [PATCH 041/241] Unit tests: account for the new WPCS whitelist comment deprecation notices A number of unit test case files contain WPCS whitelist comments to test that those are correctly being respected. As of now, a deprecation warning for use of the WPCS whitelist comments will be thrown on those lines, so we need to make sure that PHPCS expects those warnings. --- .../Tests/DB/PreparedSQLPlaceholdersUnitTest.php | 2 ++ WordPress/Tests/DB/PreparedSQLUnitTest.php | 7 ++++++- WordPress/Tests/DB/SlowDBQueryUnitTest.php | 2 ++ .../NamingConventions/PrefixAllGlobalsUnitTest.php | 5 +++++ WordPress/Tests/PHP/StrictComparisonsUnitTest.php | 1 + WordPress/Tests/Security/EscapeOutputUnitTest.php | 9 ++++++++- .../Tests/Security/NonceVerificationUnitTest.php | 4 +++- .../Security/ValidatedSanitizedInputUnitTest.php | 4 +++- WordPress/Tests/WP/CapitalPDangitUnitTest.php | 1 + .../Tests/WP/GlobalVariablesOverrideUnitTest.php | 14 ++++++++++++-- .../WhiteSpace/PrecisionAlignmentUnitTest.php | 1 + 11 files changed, 44 insertions(+), 6 deletions(-) diff --git a/WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php b/WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php index 87a35ea00a..3259bb0b5c 100644 --- a/WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php +++ b/WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php @@ -85,7 +85,9 @@ public function getWarningList() { 57 => 1, 58 => 1, 61 => 1, + 62 => 1, // Whitelist comment deprecation warning. 66 => 1, + 68 => 1, // Whitelist comment deprecation warning. 126 => 1, 139 => 1, 160 => 2, diff --git a/WordPress/Tests/DB/PreparedSQLUnitTest.php b/WordPress/Tests/DB/PreparedSQLUnitTest.php index d0ef7ec47d..f525dde0e6 100644 --- a/WordPress/Tests/DB/PreparedSQLUnitTest.php +++ b/WordPress/Tests/DB/PreparedSQLUnitTest.php @@ -57,7 +57,12 @@ public function getErrorList() { * @return array => */ public function getWarningList() { - return array(); + return array( + 11 => 1, // Whitelist comment deprecation warning. + 12 => 1, // Whitelist comment deprecation warning. + 97 => 1, // Whitelist comment deprecation warning. + 99 => 1, // Whitelist comment deprecation warning. + ); } } diff --git a/WordPress/Tests/DB/SlowDBQueryUnitTest.php b/WordPress/Tests/DB/SlowDBQueryUnitTest.php index 6cc4a5763b..24af5c213d 100644 --- a/WordPress/Tests/DB/SlowDBQueryUnitTest.php +++ b/WordPress/Tests/DB/SlowDBQueryUnitTest.php @@ -44,7 +44,9 @@ public function getWarningList() { 16 => 1, 19 => 2, 30 => 1, + 31 => 1, // Whitelist comment deprecation warning. 32 => 1, // Whitelist comment deprecation warning. + 35 => 1, // Whitelist comment deprecation warning. ); } diff --git a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php index 80a4872014..6db20b24ae 100644 --- a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php +++ b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php @@ -99,6 +99,11 @@ public function getWarningList( $testFile = 'PrefixAllGlobalsUnitTest.1.inc' ) { case 'PrefixAllGlobalsUnitTest.1.inc': return array( 1 => 3, // 3 x warning for potentially incorrect prefix passed. + 201 => 1, // Whitelist comment deprecation warning. + 208 => 1, // Whitelist comment deprecation warning. + 212 => 1, // Whitelist comment deprecation warning. + 215 => 1, // Whitelist comment deprecation warning. + 216 => 1, // Whitelist comment deprecation warning. 249 => 1, 250 => 1, 253 => 1, diff --git a/WordPress/Tests/PHP/StrictComparisonsUnitTest.php b/WordPress/Tests/PHP/StrictComparisonsUnitTest.php index 2f4c95d19c..79a42f6991 100644 --- a/WordPress/Tests/PHP/StrictComparisonsUnitTest.php +++ b/WordPress/Tests/PHP/StrictComparisonsUnitTest.php @@ -40,6 +40,7 @@ public function getWarningList() { 3 => 1, 10 => 1, 12 => 1, + 19 => 1, // Whitelist comment deprecation warning. 24 => 1, 29 => 1, ); diff --git a/WordPress/Tests/Security/EscapeOutputUnitTest.php b/WordPress/Tests/Security/EscapeOutputUnitTest.php index 91a97215dc..6fc0837e54 100644 --- a/WordPress/Tests/Security/EscapeOutputUnitTest.php +++ b/WordPress/Tests/Security/EscapeOutputUnitTest.php @@ -88,7 +88,14 @@ public function getErrorList() { * @return array => */ public function getWarningList() { - return array(); + return array( + 126 => 1, // Whitelist comment deprecation warning. + 127 => 1, // Whitelist comment deprecation warning. + 128 => 1, // Whitelist comment deprecation warning. + 241 => 1, // Whitelist comment deprecation warning. + 243 => 1, // Whitelist comment deprecation warning. + 250 => 1, // Whitelist comment deprecation warning. + ); } } diff --git a/WordPress/Tests/Security/NonceVerificationUnitTest.php b/WordPress/Tests/Security/NonceVerificationUnitTest.php index a7935c9557..d937edb1e9 100644 --- a/WordPress/Tests/Security/NonceVerificationUnitTest.php +++ b/WordPress/Tests/Security/NonceVerificationUnitTest.php @@ -55,7 +55,9 @@ public function getErrorList() { * @return array => */ public function getWarningList() { - return array(); + return array( + 88 => 1, // Whitelist comment deprecation warning. + ); } } diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php index 9eed79b4e8..02b7e9d4ae 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php @@ -63,7 +63,9 @@ public function getErrorList() { * @return array => */ public function getWarningList() { - return array(); + return array( + 76 => 1, // Whitelist comment deprecation warning. + ); } } diff --git a/WordPress/Tests/WP/CapitalPDangitUnitTest.php b/WordPress/Tests/WP/CapitalPDangitUnitTest.php index 494b03a72b..1139ee348e 100644 --- a/WordPress/Tests/WP/CapitalPDangitUnitTest.php +++ b/WordPress/Tests/WP/CapitalPDangitUnitTest.php @@ -59,6 +59,7 @@ public function getWarningList() { 101 => 1, 139 => 1, 146 => 0, // False negative. + 167 => 1, // Whitelist comment deprecation warning. 173 => 1, 181 => 1, ); diff --git a/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php b/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php index 9739e83258..0f77e278e0 100644 --- a/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php +++ b/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php @@ -85,10 +85,20 @@ public function getErrorList( $testFile = '' ) { /** * Returns the lines where warnings should occur. * + * @param string $testFile The name of the file being tested. + * * @return array => */ - public function getWarningList() { - return array(); + public function getWarningList( $testFile = '' ) { + switch ( $testFile ) { + case 'GlobalVariablesOverrideUnitTest.1.inc': + return array( + 11 => 1, // Whitelist comment deprecation warning. + ); + + default: + return array(); + } } } diff --git a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php index 7b600c1729..a928640dc3 100644 --- a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php +++ b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php @@ -69,6 +69,7 @@ public function getWarningList( $testFile = '' ) { 30 => 1, 31 => 1, 32 => 1, + 34 => 1, // Whitelist comment deprecation warning. 39 => 1, 65 => 1, ); From dd7566023277912d4e8284d35cd5f939621a121d Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 16 Dec 2018 18:34:35 +0100 Subject: [PATCH 042/241] Core: Defer to upstream `Generic.WhiteSpace.ArbitraryParenthesesSpacing` sniff (PHPCS 3.3.0) PHPCS 3.3.0 includes the same `ArbitraryParenthesesSpacing` sniff as was previously pulled to WPCS. As the minimum PHPCS requirement has gone up to beyond 3.3.0 now, we can switch over to use the upstream version instead. Note: Deprecating the WPCS version of the sniff and letting it extend the upstream version and throwing a deprecation message would be useless in this case, as: * When doing so, the error codes for the normal messages would not change, so people would not be able to update their custom rulesets and/or inline annotations. * If both sniffs - the WPCS one and the PHPCS version - would be included in the ruleset, we'd need to silence the error codes from one or the other to prevent duplicate messages from being thrown. - If we'd silence the PHPCS messages, the net effect would be the same as just keeping the WPCS sniff and people would still not be able to adjust their rulesets/annotations. - If we'd silence the WPCS messages, the net effect would be the same as this PR minus the deprecation message. So, as this will be going into a major release anyway, we may as well get the change over with. Note: this is a BC-break for anyone using a custom ruleset or PHPCS annotations referencing the previously included sniff. Refs: * squizlabs/PHP_CodeSniffer 1701 --- WordPress-Core/ruleset.xml | 6 +- .../ArbitraryParenthesesSpacingSniff.php | 250 ------------------ .../ArbitraryParenthesesSpacingUnitTest.inc | 161 ----------- ...itraryParenthesesSpacingUnitTest.inc.fixed | 149 ----------- .../ArbitraryParenthesesSpacingUnitTest.php | 75 ------ 5 files changed, 2 insertions(+), 639 deletions(-) delete mode 100644 WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php delete mode 100644 WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc delete mode 100644 WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed delete mode 100644 WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.php diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index 99483c11c6..26d183f164 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -260,11 +260,9 @@ - - + - + diff --git a/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php deleted file mode 100644 index 89c58ba60c..0000000000 --- a/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php +++ /dev/null @@ -1,250 +0,0 @@ -ignoreTokens = Tokens::$functionNameTokens; - $this->ignoreTokens[ \T_VARIABLE ] = \T_VARIABLE; - $this->ignoreTokens[ \T_CLOSE_PARENTHESIS ] = \T_CLOSE_PARENTHESIS; - $this->ignoreTokens[ \T_CLOSE_CURLY_BRACKET ] = \T_CLOSE_CURLY_BRACKET; - $this->ignoreTokens[ \T_CLOSE_SQUARE_BRACKET ] = \T_CLOSE_SQUARE_BRACKET; - $this->ignoreTokens[ \T_CLOSE_SHORT_ARRAY ] = \T_CLOSE_SHORT_ARRAY; - $this->ignoreTokens[ \T_ANON_CLASS ] = \T_ANON_CLASS; - $this->ignoreTokens[ \T_USE ] = \T_USE; - $this->ignoreTokens[ \T_LIST ] = \T_LIST; - $this->ignoreTokens[ \T_DECLARE ] = \T_DECLARE; - - // Language constructs where the use of parentheses should be discouraged instead. - $this->ignoreTokens[ \T_THROW ] = \T_THROW; - $this->ignoreTokens[ \T_YIELD ] = \T_YIELD; - $this->ignoreTokens[ \T_YIELD_FROM ] = \T_YIELD_FROM; - $this->ignoreTokens[ \T_CLONE ] = \T_CLONE; - - return array( - \T_OPEN_PARENTHESIS, - \T_CLOSE_PARENTHESIS, - ); - } - - /** - * Processes this test, when one of its tokens is encountered. - * - * @since 0.14.0 - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return int|void Integer stack pointer to skip forward or void to continue - * normal file processing. - */ - public function process_token( $stackPtr ) { - - if ( isset( $this->tokens[ $stackPtr ]['parenthesis_owner'] ) ) { - // This parenthesis is owned by a function/control structure etc. - return; - } - - // More checking for the type of parenthesis we *don't* want to handle. - $opener = $stackPtr; - if ( \T_CLOSE_PARENTHESIS === $this->tokens[ $stackPtr ]['code'] ) { - if ( ! isset( $this->tokens[ $stackPtr ]['parenthesis_opener'] ) ) { - // Parse error. - return; - } - - $opener = $this->tokens[ $stackPtr ]['parenthesis_opener']; - } - - $preOpener = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $opener - 1 ), null, true ); - if ( false !== $preOpener && isset( $this->ignoreTokens[ $this->tokens[ $preOpener ]['code'] ] ) ) { - // Function or language construct call. - return; - } - - /* - * Check for empty parentheses. - */ - if ( \T_OPEN_PARENTHESIS === $this->tokens[ $stackPtr ]['code'] - && isset( $this->tokens[ $stackPtr ]['parenthesis_closer'] ) - ) { - $nextNonEmpty = $this->phpcsFile->findNext( \T_WHITESPACE, ( $stackPtr + 1 ), null, true ); - if ( $nextNonEmpty === $this->tokens[ $stackPtr ]['parenthesis_closer'] ) { - $this->phpcsFile->addWarning( 'Empty set of arbitrary parentheses found.', $stackPtr, 'FoundEmpty' ); - - return ( $this->tokens[ $stackPtr ]['parenthesis_closer'] + 1 ); - } - } - - /* - * Check the spacing on the inside of the parentheses. - */ - $this->spacingInside = (int) $this->spacingInside; - - if ( \T_OPEN_PARENTHESIS === $this->tokens[ $stackPtr ]['code'] - && isset( $this->tokens[ ( $stackPtr + 1 ) ], $this->tokens[ ( $stackPtr + 2 ) ] ) - ) { - $nextToken = $this->tokens[ ( $stackPtr + 1 ) ]; - - if ( \T_WHITESPACE !== $nextToken['code'] ) { - $inside = 0; - } else { - if ( $this->tokens[ ( $stackPtr + 2 ) ]['line'] !== $this->tokens[ $stackPtr ]['line'] ) { - $inside = 'newline'; - } else { - $inside = $nextToken['length']; - } - } - - if ( $this->spacingInside !== $inside - && ( 'newline' !== $inside || false === $this->ignoreNewlines ) - ) { - $error = 'Expected %s space after open parenthesis; %s found'; - $data = array( - $this->spacingInside, - $inside, - ); - $fix = $this->phpcsFile->addFixableError( $error, $stackPtr, 'SpaceAfterOpen', $data ); - - if ( true === $fix ) { - $expected = ''; - if ( $this->spacingInside > 0 ) { - $expected = str_repeat( ' ', $this->spacingInside ); - } - - if ( 0 === $inside ) { - if ( '' !== $expected ) { - $this->phpcsFile->fixer->addContent( $stackPtr, $expected ); - } - } elseif ( 'newline' === $inside ) { - $this->phpcsFile->fixer->beginChangeset(); - for ( $i = ( $stackPtr + 2 ); $i < $this->phpcsFile->numTokens; $i++ ) { - if ( \T_WHITESPACE !== $this->tokens[ $i ]['code'] ) { - break; - } - $this->phpcsFile->fixer->replaceToken( $i, '' ); - } - $this->phpcsFile->fixer->replaceToken( ( $stackPtr + 1 ), $expected ); - $this->phpcsFile->fixer->endChangeset(); - } else { - $this->phpcsFile->fixer->replaceToken( ( $stackPtr + 1 ), $expected ); - } - } - } - } - - if ( \T_CLOSE_PARENTHESIS === $this->tokens[ $stackPtr ]['code'] - && isset( $this->tokens[ ( $stackPtr - 1 ) ], $this->tokens[ ( $stackPtr - 2 ) ] ) - ) { - $prevToken = $this->tokens[ ( $stackPtr - 1 ) ]; - - if ( \T_WHITESPACE !== $prevToken['code'] ) { - $inside = 0; - } else { - if ( $this->tokens[ ( $stackPtr - 2 ) ]['line'] !== $this->tokens[ $stackPtr ]['line'] ) { - $inside = 'newline'; - } else { - $inside = $prevToken['length']; - } - } - - if ( $this->spacingInside !== $inside - && ( 'newline' !== $inside || false === $this->ignoreNewlines ) - ) { - $error = 'Expected %s space before close parenthesis; %s found'; - $data = array( - $this->spacingInside, - $inside, - ); - $fix = $this->phpcsFile->addFixableError( $error, $stackPtr, 'SpaceBeforeClose', $data ); - - if ( true === $fix ) { - $expected = ''; - if ( $this->spacingInside > 0 ) { - $expected = str_repeat( ' ', $this->spacingInside ); - } - - if ( 0 === $inside ) { - if ( '' !== $expected ) { - $this->phpcsFile->fixer->addContentBefore( $stackPtr, $expected ); - } - } elseif ( 'newline' === $inside ) { - $this->phpcsFile->fixer->beginChangeset(); - for ( $i = ( $stackPtr - 2 ); $i > 0; $i-- ) { - if ( \T_WHITESPACE !== $this->tokens[ $i ]['code'] ) { - break; - } - $this->phpcsFile->fixer->replaceToken( $i, '' ); - } - $this->phpcsFile->fixer->replaceToken( ( $stackPtr - 1 ), $expected ); - $this->phpcsFile->fixer->endChangeset(); - } else { - $this->phpcsFile->fixer->replaceToken( ( $stackPtr - 1 ), $expected ); - } - } - } - } - } - -} diff --git a/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc b/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc deleted file mode 100644 index 7ec5d639e8..0000000000 --- a/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc +++ /dev/null @@ -1,161 +0,0 @@ -{$var}( $foo,$bar ); - -(function( $a, $b ) { - return function( $c, $d ) use ( $a, $b ) { - echo $a, $b, $c, $d; - }; -})( 'a','b' )( 'c','d' ); - -$closure( $foo,$bar ); -$var = $closure() + $closure( $foo,$bar ) + self::$closure( $foo,$bar ); - -class Test { - public static function baz( $foo, $bar ) { - $a = new self( $foo,$bar ); - $b = new static( $foo,$bar ); - } -} - -/* - * Test warning for empty parentheses. - */ -$a = 4 + (); // Warning. -$a = 4 + ( ); // Warning. -$a = 4 + (/* Not empty */); - -/* - * Test the actual sniff. - */ -if ((null !== $extra) && ($row->extra !== $extra)) {} - -if (( null !== $extra ) && ( $row->extra !== $extra )) {} // Bad x 4. - -if (( null !== $extra // Bad x 1. - && is_int($extra)) - && ( $row->extra !== $extra // Bad x 1. - || $something ) // Bad x 1. -) {} - -if (( null !== $extra ) // Bad x 2. - && ( $row->extra !== $extra ) // Bad x 2. -) {} - -$a = (null !== $extra); -$a = ( null !== $extra ); // Bad x 2. - -$sx = $vert ? ($w - 1) : 0; - -$this->is_overloaded = ( ( ini_get("mbstring.func_overload") & 2 ) != 0 ) && function_exists('mb_substr'); // Bad x 4. - -$image->flip( ($operation->axis & 1) != 0, ($operation->axis & 2) != 0 ); - -if ( $success && ('nothumb' == $target || 'all' == $target) ) {} - -$directory = ('/' == $file[ strlen($file)-1 ]); - -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 1 -if ((null !== $extra) && ($row->extra !== $extra)) {} // Bad x 4. - -if (( null !== $extra ) && ( $row->extra !== $extra )) {} - -if (( null !== $extra // Bad x 1. - && is_int($extra)) // Bad x 1. - && ( $row->extra !== $extra - || $something ) // Bad x 1. -) {} - -if ((null !== $extra) // Bad x 2. - && ($row->extra !== $extra) // Bad x 2. -) {} - -$a = (null !== $extra); // Bad x 2. -$a = ( null !== $extra ); - -$sx = $vert ? ($w - 1) : 0; // Bad x 2. - -$this->is_overloaded = ((ini_get("mbstring.func_overload") & 2) != 0) && function_exists('mb_substr'); // Bad x 4. - -$image->flip( ($operation->axis & 1) != 0, ($operation->axis & 2) != 0 ); // Bad x 4. - -if ( $success && ('nothumb' == $target || 'all' == $target) ) {} // Bad x 2. - -$directory = ('/' == $file[ strlen($file)-1 ]); // Bad x 2. - -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 - -/* - * Test handling of ignoreNewlines. - */ -if ( - ( - null !== $extra - ) && ( - $row->extra !== $extra - ) -) {} // Bad x 4, 1 x line 123, 2 x line 125, 1 x line 127. - - -$a = ( - null !== $extra -); // Bad x 2, 1 x line 131, 1 x line 133. - -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 1 -if ( - ( - null !== $extra - ) && ( - $row->extra !== $extra - ) -) {} // Bad x 4, 1 x line 137, 2 x line 139, 1 x line 141. - -$a = ( - null !== $extra -); // Bad x 2, 1 x line 144, 1 x line 146. -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 - -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines true -if ( - ( - null !== $extra - ) && ( - $row->extra !== $extra - ) -) {} - -$a = ( - null !== $extra -); -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines false diff --git a/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed b/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed deleted file mode 100644 index c75771237c..0000000000 --- a/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed +++ /dev/null @@ -1,149 +0,0 @@ -{$var}( $foo,$bar ); - -(function( $a, $b ) { - return function( $c, $d ) use ( $a, $b ) { - echo $a, $b, $c, $d; - }; -})( 'a','b' )( 'c','d' ); - -$closure( $foo,$bar ); -$var = $closure() + $closure( $foo,$bar ) + self::$closure( $foo,$bar ); - -class Test { - public static function baz( $foo, $bar ) { - $a = new self( $foo,$bar ); - $b = new static( $foo,$bar ); - } -} - -/* - * Test warning for empty parentheses. - */ -$a = 4 + (); // Warning. -$a = 4 + ( ); // Warning. -$a = 4 + (/* Not empty */); - -/* - * Test the actual sniff. - */ -if ((null !== $extra) && ($row->extra !== $extra)) {} - -if ((null !== $extra) && ($row->extra !== $extra)) {} // Bad x 4. - -if ((null !== $extra // Bad x 1. - && is_int($extra)) - && ($row->extra !== $extra // Bad x 1. - || $something) // Bad x 1. -) {} - -if ((null !== $extra) // Bad x 2. - && ($row->extra !== $extra) // Bad x 2. -) {} - -$a = (null !== $extra); -$a = (null !== $extra); // Bad x 2. - -$sx = $vert ? ($w - 1) : 0; - -$this->is_overloaded = ((ini_get("mbstring.func_overload") & 2) != 0) && function_exists('mb_substr'); // Bad x 4. - -$image->flip( ($operation->axis & 1) != 0, ($operation->axis & 2) != 0 ); - -if ( $success && ('nothumb' == $target || 'all' == $target) ) {} - -$directory = ('/' == $file[ strlen($file)-1 ]); - -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 1 -if (( null !== $extra ) && ( $row->extra !== $extra )) {} // Bad x 4. - -if (( null !== $extra ) && ( $row->extra !== $extra )) {} - -if (( null !== $extra // Bad x 1. - && is_int($extra) ) // Bad x 1. - && ( $row->extra !== $extra - || $something ) // Bad x 1. -) {} - -if (( null !== $extra ) // Bad x 2. - && ( $row->extra !== $extra ) // Bad x 2. -) {} - -$a = ( null !== $extra ); // Bad x 2. -$a = ( null !== $extra ); - -$sx = $vert ? ( $w - 1 ) : 0; // Bad x 2. - -$this->is_overloaded = ( ( ini_get("mbstring.func_overload") & 2 ) != 0 ) && function_exists('mb_substr'); // Bad x 4. - -$image->flip( ( $operation->axis & 1 ) != 0, ( $operation->axis & 2 ) != 0 ); // Bad x 4. - -if ( $success && ( 'nothumb' == $target || 'all' == $target ) ) {} // Bad x 2. - -$directory = ( '/' == $file[ strlen($file)-1 ] ); // Bad x 2. - -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 - -/* - * Test handling of ignoreNewlines. - */ -if ( - (null !== $extra) && ($row->extra !== $extra) -) {} // Bad x 4, 1 x line 123, 2 x line 125, 1 x line 127. - - -$a = (null !== $extra); // Bad x 2, 1 x line 131, 1 x line 133. - -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 1 -if ( - ( null !== $extra ) && ( $row->extra !== $extra ) -) {} // Bad x 4, 1 x line 137, 2 x line 139, 1 x line 141. - -$a = ( null !== $extra ); // Bad x 2, 1 x line 144, 1 x line 146. -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 - -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines true -if ( - ( - null !== $extra - ) && ( - $row->extra !== $extra - ) -) {} - -$a = ( - null !== $extra -); -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines false diff --git a/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.php deleted file mode 100644 index e2c3ef9218..0000000000 --- a/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.php +++ /dev/null @@ -1,75 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 64 => 4, - 66 => 1, - 68 => 1, - 69 => 1, - 72 => 2, - 73 => 2, - 77 => 2, - 81 => 4, - 90 => 4, - 94 => 1, - 95 => 1, - 97 => 1, - 100 => 2, - 101 => 2, - 104 => 2, - 107 => 2, - 109 => 4, - 111 => 4, - 113 => 2, - 115 => 2, - 123 => 1, - 125 => 2, - 127 => 1, - 131 => 1, - 133 => 1, - 137 => 1, - 139 => 2, - 141 => 1, - 144 => 1, - 146 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 55 => 1, - 56 => 1, - ); - } - -} From ac5c1a88a2fadfef033e1512c9b14f56e1e54f12 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 17 Dec 2018 03:17:29 +0100 Subject: [PATCH 043/241] Core: Defer to upstream `Generic.PHP.LowerCaseType` sniff (PHPCS 3.3.0) PHPCS 3.3.0 includes a new `Generic.PHP.LowerCaseType` sniff which has some overlap with the WPCS native `WordPress.PHP.TypeCasts` sniff. The native `WordPress.PHP.TypeCasts`, which was introduced in WPCS 1.2.0, checked: * Whether the correct form (short & normalized) of type casts is used. * Whether the type cast is lowercase. * Discourages the use of the `(unset)` and `(binary)` casts. The upstream `Generic.PHP.LowerCaseType` sniff checks: * Whether a type cast is lowercase. * Whether the type of a (non-object) parameter type declarations is lowercase. * Whether the type of a (non-object) return type declaration is lowerase. In this PR, I'm removing the "lowercase" check from the WPCS `WordPress.PHP.TypeCasts` sniff in favour of including the upstream sniff. This does mean that the case of parameter and return type declaration will now also be checked. As having those be lowercase would be consistent with the existing WP rules regarding type casts and other PHP keywords being lowercase, as well as be consistent with PSR-12, I believe this is an acceptable addition. Note: this is a BC-break for anyone using a custom ruleset or PHPCS annotations referencing the previous WPCS native errorcode for the lowercase check. Refs: * 1483 * https://github.com/squizlabs/PHP_CodeSniffer/commit/5a989395a4318475590c6515512f17e2b8e4df8f * squizlabs/PHP_CodeSniffer 2023 --- WordPress-Core/ruleset.xml | 2 ++ WordPress/Sniffs/PHP/TypeCastsSniff.php | 32 +++---------------- WordPress/Tests/PHP/TypeCastsUnitTest.inc | 28 ---------------- .../Tests/PHP/TypeCastsUnitTest.inc.fixed | 28 ---------------- WordPress/Tests/PHP/TypeCastsUnitTest.php | 32 ++----------------- 5 files changed, 8 insertions(+), 114 deletions(-) diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index 99483c11c6..5b75ee0c39 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -250,6 +250,8 @@ + + diff --git a/WordPress/Sniffs/PHP/TypeCastsSniff.php b/WordPress/Sniffs/PHP/TypeCastsSniff.php index 343ddf1785..166c0f5a1f 100644 --- a/WordPress/Sniffs/PHP/TypeCastsSniff.php +++ b/WordPress/Sniffs/PHP/TypeCastsSniff.php @@ -36,7 +36,10 @@ class TypeCastsSniff extends Sniff { * @return array */ public function register() { - return Tokens::$castTokens; + $targets = Tokens::$castTokens; + unset( $targets[ \T_ARRAY_CAST ], $targets[ \T_OBJECT_CAST ] ); + + return $targets; } /** @@ -122,33 +125,6 @@ public function process_token( $stackPtr ) { ); break; } - - /* - * {@internal Once the minimum PHPCS version has gone up to PHPCS 3.3.0+, the lowercase - * check below can be removed in favour of adding the `Generic.PHP.LowerCaseType` sniff - * to the ruleset. - * Note: the `register()` function also needs adjusting in that case to only register the - * targetted type casts above and the metrics recording should probably be adjusted as well. - * The above mentioned Generic sniff records metrics about the case of typecasts, so we - * don't need to worry about those no longer being recorded. They will be, just slightly - * differently.}} - */ - if ( $typecast_lc !== $typecast ) { - $data = array( - $typecast_lc, - $typecast, - ); - - $fix = $this->phpcsFile->addFixableError( - 'PHP type casts must be lowercase; expected "%s" but found "%s"', - $stackPtr, - 'NonLowercaseFound', - $data - ); - if ( true === $fix ) { - $this->phpcsFile->fixer->replaceToken( $stackPtr, $typecast_lc ); - } - } } } diff --git a/WordPress/Tests/PHP/TypeCastsUnitTest.inc b/WordPress/Tests/PHP/TypeCastsUnitTest.inc index a69c06b379..8d0fd9e74f 100644 --- a/WordPress/Tests/PHP/TypeCastsUnitTest.inc +++ b/WordPress/Tests/PHP/TypeCastsUnitTest.inc @@ -20,34 +20,6 @@ $a = (binary) $b; // Warning. $a = b"binary string"; // Warning. $a = b"binary $string"; // Warning. -// Error: Mixed case. -$a = (Bool) $b; -$a = (Boolean) $b; // + wrong form. -$a = (Int) $b; -$a = (Integer) $b; // + wrong form. -$a = (Float) $b; -$a = (Double) $b; // + wrong form. -$a = (Real) $b; // + wrong form. -$a = (String) $b; -$a = (Array) $b; -$a = (Object) $b; -$a = (Unset) $b; // + discouraged. -$a = (Binary) $b; // + discouraged. - -// Error: Uppercase. -$a = (BOOL) $b; -$a = (BOOLEAN) $b; // + wrong form. -$a = (INT) $b; -$a = (INTEGER) $b; // + wrong form. -$a = (FLOAT) $b; -$a = (DOUBLE) $b; // + wrong form. -$a = (REAL) $b; // + wrong form. -$a = (STRING) $b; -$a = (ARRAY) $b; -$a = (OBJECT) $b; -$a = (UNSET) $b; // + discouraged. -$a = (BINARY) $b; // + discouraged. - // Test recognition with whitespace within the cast. // OK. $a = ( bool ) $b; diff --git a/WordPress/Tests/PHP/TypeCastsUnitTest.inc.fixed b/WordPress/Tests/PHP/TypeCastsUnitTest.inc.fixed index 076ed30bd2..3ce98e66cf 100644 --- a/WordPress/Tests/PHP/TypeCastsUnitTest.inc.fixed +++ b/WordPress/Tests/PHP/TypeCastsUnitTest.inc.fixed @@ -20,34 +20,6 @@ $a = (binary) $b; // Warning. $a = b"binary string"; // Warning. $a = b"binary $string"; // Warning. -// Error: Mixed case. -$a = (bool) $b; -$a = (bool) $b; // + wrong form. -$a = (int) $b; -$a = (int) $b; // + wrong form. -$a = (float) $b; -$a = (float) $b; // + wrong form. -$a = (float) $b; // + wrong form. -$a = (string) $b; -$a = (array) $b; -$a = (object) $b; -$a = (unset) $b; // + discouraged. -$a = (binary) $b; // + discouraged. - -// Error: Uppercase. -$a = (bool) $b; -$a = (bool) $b; // + wrong form. -$a = (int) $b; -$a = (int) $b; // + wrong form. -$a = (float) $b; -$a = (float) $b; // + wrong form. -$a = (float) $b; // + wrong form. -$a = (string) $b; -$a = (array) $b; -$a = (object) $b; -$a = (unset) $b; // + discouraged. -$a = (binary) $b; // + discouraged. - // Test recognition with whitespace within the cast. // OK. $a = ( bool ) $b; diff --git a/WordPress/Tests/PHP/TypeCastsUnitTest.php b/WordPress/Tests/PHP/TypeCastsUnitTest.php index cdd88bbb68..11aa665c2b 100644 --- a/WordPress/Tests/PHP/TypeCastsUnitTest.php +++ b/WordPress/Tests/PHP/TypeCastsUnitTest.php @@ -32,34 +32,10 @@ public function getErrorList() { 13 => 1, 14 => 1, 15 => 1, - 24 => 1, - 25 => 2, - 26 => 1, - 27 => 2, - 28 => 1, - 29 => 2, - 30 => 2, - 31 => 1, 32 => 1, 33 => 1, 34 => 1, 35 => 1, - 38 => 1, - 39 => 2, - 40 => 1, - 41 => 2, - 42 => 1, - 43 => 2, - 44 => 2, - 45 => 1, - 46 => 1, - 47 => 1, - 48 => 1, - 49 => 1, - 60 => 1, - 61 => 1, - 62 => 1, - 63 => 1, ); } @@ -74,12 +50,8 @@ public function getWarningList() { 19 => 1, 20 => ( version_compare( PHPCSHelper::get_version(), '3.4.0', '<' ) === true ? 0 : 1 ), 21 => 1, - 34 => 1, - 35 => 1, - 48 => 1, - 49 => 1, - 64 => 1, - 65 => 1, + 36 => 1, + 37 => 1, ); } } From 645568859a85fcf1849226e3e6b01a8bad3593ea Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 17 Dec 2018 00:37:12 +0100 Subject: [PATCH 044/241] Sniff::merge_custom_array(): Remove support for incorrectly set custom array properties Array properties passed in from a custom ruleset need to have a `type="array"` attribute. Until now WPCS was lenient when this attribute was missing and would convert an array passed as a comma delimited string to an array. This functionality was deprecated for the only property which still "officially" allowed for a comma-delimited string list in WPCS 1.0.0 and will now be removed. The only exception are the two array properties which can also be set via the command-line, i.e. the `prefixes` property for the `WordPress.NamingConventions.PrefixAllGlobals` sniff and the `text_domain` property for the `WordPress.WP.I18n` sniff. If - and only if - these properties are set from the command-line, the sniffs will still convert the received string to an array. Refs: * 1390 This also removes the leniency for spaces surrounding array values. PHPCS 3.2.0 includes a similar fix as was previously made in PR 1185, which means that properties passed as arrays will already be trimmed, so no need to do it again. Refs: * 1185 * squizlabs/PHP_CodeSniffer 1689 --- WordPress/Sniff.php | 30 +++++++------------ .../PrefixAllGlobalsSniff.php | 2 +- WordPress/Sniffs/WP/I18nSniff.php | 2 +- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index f95829a866..8341e10def 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -943,10 +943,8 @@ protected function string_to_errorcode( $base_string ) { } /** - * Merge a pre-set array with a ruleset provided array or inline provided string. + * Merge a pre-set array with a ruleset provided array. * - * - Will correctly handle custom array properties which were set without - * the `type="array"` indicator. * - By default flips custom lists to allow for using `isset()` instead * of `in_array()`. * - When `$flip` is true: @@ -961,14 +959,14 @@ protected function string_to_errorcode( $base_string ) { * which extends an upstream sniff can also use it.}} * * @since 0.11.0 - * - * @param array|string $custom Custom list as provided via a ruleset. - * Can be either a comma-delimited string or - * an array of values. - * @param array $base Optional. Base list. Defaults to an empty array. - * Expects `value => true` format when `$flip` is true. - * @param bool $flip Optional. Whether or not to flip the custom list. - * Defaults to true. + * @since 2.0.0 No longer supports custom array properties which were incorrectly + * passed as a string. + * + * @param array $custom Custom list as provided via a ruleset. + * @param array $base Optional. Base list. Defaults to an empty array. + * Expects `value => true` format when `$flip` is true. + * @param bool $flip Optional. Whether or not to flip the custom list. + * Defaults to true. * @return array */ public static function merge_custom_array( $custom, $base = array(), $flip = true ) { @@ -976,18 +974,10 @@ public static function merge_custom_array( $custom, $base = array(), $flip = tru $base = array_filter( $base ); } - if ( empty( $custom ) || ( ! \is_array( $custom ) && ! \is_string( $custom ) ) ) { + if ( empty( $custom ) || ! \is_array( $custom ) ) { return $base; } - // Allow for a comma delimited list. - if ( \is_string( $custom ) ) { - $custom = explode( ',', $custom ); - } - - // Always trim whitespace from the values. - $custom = array_filter( array_map( 'trim', $custom ) ); - if ( true === $flip ) { $custom = array_fill_keys( $custom, false ); } diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index 8994e57130..5656b2c7e8 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -240,7 +240,7 @@ public function process_token( $stackPtr ) { // Allow overruling the prefixes set in a ruleset via the command line. $cl_prefixes = trim( PHPCSHelper::get_config_data( 'prefixes' ) ); if ( ! empty( $cl_prefixes ) ) { - $this->prefixes = $cl_prefixes; + $this->prefixes = array_filter( array_map( 'trim', explode( ',', $cl_prefixes ) ) ); } $this->prefixes = $this->merge_custom_array( $this->prefixes, array(), false ); diff --git a/WordPress/Sniffs/WP/I18nSniff.php b/WordPress/Sniffs/WP/I18nSniff.php index c5dab418a9..7eff323ef3 100644 --- a/WordPress/Sniffs/WP/I18nSniff.php +++ b/WordPress/Sniffs/WP/I18nSniff.php @@ -192,7 +192,7 @@ public function process_token( $stack_ptr ) { // Allow overruling the text_domain set in a ruleset via the command line. $cl_text_domain = trim( PHPCSHelper::get_config_data( 'text_domain' ) ); if ( ! empty( $cl_text_domain ) ) { - $this->text_domain = $cl_text_domain; + $this->text_domain = array_filter( array_map( 'trim', explode( ',', $cl_text_domain ) ) ); } $this->text_domain = $this->merge_custom_array( $this->text_domain, array(), false ); From 698eade1b4d5c6107486ccd2a8d525a5a8c5f44d Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 17 Dec 2018 02:32:42 +0100 Subject: [PATCH 045/241] Extra: Use the new `Generic.WhiteSpace.LanguageConstructSpacing` sniff (PHPCS 3.3.0) The `Squiz.WhiteSpace.LanguageConstructSpacing` sniff has been deprecated in PHPCS 3.3.0 and will be removed in PHPCS 4, in favour of the newly introduced `Generic.WhiteSpace.LanguageConstructSpacing` sniff. Ref: * 1328 * squizlabs/PHP_CodeSniffer 1337 --- WordPress-Extra/ruleset.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index 87acba16a9..14529fc79b 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -56,7 +56,7 @@ - + From 1c5e627b5ae2e01b8c85df47eba26abda4a4a5f2 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 17 Dec 2018 02:17:27 +0100 Subject: [PATCH 046/241] ValidVariableName: Defer to the upstream `$phpReservedVars` property (PHPCS 3.3.0) The upstream `PHP_CodeSniffer\Sniffs\AbstractVariableSniff` contains the same list of PHP reserved variables since PHPCS 3.3.0, so no need to maintain it ourselves. Refs: * squizlabs/PHP_CodeSniffer 1888 --- .../ValidVariableNameSniff.php | 28 ++----------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index 049b3ebab9..8c9f6a891d 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -23,6 +23,7 @@ * * @since 0.9.0 * @since 0.13.0 Class name changed: this class is now namespaced. + * @since 2.0.0 Defers to the upstream `$phpReservedVars` property. * * Last synced with base class June 2018 at commit 78ddbae97cac078f09928bf89e3ab9e53ad2ace0. * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -31,29 +32,6 @@ */ class ValidVariableNameSniff extends PHPCS_AbstractVariableSniff { - /** - * PHP Reserved Vars. - * - * @since 0.9.0 - * @since 0.11.0 Changed visibility from public to protected. - * - * @var array - */ - protected $php_reserved_vars = array( - '_SERVER' => true, - '_GET' => true, - '_POST' => true, - '_REQUEST' => true, - '_SESSION' => true, - '_ENV' => true, - '_COOKIE' => true, - '_FILES' => true, - 'GLOBALS' => true, - 'http_response_header' => true, - 'HTTP_RAW_POST_DATA' => true, - 'php_errormsg' => true, - ); - /** * Mixed-case variables used by WordPress. * @@ -131,7 +109,7 @@ protected function processVariable( File $phpcs_file, $stack_ptr ) { $var_name = ltrim( $tokens[ $stack_ptr ]['content'], '$' ); // If it's a php reserved var, then its ok. - if ( isset( $this->php_reserved_vars[ $var_name ] ) ) { + if ( isset( $this->phpReservedVars[ $var_name ] ) ) { return; } @@ -254,7 +232,7 @@ protected function processVariableInString( File $phpcs_file, $stack_ptr ) { foreach ( $matches[1] as $var_name ) { // If it's a php reserved var, then its ok. - if ( isset( $this->php_reserved_vars[ $var_name ] ) ) { + if ( isset( $this->phpReservedVars[ $var_name ] ) ) { continue; } From 366b8fb21e91fb047fd9c486040d2e30b2992ce4 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 17 Dec 2018 04:09:12 +0100 Subject: [PATCH 047/241] Extra: Document why two WPCS native sniffs are not (yet) replaced by upstream sniffs --- WordPress-Extra/ruleset.xml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index 87acba16a9..f324e74648 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -27,7 +27,9 @@ + https://github.com/squizlabs/PHP_CodeSniffer/pull/1594 + Note: the "assignment in ternary" part of the sniff is currently not yet covered in + the upstream version. This needs to be pulled first before we can defer to upstream. --> + https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/919 + Note: there is a similar upstream sniff `PSR12.Classes.ClassInstantiation`, however + that sniff: + - does not cover JS files; + - does not demand parentheses for PHP anonymous classes; + - does not check the whitespace between the class name and the parentheses; + - does not check for PHP new by reference. + For those reasons, the WPCS version should remain. --> From fbd87ae372cb6928721158b817fcc1c3320d51d4 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 17 Dec 2018 05:43:40 +0100 Subject: [PATCH 048/241] GH: Remove superseded issue template --- .github/issue_template.md | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 .github/issue_template.md diff --git a/.github/issue_template.md b/.github/issue_template.md deleted file mode 100644 index f6e4f49872..0000000000 --- a/.github/issue_template.md +++ /dev/null @@ -1,11 +0,0 @@ - \ No newline at end of file From 8e7019f6d83ed1bf51419bd267ca9039b1eedfa8 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 8 Jul 2018 00:29:19 +0200 Subject: [PATCH 049/241] ArrayDeclarationSpacing: improve handling of multi-line trailing comments In a multi-line array, if an array item was followed by a multi-line trailing comment and the next item started on the same line as the end of the trailing comment, no error was thrown, nor was this auto-fixed. This commit fixes that. Loosely related to 1384 --- .../Arrays/ArrayDeclarationSpacingSniff.php | 27 ++++++++-- .../ArrayDeclarationSpacingUnitTest.1.inc | 10 ++++ ...rrayDeclarationSpacingUnitTest.1.inc.fixed | 11 ++++ .../ArrayDeclarationSpacingUnitTest.2.inc | 10 ++++ ...rrayDeclarationSpacingUnitTest.2.inc.fixed | 11 ++++ .../ArrayDeclarationSpacingUnitTest.php | 50 ++++++++++--------- 6 files changed, 91 insertions(+), 28 deletions(-) diff --git a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php index c46769d89f..949d818d95 100644 --- a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php @@ -383,12 +383,31 @@ protected function process_multi_line_array( $stackPtr, $opener, $closer ) { ); // Ignore comments after array items if the next real content starts on a new line. - if ( \T_COMMENT === $this->tokens[ $first_content ]['code'] - || isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $first_content ]['code'] ] ) + if ( $this->tokens[ $first_content ]['line'] === $this->tokens[ $end_of_last_item ]['line'] + && ( \T_COMMENT === $this->tokens[ $first_content ]['code'] + || isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $first_content ]['code'] ] ) ) ) { + $end_of_comment = $first_content; + + // Find the end of (multi-line) /* */- style trailing comments. + if ( substr( ltrim( $this->tokens[ $end_of_comment ]['content'] ), 0, 2 ) === '/*' ) { + while ( ( \T_COMMENT === $this->tokens[ $end_of_comment ]['code'] + || isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $end_of_comment ]['code'] ] ) ) + && substr( rtrim( $this->tokens[ $end_of_comment ]['content'] ), -2 ) !== '*/' + && ( $end_of_comment + 1 ) < $end_of_this_item + ) { + $end_of_comment++; + } + + if ( $this->tokens[ $end_of_comment ]['line'] !== $this->tokens[ $end_of_last_item ]['line'] ) { + // Multi-line trailing comment. + $end_of_last_item = $end_of_comment; + } + } + $next = $this->phpcsFile->findNext( array( \T_WHITESPACE, \T_DOC_COMMENT_WHITESPACE ), - ( $first_content + 1 ), + ( $end_of_comment + 1 ), $end_of_this_item, true ); @@ -422,7 +441,7 @@ protected function process_multi_line_array( $stackPtr, $opener, $closer ) { $this->phpcsFile->fixer->beginChangeset(); - if ( $item['start'] <= ( $first_content - 1 ) + if ( ( $end_of_last_item + 1 ) <= ( $first_content - 1 ) && \T_WHITESPACE === $this->tokens[ ( $first_content - 1 ) ]['code'] ) { // Remove whitespace which would otherwise becoming trailing diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc index c5e1eb35d3..0a241823d1 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc @@ -114,3 +114,13 @@ $foo = array( 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode 'meta_value' => 'bar', // phpcs:ignore Standard.Category.SniffName.ErrorCode ); + +// Test for fixing array with multi-line comments between values. +$bad = array( + 'key1' => 'value1', /* comment + end */ 'key2' => 'value2', // Bad. + /* Non-trailing comment. */ + 'key3' => 'value3', /* comment + end */ + 'key4' => 'value4' +); diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed index 53e935b11f..244b5787e4 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed @@ -169,3 +169,14 @@ $foo = array( 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode 'meta_value' => 'bar', // phpcs:ignore Standard.Category.SniffName.ErrorCode ); + +// Test for fixing array with multi-line comments between values. +$bad = array( + 'key1' => 'value1', /* comment + end */ +'key2' => 'value2', // Bad. + /* Non-trailing comment. */ + 'key3' => 'value3', /* comment + end */ + 'key4' => 'value4' +); diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc index e9157b7981..fc659e3612 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc @@ -97,3 +97,13 @@ $foo = [ 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode 'meta_value' => 'bar', // phpcs:ignore Standard.Category.SniffName.ErrorCode ]; + +// Test for fixing array with multi-line comments between values. +$bad = [ + 'key1' => 'value1', /* comment + end */ 'key2' => 'value2', // Bad. + /* Non-trailing comment. */ + 'key3' => 'value3', /* comment + end */ + 'key4' => 'value4' +]; diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed index 1dfa3c8e9f..58adaa3bdf 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed @@ -153,3 +153,14 @@ $foo = [ 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode 'meta_value' => 'bar', // phpcs:ignore Standard.Category.SniffName.ErrorCode ]; + +// Test for fixing array with multi-line comments between values. +$bad = [ + 'key1' => 'value1', /* comment + end */ +'key2' => 'value2', // Bad. + /* Non-trailing comment. */ + 'key3' => 'value3', /* comment + end */ + 'key4' => 'value4' +]; diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php index 3114e175bf..713d8b8cb5 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php @@ -62,35 +62,37 @@ public function getErrorList( $testFile = '' ) { 104 => 2, 108 => 1, 109 => 1, + 121 => 1, ); // Short arrays. case 'ArrayDeclarationSpacingUnitTest.2.inc': return array( - 8 => 2, - 11 => 2, - 16 => 4, - 20 => 2, - 22 => 1, - 26 => 1, - 29 => 1, - 32 => 1, - 45 => 1, - 46 => 1, - 47 => 1, - 67 => 1, - 68 => 1, - 71 => 1, - 72 => 2, - 75 => 3, - 77 => 1, - 80 => 1, - 81 => 2, - 84 => 1, - 86 => 2, - 87 => 2, - 91 => 1, - 92 => 1, + 8 => 2, + 11 => 2, + 16 => 4, + 20 => 2, + 22 => 1, + 26 => 1, + 29 => 1, + 32 => 1, + 45 => 1, + 46 => 1, + 47 => 1, + 67 => 1, + 68 => 1, + 71 => 1, + 72 => 2, + 75 => 3, + 77 => 1, + 80 => 1, + 81 => 2, + 84 => 1, + 86 => 2, + 87 => 2, + 91 => 1, + 92 => 1, + 104 => 1, ); default: From 34ccaee1ce051c39df7b552c25840f100e9db266 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 22 Dec 2018 16:26:22 +0100 Subject: [PATCH 050/241] Composer: some tweaks * Make the scripts section more readable by setting each script up as an array. * `require-dev` the DealerDirect Composer plugin to make live easier on WPCS devs using Composer for their dev environment. Includes: - Adjusting the `install-codestandards` script to use the plugin. - Removing the `post-install-cmd` and `post-update-cmd` which shouldn't be needed anymore as the plugin automatically takes care of installing the standards. * Includes updating the inline documentation in the Travis script to be inline with these changes. --- .travis.yml | 2 +- composer.json | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index b97e957b4e..64fe800947 100644 --- a/.travis.yml +++ b/.travis.yml @@ -55,7 +55,7 @@ before_install: - | if [[ "$SNIFF" == "1" ]]; then composer install --dev --no-suggest - # The post-install-cmd script takes care of the installed_paths. + # The `dev` required DealerDirect Composer plugin takes care of the installed_paths. else # The above require already does the install. $(pwd)/vendor/bin/phpcs --config-set installed_paths $(pwd) diff --git a/composer.json b/composer.json index 3b1adc8457..7e6f35545b 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,7 @@ "squizlabs/php_codesniffer": "^3.3.1" }, "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0", "phpcompatibility/php-compatibility": "^9.0", "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, @@ -27,12 +28,18 @@ }, "minimum-stability": "RC", "scripts": { - "post-install-cmd": "@install-codestandards", - "post-update-cmd": "@install-codestandards", - "check-cs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs", - "fix-cs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf", - "install-codestandards": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --config-set installed_paths ../../..,../../phpcompatibility/php-compatibility", - "run-tests": "@php ./vendor/phpunit/phpunit/phpunit --filter WordPress --bootstrap=\"./vendor/squizlabs/php_codesniffer/tests/bootstrap.php\" ./vendor/squizlabs/php_codesniffer/tests/AllTests.php" + "check-cs": [ + "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs" + ], + "fix-cs": [ + "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf" + ], + "install-codestandards": [ + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run" + ], + "run-tests": [ + "@php ./vendor/phpunit/phpunit/phpunit --filter WordPress --bootstrap=\"./vendor/squizlabs/php_codesniffer/tests/bootstrap.php\" ./vendor/squizlabs/php_codesniffer/tests/AllTests.php" + ] }, "support": { "issues": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues", From 72818a7be2fc804be47d44cff5ba57a87b360d87 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 23 Dec 2018 03:38:15 +0100 Subject: [PATCH 051/241] Extra: remove superfluous directive The sniff already throws a warning for that error code, so we don't need to change the `type`. --- WordPress-Extra/ruleset.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index aee8d0c2c7..6222ec1e55 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -76,9 +76,6 @@ - - warning - From c8f8c978a04f81eb48b81e27c825afdfb8dda026 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 23 Dec 2018 03:37:29 +0100 Subject: [PATCH 052/241] Extra: Replace `Squiz.Scope.MemberVarScope` with `PSR2.Classes.PropertyDeclaration` PR 1103 added the `Squiz.Scope.MemberVarScope` sniff to the `WordPress-Extra` ruleset which checks that all class properties have their visibility declared. The upstream `PSR2.Classes.PropertyDeclaration` sniff also does this, however it contains more extensive checks. In addition to checking for the visibility of properties being declared, this sniff also checks: * That property names are not prefixed with an underscore `_` to indicate visibility. _For methods, we already check this in the `Extra` ruleset via the `PSR2.Methods.MethodDeclaration` sniff._ * That the `var` keyword is not used for property declarations. This could be considered a duplicate check with the "use visibility" check. * That each property declaration statement only declares one property, i.e. it forbids the use of code like this: ```php public $prop1 = true, $prop2 = '', $prop3 = 123; ``` Even though there is no precedent or reference to this type of property declarations in the handbook or elsewhere in the various rulesets, WP Core itself does not appear to use multi-property assignments, so we may as well check leave the check in for now. People can always still exclude it in their own custom rulesets and if we'd get a lot of push-back, we can reconsider. * As of PHPCS 3.4.0: that the order of the property keywords is `visibility static`, not `static visibility` (includes fixer). _For methods, we already check this in the `Extra` ruleset via the `PSR2.Methods.MethodDeclaration` sniff._ All in all, using the `PSR2` sniff is more in line with the checks we already have in place for methods, so IMO, this seemed like a good change to make. --- WordPress-Extra/ruleset.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index aee8d0c2c7..6370e07db3 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -73,7 +73,7 @@ - + From f5913cc0357be2236360f04a009a24f6189160ce Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 22 Dec 2018 16:49:47 +0100 Subject: [PATCH 053/241] PHPCS native ruleset: don't require exact array double arrow alignment When the item with the _longest_ array key is removed, WPCS requires the double arrows in the whole array to be re-aligned. Setting the [`exact` property](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#array-alignment-allow-non-exact-alignment) to `false` removes this requirement and allows for cleaner diffs when this happens. As PR 1547 removed a large number of items from the `Sniff::$autoEscapedFunctions` array, PHPCS was currently throwing warnings about the WPCS codebase. This small tweaks gets rid of those, while still allowing `phpcbf` to fix them up if so desired. --- .phpcs.xml.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index fd5ccc1510..0bc9d6c10e 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -26,6 +26,7 @@ + From 816322ce923d703e4444e4a6e25b4f1529642339 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 22 Jul 2017 19:51:37 +0200 Subject: [PATCH 054/241] Documentation: Touch up the class and method documentation What with classes originally having underscore delimited names, then becoming namespaced and now the namespaces being changed, documentation still referencing old, outdated class names can be confusing for new contributors. With that in mind, I've fixed up most of the documentation to either reference the sniff _code_ or the current sniff class name. --- .../AbstractArrayAssignmentRestrictionsSniff.php | 4 ++-- WordPress/AbstractClassRestrictionsSniff.php | 2 +- WordPress/AbstractFunctionRestrictionsSniff.php | 6 +++--- WordPress/Sniff.php | 8 ++++---- .../Sniffs/Arrays/ArrayDeclarationSpacingSniff.php | 11 +++++------ .../Arrays/ArrayKeySpacingRestrictionsSniff.php | 2 +- WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php | 2 +- WordPress/Sniffs/Files/FileNameSniff.php | 4 ++-- .../NamingConventions/PrefixAllGlobalsSniff.php | 2 +- .../Sniffs/NamingConventions/ValidHookNameSniff.php | 2 +- WordPress/Sniffs/PHP/DontExtractSniff.php | 3 ++- WordPress/Sniffs/PHP/POSIXFunctionsSniff.php | 5 +++-- WordPress/Sniffs/PHP/StrictInArraySniff.php | 9 +++++---- WordPress/Sniffs/PHP/YodaConditionsSniff.php | 2 +- WordPress/Sniffs/Security/EscapeOutputSniff.php | 4 ++-- WordPress/Sniffs/Security/PluginMenuSlugSniff.php | 3 ++- .../Sniffs/Security/ValidatedSanitizedInputSniff.php | 4 ++-- WordPress/Sniffs/WP/AlternativeFunctionsSniff.php | 2 +- WordPress/Sniffs/WP/CronIntervalSniff.php | 2 +- WordPress/Sniffs/WP/DeprecatedClassesSniff.php | 2 +- WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php | 2 +- .../Sniffs/WP/DeprecatedParameterValuesSniff.php | 2 +- WordPress/Sniffs/WP/DeprecatedParametersSniff.php | 2 +- WordPress/Sniffs/WP/EnqueuedResourcesSniff.php | 2 +- WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php | 6 +++--- WordPress/Sniffs/WP/I18nSniff.php | 3 ++- WordPress/Sniffs/WP/TimezoneChangeSniff.php | 4 ++-- .../Sniffs/WhiteSpace/CastStructureSpacingSniff.php | 2 +- .../WhiteSpace/ControlStructureSpacingSniff.php | 2 +- 29 files changed, 54 insertions(+), 50 deletions(-) diff --git a/WordPress/AbstractArrayAssignmentRestrictionsSniff.php b/WordPress/AbstractArrayAssignmentRestrictionsSniff.php index fff3a71fc8..6095db0d72 100644 --- a/WordPress/AbstractArrayAssignmentRestrictionsSniff.php +++ b/WordPress/AbstractArrayAssignmentRestrictionsSniff.php @@ -19,8 +19,8 @@ * @since 0.3.0 * @since 0.10.0 Class became a proper abstract class. This was already the behaviour. * Moved the file and renamed the class from - * `WordPress_Sniffs_Arrays_ArrayAssignmentRestrictionsSniff` to - * `WordPress_AbstractArrayAssignmentRestrictionsSniff`. + * `\WordPressCS\WordPress\Sniffs\Arrays\ArrayAssignmentRestrictionsSniff` to + * `\WordPressCS\WordPress\AbstractArrayAssignmentRestrictionsSniff`. */ abstract class AbstractArrayAssignmentRestrictionsSniff extends Sniff { diff --git a/WordPress/AbstractClassRestrictionsSniff.php b/WordPress/AbstractClassRestrictionsSniff.php index 05b0dcc5b7..ad46cb83a4 100644 --- a/WordPress/AbstractClassRestrictionsSniff.php +++ b/WordPress/AbstractClassRestrictionsSniff.php @@ -79,7 +79,7 @@ public function register() { /** * Processes this test, when one of its tokens is encountered. * - * {@internal Unlike in the `WordPress_AbstractFunctionRestrictionsSniff`, + * {@internal Unlike in the `AbstractFunctionRestrictionsSniff`, * we can't do a preliminary check on classes as at this point * we don't know the class name yet.}} * diff --git a/WordPress/AbstractFunctionRestrictionsSniff.php b/WordPress/AbstractFunctionRestrictionsSniff.php index 1fbc24a4bd..ea2e50ae23 100644 --- a/WordPress/AbstractFunctionRestrictionsSniff.php +++ b/WordPress/AbstractFunctionRestrictionsSniff.php @@ -20,9 +20,9 @@ * @since 0.3.0 * @since 0.10.0 Class became a proper abstract class. This was already the behaviour. * Moved the file and renamed the class from - * `WordPress_Sniffs_Functions_FunctionRestrictionsSniff` to - * `WordPress_AbstractFunctionRestrictionsSniff`. - * @since 0.11.0 Extends the WordPress_Sniff class. + * `\WordPressCS\WordPress\Sniffs\Functions\FunctionRestrictionsSniff` to + * `\WordPressCS\WordPress\AbstractFunctionRestrictionsSniff`. + * @since 0.11.0 Extends the WordPressCS native `Sniff` class. */ abstract class AbstractFunctionRestrictionsSniff extends Sniff { diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 8341e10def..245f7d8443 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -500,7 +500,7 @@ abstract class Sniff implements PHPCS_Sniff { * @since 0.3.0 * @since 0.11.0 Changed visibility from public to protected. * @since 0.12.0 Renamed from `$globals` to `$wp_globals` to be more descriptive. - * @since 0.12.0 Moved from WordPress_Sniffs_Variables_GlobalVariablesSniff to WordPress_Sniff + * @since 0.12.0 Moved here from the WordPress.Variables.GlobalVariables sniff. * * @var array */ @@ -955,7 +955,7 @@ protected function string_to_errorcode( $base_string ) { * before merging/returning to allow for resetting to the base array. * * {@internal Function is static as it doesn't use any of the properties or others - * methods anyway and this way the `WordPress_Sniffs_NamingConventions_ValidVariableNameSniff` + * methods anyway and this way the `WordPress.NamingConventions.ValidVariableName` sniff * which extends an upstream sniff can also use it.}} * * @since 0.11.0 @@ -2196,7 +2196,7 @@ protected function find_array_open_close( $stackPtr ) { * Determine the namespace name an arbitrary token lives in. * * @since 0.10.0 - * @since 0.12.0 Moved from the WordPress_AbstractClassRestrictionsSniff to this sniff. + * @since 0.12.0 Moved from the `AbstractClassRestrictionsSniff` to this class. * * @param int $stackPtr The token position for which to determine the namespace. * @@ -2262,7 +2262,7 @@ public function determine_namespace( $stackPtr ) { * i.e. MyProject\Sub\Level which will be returned together as one string. * * @since 0.12.0 A lesser variant of this method previously existed in the - * WordPress_AbstractClassRestrictionsSniff. + * `AbstractClassRestrictionsSniff` class. * * @param int|bool $stackPtr The position of a T_NAMESPACE token. * diff --git a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php index 949d818d95..f5c6257f3c 100644 --- a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php @@ -27,14 +27,13 @@ * @package WPCS\WordPressCodingStandards * * @since 0.11.0 - The WordPress specific additional checks have now been split off - * from the WordPress_Sniffs_Arrays_ArrayDeclaration sniff into - * this sniff. + * from the `WordPress.Arrays.ArrayDeclaration` sniff into this sniff. * - Added sniffing & fixing for associative arrays. * @since 0.12.0 Decoupled this sniff from the upstream sniff completely. - * This sniff now extends the `WordPress_Sniff` instead. - * @since 0.13.0 Added the last remaining checks from the `ArrayDeclaration` sniff - * which were not covered elsewhere. The `ArrayDeclaration` sniff has - * now been deprecated. + * This sniff now extends the WordPressCS native `Sniff` class instead. + * @since 0.13.0 Added the last remaining checks from the `WordPress.Arrays.ArrayDeclaration` + * sniff which were not covered elsewhere. + * The `WordPress.Arrays.ArrayDeclaration` sniff has now been deprecated. * @since 0.13.0 Class name changed: this class is now namespaced. * @since 0.14.0 Single item associative arrays are now by default exempt from the * "must be multi-line" rule. This behaviour can be changed using the diff --git a/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php b/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php index 0ef102e891..b209409368 100644 --- a/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php @@ -20,7 +20,7 @@ * * @since 0.3.0 * @since 0.7.0 This sniff now has the ability to fix a number of the issues it flags. - * @since 0.12.0 This class now extends WordPress_Sniff. + * @since 0.12.0 This class now extends the WordPressCS native `Sniff` class. * @since 0.13.0 Class name changed: this class is now namespaced. */ class ArrayKeySpacingRestrictionsSniff extends Sniff { diff --git a/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php b/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php index eecb3e757e..35b4e6447b 100644 --- a/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php +++ b/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php @@ -21,7 +21,7 @@ * * @since 0.3.0 * @since 0.6.0 Removed the add_unique_message() function as it is no longer needed. - * @since 0.11.0 This class now extends WordPress_Sniff. + * @since 0.11.0 This class now extends the WordPressCS native `Sniff` class. * @since 0.13.0 Class name changed: this class is now namespaced. * @since 1.0.0 This sniff has been moved from the `VIP` category to the `DB` category. */ diff --git a/WordPress/Sniffs/Files/FileNameSniff.php b/WordPress/Sniffs/Files/FileNameSniff.php index 797d277d31..43eb1061b9 100644 --- a/WordPress/Sniffs/Files/FileNameSniff.php +++ b/WordPress/Sniffs/Files/FileNameSniff.php @@ -25,10 +25,10 @@ * template tags end in `-template`. Based on @subpackage file DocBlock tag. * - This sniff will now allow for underscores in file names for certain theme * specific exceptions if the `$is_theme` property is set to `true`. - * @since 0.12.0 Now extends the `WordPress_Sniff` class. + * @since 0.12.0 Now extends the WordPressCS native `Sniff` class. * @since 0.13.0 Class name changed: this class is now namespaced. * - * @uses \WordPress\Sniff::$custom_test_class_whitelist + * @uses \WordPressCS\WordPress\Sniff::$custom_test_class_whitelist */ class FileNameSniff extends Sniff { diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index 5656b2c7e8..1dd90a3fb8 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -22,7 +22,7 @@ * @since 0.13.0 Class name changed: this class is now namespaced. * @since 1.2.0 Now also checks whether namespaces are prefixed. * - * @uses \WordPress\Sniff::$custom_test_class_whitelist + * @uses \WordPressCS\WordPress\Sniff::$custom_test_class_whitelist */ class PrefixAllGlobalsSniff extends AbstractFunctionParameterSniff { diff --git a/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php index ae133c0b69..e7dc9b9e86 100644 --- a/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php @@ -24,7 +24,7 @@ * @package WPCS\WordPressCodingStandards * * @since 0.10.0 - * @since 0.11.0 Extends the WordPress_AbstractFunctionParameterSniff class. + * @since 0.11.0 Extends the WordPressCS native `AbstractFunctionParameterSniff` class. * @since 0.13.0 Class name changed: this class is now namespaced. */ class ValidHookNameSniff extends AbstractFunctionParameterSniff { diff --git a/WordPress/Sniffs/PHP/DontExtractSniff.php b/WordPress/Sniffs/PHP/DontExtractSniff.php index 6db447ad0d..0b9b984b3a 100644 --- a/WordPress/Sniffs/PHP/DontExtractSniff.php +++ b/WordPress/Sniffs/PHP/DontExtractSniff.php @@ -18,7 +18,8 @@ * * @package WPCS\WordPressCodingStandards * - * @since 0.10.0 Previously this check was contained within WordPress_Sniffs_VIP_RestrictedFunctionsSniff. + * @since 0.10.0 Previously this check was contained within the + * `WordPress.VIP.RestrictedFunctions` sniff. * @since 0.13.0 Class name changed: this class is now namespaced. * @since 1.0.0 This sniff has been moved from the `Functions` category to the `PHP` category. */ diff --git a/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php b/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php index a7e1b0be7b..aade23c63c 100644 --- a/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php @@ -20,8 +20,9 @@ * * @package WPCS\WordPressCodingStandards * - * @since 0.10.0 Previously this check was contained within WordPress_Sniffs_VIP_RestrictedFunctionsSniff - * and the WordPress_Sniffs_PHP_DiscouragedPHPFunctionsSniff. + * @since 0.10.0 Previously this check was contained within the + * `WordPress.VIP.RestrictedFunctions` and the + * `WordPress.PHP.DiscouragedPHPFunctions` sniffs. * @since 0.13.0 Class name changed: this class is now namespaced. */ class POSIXFunctionsSniff extends AbstractFunctionRestrictionsSniff { diff --git a/WordPress/Sniffs/PHP/StrictInArraySniff.php b/WordPress/Sniffs/PHP/StrictInArraySniff.php index f74f3f491d..f50ce14b9f 100644 --- a/WordPress/Sniffs/PHP/StrictInArraySniff.php +++ b/WordPress/Sniffs/PHP/StrictInArraySniff.php @@ -19,10 +19,11 @@ * @package WPCS\WordPressCodingStandards * * @since 0.9.0 - * @since 0.10.0 This sniff not only checks for `in_array()`, but also `array_search()` and `array_keys()`. - * The sniff no longer needlessly extends the WordPress_Sniffs_Arrays_ArrayAssignmentRestrictionsSniff - * which it didn't use. - * @since 0.11.0 Refactored to extend the new WordPress_AbstractFunctionParameterSniff. + * @since 0.10.0 - This sniff not only checks for `in_array()`, but also `array_search()` + * and `array_keys()`. + * - The sniff no longer needlessly extends the `ArrayAssignmentRestrictionsSniff` + * class which it didn't use. + * @since 0.11.0 Refactored to extend the new WordPressCS native `AbstractFunctionParameterSniff` class. * @since 0.13.0 Class name changed: this class is now namespaced. */ class StrictInArraySniff extends AbstractFunctionParameterSniff { diff --git a/WordPress/Sniffs/PHP/YodaConditionsSniff.php b/WordPress/Sniffs/PHP/YodaConditionsSniff.php index bd6738f69c..0587da884d 100644 --- a/WordPress/Sniffs/PHP/YodaConditionsSniff.php +++ b/WordPress/Sniffs/PHP/YodaConditionsSniff.php @@ -20,7 +20,7 @@ * @package WPCS\WordPressCodingStandards * * @since 0.3.0 - * @since 0.12.0 This class now extends WordPress_Sniff. + * @since 0.12.0 This class now extends the WordPressCS native `Sniff` class. * @since 0.13.0 Class name changed: this class is now namespaced. */ class YodaConditionsSniff extends Sniff { diff --git a/WordPress/Sniffs/Security/EscapeOutputSniff.php b/WordPress/Sniffs/Security/EscapeOutputSniff.php index 2458ddcef0..a4dd060cb2 100644 --- a/WordPress/Sniffs/Security/EscapeOutputSniff.php +++ b/WordPress/Sniffs/Security/EscapeOutputSniff.php @@ -20,9 +20,9 @@ * @package WPCS\WordPressCodingStandards * * @since 2013-06-11 - * @since 0.4.0 This class now extends WordPress_Sniff. + * @since 0.4.0 This class now extends the WordPressCS native `Sniff` class. * @since 0.5.0 The various function list properties which used to be contained in this class - * have been moved to the WordPress_Sniff parent class. + * have been moved to the WordPressCS native `Sniff` parent class. * @since 0.12.0 This sniff will now also check for output escaping when using shorthand * echo tags ` value * in a custom ruleset. * - * @uses \WordPress\Sniff::$minimum_supported_version + * @uses \WordPressCS\WordPress\Sniff::$minimum_supported_version */ class DeprecatedClassesSniff extends AbstractClassRestrictionsSniff { diff --git a/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php b/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php index 15adbc5307..7270899004 100644 --- a/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php @@ -28,7 +28,7 @@ * being provided via the command-line or as as value * in a custom ruleset. * - * @uses \WordPress\Sniff::$minimum_supported_version + * @uses \WordPressCS\WordPress\Sniff::$minimum_supported_version */ class DeprecatedFunctionsSniff extends AbstractFunctionRestrictionsSniff { diff --git a/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php b/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php index 7bbecee22f..01a2f7f860 100644 --- a/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php @@ -19,7 +19,7 @@ * * @since 1.0.0 * - * @uses \WordPress\Sniff::$minimum_supported_version + * @uses \WordPressCS\WordPress\Sniff::$minimum_supported_version */ class DeprecatedParameterValuesSniff extends AbstractFunctionParameterSniff { diff --git a/WordPress/Sniffs/WP/DeprecatedParametersSniff.php b/WordPress/Sniffs/WP/DeprecatedParametersSniff.php index 08980292d6..b6918cdb39 100644 --- a/WordPress/Sniffs/WP/DeprecatedParametersSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedParametersSniff.php @@ -28,7 +28,7 @@ * being provided via the command-line or as as value * in a custom ruleset. * - * @uses \WordPress\Sniff::$minimum_supported_version + * @uses \WordPressCS\WordPress\Sniff::$minimum_supported_version */ class DeprecatedParametersSniff extends AbstractFunctionParameterSniff { diff --git a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php index 05c642156f..1473eac208 100644 --- a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php +++ b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php @@ -20,7 +20,7 @@ * @package WPCS\WordPressCodingStandards * * @since 0.3.0 - * @since 0.12.0 This class now extends WordPress_Sniff. + * @since 0.12.0 This class now extends the WordPressCS native `Sniff` class. * @since 0.13.0 Class name changed: this class is now namespaced. */ class EnqueuedResourcesSniff extends Sniff { diff --git a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php index aef39075de..615cec925c 100644 --- a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php +++ b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php @@ -18,14 +18,14 @@ * @package WPCS\WordPressCodingStandards * * @since 0.3.0 - * @since 0.4.0 This class now extends WordPress_Sniff. - * @since 0.12.0 The $wp_globals property has been moved to the WordPress_Sniff. + * @since 0.4.0 This class now extends the WordPressCS native `Sniff` class. + * @since 0.12.0 The $wp_globals property has been moved to the `Sniff` class. * @since 0.13.0 Class name changed: this class is now namespaced. * @since 1.0.0 This sniff has been moved from the `Variables` category to the `WP` * category and renamed from `GlobalVariables` to `GlobalVariablesOverride`. * @since 1.1.0 The sniff now also detects variables being overriden in the global namespace. * - * @uses \WordPress\Sniff::$custom_test_class_whitelist + * @uses \WordPressCS\WordPress\Sniff::$custom_test_class_whitelist */ class GlobalVariablesOverrideSniff extends Sniff { diff --git a/WordPress/Sniffs/WP/I18nSniff.php b/WordPress/Sniffs/WP/I18nSniff.php index 7eff323ef3..01797b5f78 100644 --- a/WordPress/Sniffs/WP/I18nSniff.php +++ b/WordPress/Sniffs/WP/I18nSniff.php @@ -27,7 +27,8 @@ * as a comma-delimited list. * `phpcs --runtime-set text_domain my-slug,default` * @since 0.13.0 Class name changed: this class is now namespaced. - * @since 1.0.0 This class now extends the AbstractFunctionRestrictionSniff. + * @since 1.0.0 This class now extends the WordPressCS native + * `AbstractFunctionRestrictionSniff` class. * The parent `exclude` property is, however, disabled as it * would disable the whole sniff. */ diff --git a/WordPress/Sniffs/WP/TimezoneChangeSniff.php b/WordPress/Sniffs/WP/TimezoneChangeSniff.php index 5970e19b1c..c57f8556cb 100644 --- a/WordPress/Sniffs/WP/TimezoneChangeSniff.php +++ b/WordPress/Sniffs/WP/TimezoneChangeSniff.php @@ -19,8 +19,8 @@ * @package WPCS\WordPressCodingStandards * * @since 0.3.0 - * @since 0.11.0 Extends the WordPress_AbstractFunctionRestrictionsSniff instead of the - * Generic_Sniffs_PHP_ForbiddenFunctionsSniff. + * @since 0.11.0 Extends the WordPressCS native `AbstractFunctionRestrictionsSniff` + * class instead of the upstream `Generic.PHP.ForbiddenFunctions` sniff. * @since 0.13.0 Class name changed: this class is now namespaced. * @since 1.0.0 This sniff has been moved from the `VIP` category to the `WP` category. */ diff --git a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php index af87a7d634..0aa4ff9cc2 100755 --- a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php @@ -22,7 +22,7 @@ * @since 0.3.0 * @since 0.11.0 This sniff now has the ability to fix the issues it flags. * @since 0.11.0 The error level for all errors thrown by this sniff has been raised from warning to error. - * @since 0.12.0 This class now extends WordPress_Sniff. + * @since 0.12.0 This class now extends the WordPressCS native `Sniff` class. * @since 0.13.0 Class name changed: this class is now namespaced. */ class CastStructureSpacingSniff extends Sniff { diff --git a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php index e6de10e8d1..b0654ae4f1 100644 --- a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php @@ -20,7 +20,7 @@ * @since 0.1.0 * @since 2013-06-11 This sniff no longer supports JS. * @since 0.3.0 This sniff now has the ability to fix most errors it flags. - * @since 0.7.0 This class now extends WordPress_Sniff. + * @since 0.7.0 This class now extends the WordPressCS native `Sniff` class. * @since 0.13.0 Class name changed: this class is now namespaced. * * Last synced with base class 2017-01-15 at commit b024ad84656c37ef5733c6998ebc1e60957b2277. From 595da31d588bf1596b40f28fd3494c85f516ea98 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 05:23:20 +0100 Subject: [PATCH 055/241] WPCS 2.0.0: Remove the PHPCSAliases file After extensive testing based on issues which were previously reported, I've concluded that the `PHPCSAliases.php` file can now be safely removed. Test setup I've used to confirm this: * Clean Composer install of PHPCS + WPCS _without the `installed_paths` config directive being set. ```json { "require": {}, "require-dev": { "squizlabs/php_codesniffer": "^3.3", "wp-coding-standards/wpcs": "^1.1" } } ``` * Basic PHPCS ruleset: ```xml . vendor/* ``` * A PHP test file which would generate issues. Tests I've run: * Running `vendor/bin/phpcs` on the above (which would be with WPCS 1.2.1) works fine. * Changed the `config` directive value to point to my local WPCS dev install: `` * Tested again against the `develop` branch, still was working fine. * Now we get to the interesting part: changed to this branch and ran it again. Still working fine. * Changed the `` to `` and still working fine. * Changed the `` to ``, i.e. not a registered standard, but a subcategory and still working fine. Based on all this, I'm concluding that the WPCS autoloader in the PHPCSAlias file is no longer needed and can now be safely removed. Refs: * 1087 * squizlabs/PHP_CodeSniffer 1591 --- WordPress-Core/ruleset.xml | 2 -- WordPress-Extra/ruleset.xml | 2 -- WordPress/PHPCSAliases.php | 46 ------------------------------------- WordPress/ruleset.xml | 2 -- 4 files changed, 52 deletions(-) delete mode 100644 WordPress/PHPCSAliases.php diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index 4d4f5af8e4..045d5de7f5 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -3,8 +3,6 @@ Non-controversial generally-agreed upon WordPress Coding Standards - ./../WordPress/PHPCSAliases.php - diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index 001241e5c1..ad65a65568 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -3,8 +3,6 @@ Best practices beyond core WordPress Coding Standards - ./../WordPress/PHPCSAliases.php - - + + diff --git a/WordPress/Sniffs/PHP/TypeCastsSniff.php b/WordPress/Sniffs/PHP/TypeCastsSniff.php index 166c0f5a1f..1d3c7663e9 100644 --- a/WordPress/Sniffs/PHP/TypeCastsSniff.php +++ b/WordPress/Sniffs/PHP/TypeCastsSniff.php @@ -16,8 +16,6 @@ * Verifies the correct usage of type cast keywords. * * Type casts should be: - * - lowercase; - * - short form, i.e. (bool) not (boolean); * - normalized, i.e. (float) not (real). * * Additionally, the use of the (unset) and (binary) casts is discouraged. @@ -27,6 +25,8 @@ * @package WPCS\WordPressCodingStandards * * @since 1.2.0 + * @since 2.0.0 No longer checks that type casts are lowercase or short form. + * Relevant PHPCS native sniffs have been included in the rulesets instead. */ class TypeCastsSniff extends Sniff { @@ -36,10 +36,12 @@ class TypeCastsSniff extends Sniff { * @return array */ public function register() { - $targets = Tokens::$castTokens; - unset( $targets[ \T_ARRAY_CAST ], $targets[ \T_OBJECT_CAST ] ); - - return $targets; + return array( + \T_DOUBLE_CAST, + \T_UNSET_CAST, + \T_STRING_CAST, + \T_BINARY_CAST, + ); } /** @@ -55,39 +57,7 @@ public function process_token( $stackPtr ) { $typecast = str_replace( ' ', '', $this->tokens[ $stackPtr ]['content'] ); $typecast_lc = strtolower( $typecast ); - $this->phpcsFile->recordMetric( $stackPtr, 'Typecast encountered', $typecast ); - switch ( $token_code ) { - case \T_BOOL_CAST: - if ( '(bool)' !== $typecast_lc ) { - $fix = $this->phpcsFile->addFixableError( - 'Short form type keywords must be used; expected "(bool)" but found "%s"', - $stackPtr, - 'LongBoolFound', - array( $typecast ) - ); - - if ( true === $fix ) { - $this->phpcsFile->fixer->replaceToken( $stackPtr, '(bool)' ); - } - } - break; - - case \T_INT_CAST: - if ( '(int)' !== $typecast_lc ) { - $fix = $this->phpcsFile->addFixableError( - 'Short form type keywords must be used; expected "(int)" but found "%s"', - $stackPtr, - 'LongIntFound', - array( $typecast ) - ); - - if ( true === $fix ) { - $this->phpcsFile->fixer->replaceToken( $stackPtr, '(int)' ); - } - } - break; - case \T_DOUBLE_CAST: if ( '(float)' !== $typecast_lc ) { $fix = $this->phpcsFile->addFixableError( diff --git a/WordPress/Tests/PHP/TypeCastsUnitTest.inc b/WordPress/Tests/PHP/TypeCastsUnitTest.inc index 8d0fd9e74f..e5b6f78b92 100644 --- a/WordPress/Tests/PHP/TypeCastsUnitTest.inc +++ b/WordPress/Tests/PHP/TypeCastsUnitTest.inc @@ -1,16 +1,12 @@ 1, - 13 => 1, - 14 => 1, - 15 => 1, - 32 => 1, - 33 => 1, - 34 => 1, - 35 => 1, + 10 => 1, + 11 => 1, + 26 => 1, + 27 => 1, ); } @@ -46,12 +42,12 @@ public function getErrorList() { */ public function getWarningList() { return array( - 18 => 1, - 19 => 1, - 20 => ( version_compare( PHPCSHelper::get_version(), '3.4.0', '<' ) === true ? 0 : 1 ), - 21 => 1, - 36 => 1, - 37 => 1, + 14 => 1, + 15 => 1, + 16 => ( version_compare( PHPCSHelper::get_version(), '3.4.0', '<' ) === true ? 0 : 1 ), + 17 => 1, + 28 => 1, + 29 => 1, ); } } From abab1cb8f3156a3c5a4f81a2c24d921f0348853d Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 25 Dec 2018 05:50:14 +0100 Subject: [PATCH 057/241] OperatorSpacing: check spacing around `instanceof` operator PHPCS 3.3.0 introduces a `PSR12.Operators.OperatorSpacing` sniff. I've investigated whether that sniff would be a better sniff to extend for the `WordPress.WhiteSpace.OperatorSpacing` sniff than the `Squiz.WhiteSpace.OperatorSpacing` sniff which is currently being extended and have concluded that it is not for the following reason: * The PSR12 sniff demands _at least_ one space instead of _exactly_ one space (both allow for new lines with the correct properties). All the same, the `PSR12` sniff did include an additional token - `T_INSTANCEOF` - which makes sense to add to the WPCS sniff. Includes unit tests. --- WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php | 1 + WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc | 4 ++++ WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed | 4 ++++ WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php | 1 + 4 files changed, 10 insertions(+) diff --git a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php index 4dedca618a..26c12e20b1 100644 --- a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php @@ -54,6 +54,7 @@ class OperatorSpacingSniff extends PHPCS_Squiz_OperatorSpacingSniff { public function register() { $tokens = parent::register(); $tokens[ \T_BOOLEAN_NOT ] = \T_BOOLEAN_NOT; + $tokens[ \T_INSTANCEOF ] = \T_INSTANCEOF; $logical_operators = Tokens::$booleanOperators; // Using array union to auto-dedup. diff --git a/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc b/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc index bad89cc0af..0f3f6d5a9e 100644 --- a/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc +++ b/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc @@ -64,3 +64,7 @@ if ( $a === $b if ( $a === $b or $b === $c ) {} + +// Instanceof +if ( MyClass instanceof SomeOtherClass ) {} +if ( MyClass instanceof SomeOtherClass ) {} diff --git a/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed b/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed index 4a3214f57e..21854ae661 100644 --- a/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed +++ b/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed @@ -64,3 +64,7 @@ if ( $a === $b if ( $a === $b or $b === $c ) {} + +// Instanceof +if ( MyClass instanceof SomeOtherClass ) {} +if ( MyClass instanceof SomeOtherClass ) {} diff --git a/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php index ff7325c071..421c61fd8d 100644 --- a/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php +++ b/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php @@ -42,6 +42,7 @@ public function getErrorList() { 49 => 2, 50 => 2, 51 => 2, + 69 => 2, ); } From b1451f7773f92c3e66c91aa47337cc5229e82cde Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 23 Dec 2018 14:58:00 +0100 Subject: [PATCH 058/241] README: improve instructions about using PHPCompatibility (PHPCS 3.0+) PHPCS 3.0.0 introduced an `` directive as a counter-part to the pre-existing ``. This allows to easily limit the PHPCompatibility sniffs to PHP files only, while still allowing the rest of the ruleset to be applied to both PHP, JS as well as CSS files. --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c4b644d5d2..b2662a15e1 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,13 @@ The [PHPCompatibility](https://github.com/PHPCompatibility/PHPCompatibility) sni The [PHPCompatibilityWP](https://github.com/PHPCompatibility/PHPCompatibilityWP) ruleset is based on PHPCompatibility, but specifically crafted to prevent false positives for projects which expect to run within the context of WordPress, i.e. core, plugins and themes. -Install either as a separate ruleset and either run it separately against your code or add it to your custom ruleset. +Install either as a separate ruleset and run it separately against your code or add it to your custom ruleset, like so: +```xml + + + *\.php$ + +``` Whichever way you run it, do make sure you set the `testVersion` to run the sniffs against. The `testVersion` determines for which PHP versions you will receive compatibility information. The recommended setting for this at this moment is `5.2-` to support the same PHP versions as WordPress Core supports. From f99585eef830d7701e803be979742e8692e2d1bd Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 25 Dec 2018 15:14:52 +0100 Subject: [PATCH 059/241] WPCS native PHPCS ruleset: minor tweaks The `basepath` and `parallel` options were introduced in PHPCS 3.0 and can now be enabled for the WPCS native PHPCS checking. And as WPCS 2.0.0 drops the `VIP` ruleset, we can now include the `WordPress` ruleset instead of including the `WordPress-Extra` + `WordPress-Docs` rulesets separately. --- .phpcs.xml.dist | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 0bc9d6c10e..ef779c2dc3 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -7,19 +7,19 @@ + + /bin/class-ruleset-test.php */vendor/* - + - - From e3a3fec1a731de14f9d70b50ff1a5cfe086bd075 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 25 Dec 2018 16:24:05 +0100 Subject: [PATCH 060/241] PreparedSQL: use unique errorcode for messages The `WordPress.DB.PreparedSQL` sniff contains two different error messages, but didn't use unique error codes for these. --- WordPress/Sniffs/DB/PreparedSQLSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/Sniffs/DB/PreparedSQLSniff.php b/WordPress/Sniffs/DB/PreparedSQLSniff.php index 1f8fa9b3bc..80f2418b9c 100644 --- a/WordPress/Sniffs/DB/PreparedSQLSniff.php +++ b/WordPress/Sniffs/DB/PreparedSQLSniff.php @@ -151,7 +151,7 @@ function ( $symbol ) { $this->phpcsFile->addError( 'Use placeholders and $wpdb->prepare(); found interpolated variable $%s at %s', $this->i, - 'NotPrepared', + 'InterpolatedNotPrepared', array( $bad_variable, $this->tokens[ $this->i ]['content'], From aa0eb35a461d437f8021b55f8fc74a1e46fa9af5 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 25 Dec 2018 16:29:23 +0100 Subject: [PATCH 061/241] GlobalVariablesOverride: minor error code adjustment This is more a cosmetic change than anything else. The sniff name for this sniff got changed in WPCS 1.0.0 from `GlobalVariables` to `GlobalVariablesOverride`, however, the error code also contains `override` which is now redundant. This is a BC-break and as the change is cosmetic, is a bit disputable to make this change. However, as the sniff only contains one error code, excluding the whole sniff had the same effect as excluding the single error code, so with a bit of luck, not that many people will have excluded this based on the error code. --- WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php index 615cec925c..4485c027ad 100644 --- a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php +++ b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php @@ -373,7 +373,7 @@ protected function add_error( $stackPtr, $data = array() ) { $this->phpcsFile->addError( 'Overriding WordPress globals is prohibited. Found assignment to %s', $stackPtr, - 'OverrideProhibited', + 'Prohibited', $data ); } From c058b4dd4ac59d158ca2cf348590e0237eed2e37 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 25 Dec 2018 17:36:12 +0100 Subject: [PATCH 062/241] PHPCSHelper: clean up Follow-up on PR 1560. As the PHPCS 2.x code has been removed, we can now use a `use` statement for the PHPCS 3.x `PHP_CodeSniffer\Config` class. --- WordPress/PHPCSHelper.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/WordPress/PHPCSHelper.php b/WordPress/PHPCSHelper.php index bdabb35bf1..1e79685f46 100644 --- a/WordPress/PHPCSHelper.php +++ b/WordPress/PHPCSHelper.php @@ -9,6 +9,7 @@ namespace WordPressCS\WordPress; +use PHP_CodeSniffer\Config; use PHP_CodeSniffer\Files\File; /** @@ -33,7 +34,7 @@ class PHPCSHelper { * @return string */ public static function get_version() { - return \PHP_CodeSniffer\Config::VERSION; + return Config::VERSION; } /** @@ -50,7 +51,7 @@ public static function get_version() { * This will not write the config data to the config file. */ public static function set_config_data( $key, $value, $temp = false ) { - \PHP_CodeSniffer\Config::setConfigData( $key, $value, $temp ); + Config::setConfigData( $key, $value, $temp ); } /** @@ -63,7 +64,7 @@ public static function set_config_data( $key, $value, $temp = false ) { * @return string|null */ public static function get_config_data( $key ) { - return \PHP_CodeSniffer\Config::getConfigData( $key ); + return Config::getConfigData( $key ); } /** @@ -98,7 +99,7 @@ public static function ignore_annotations( File $phpcsFile = null ) { if ( isset( $phpcsFile, $phpcsFile->config->annotations ) ) { return ! $phpcsFile->config->annotations; } else { - $annotations = \PHP_CodeSniffer\Config::getConfigData( 'annotations' ); + $annotations = Config::getConfigData( 'annotations' ); if ( isset( $annotations ) ) { return ! $annotations; } From c3872c3c5396a50cf35a7c01d27f41f74ac1911f Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 25 Dec 2018 17:45:48 +0100 Subject: [PATCH 063/241] CS: minor code clean up Removing: * Unused `use` statement (no longer used after code removal). * Some unnecessary interim variables (no longer needed as code which added to the variables has been removed). * Unnecessary `return` statement. * Simplify an (re-)assignment to the same variable. * Remove an unused function parameter (no longer used after previous refactor of the function code). --- WordPress/AbstractFunctionRestrictionsSniff.php | 2 -- WordPress/Sniffs/DB/PreparedSQLSniff.php | 2 +- .../NamingConventions/ValidVariableNameSniff.php | 11 +++++------ WordPress/Sniffs/PHP/TypeCastsSniff.php | 1 - WordPress/Sniffs/Security/EscapeOutputSniff.php | 4 +--- .../NamingConventions/ValidVariableNameUnitTest.php | 4 +--- .../Tests/WhiteSpace/PrecisionAlignmentUnitTest.php | 4 +--- 7 files changed, 9 insertions(+), 19 deletions(-) diff --git a/WordPress/AbstractFunctionRestrictionsSniff.php b/WordPress/AbstractFunctionRestrictionsSniff.php index ea2e50ae23..5b11af4dad 100644 --- a/WordPress/AbstractFunctionRestrictionsSniff.php +++ b/WordPress/AbstractFunctionRestrictionsSniff.php @@ -302,8 +302,6 @@ public function process_matched_token( $stackPtr, $group_name, $matched_content $this->string_to_errorcode( $group_name . '_' . $matched_content ), array( $matched_content ) ); - - return; } /** diff --git a/WordPress/Sniffs/DB/PreparedSQLSniff.php b/WordPress/Sniffs/DB/PreparedSQLSniff.php index 1f8fa9b3bc..cb48f508ff 100644 --- a/WordPress/Sniffs/DB/PreparedSQLSniff.php +++ b/WordPress/Sniffs/DB/PreparedSQLSniff.php @@ -102,7 +102,7 @@ class PreparedSQLSniff extends Sniff { */ public function register() { - $this->ignored_tokens = $this->ignored_tokens + Tokens::$emptyTokens; + $this->ignored_tokens += Tokens::$emptyTokens; return array( \T_VARIABLE, diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index 8c9f6a891d..2b39460432 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -114,7 +114,7 @@ protected function processVariable( File $phpcs_file, $stack_ptr ) { } // Merge any custom variables with the defaults. - $this->mergeWhiteList( $phpcs_file ); + $this->mergeWhiteList(); // Likewise if it is a mixed-case var used by WordPress core. if ( isset( $this->wordpress_mixed_case_vars[ $var_name ] ) ) { @@ -203,7 +203,7 @@ protected function processMemberVar( File $phpcs_file, $stack_ptr ) { } // Merge any custom variables with the defaults. - $this->mergeWhiteList( $phpcs_file ); + $this->mergeWhiteList(); $error_data = array( $var_name ); if ( ! isset( $this->whitelisted_mixed_case_member_var_names[ $var_name ] ) && false === self::isSnakeCase( $var_name ) ) { @@ -228,7 +228,7 @@ protected function processVariableInString( File $phpcs_file, $stack_ptr ) { if ( preg_match_all( '|[^\\\]\${?([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)|', $tokens[ $stack_ptr ]['content'], $matches ) > 0 ) { // Merge any custom variables with the defaults. - $this->mergeWhiteList( $phpcs_file ); + $this->mergeWhiteList(); foreach ( $matches[1] as $var_name ) { // If it's a php reserved var, then its ok. @@ -265,12 +265,11 @@ public static function isSnakeCase( $var_name ) { * if we haven't already. * * @since 0.10.0 - * - * @param \PHP_CodeSniffer\Files\File $phpcs_file The file being scanned. + * @since 2.0.0 Removed unused $phpcs_file parameter. * * @return void */ - protected function mergeWhiteList( File $phpcs_file ) { + protected function mergeWhiteList() { if ( $this->customPropertiesWhitelist !== $this->addedCustomProperties['properties'] ) { // Fix property potentially passed as comma-delimited string. $customProperties = Sniff::merge_custom_array( $this->customPropertiesWhitelist, array(), false ); diff --git a/WordPress/Sniffs/PHP/TypeCastsSniff.php b/WordPress/Sniffs/PHP/TypeCastsSniff.php index 1d3c7663e9..47376ff39c 100644 --- a/WordPress/Sniffs/PHP/TypeCastsSniff.php +++ b/WordPress/Sniffs/PHP/TypeCastsSniff.php @@ -10,7 +10,6 @@ namespace WordPressCS\WordPress\Sniffs\PHP; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer\Util\Tokens; /** * Verifies the correct usage of type cast keywords. diff --git a/WordPress/Sniffs/Security/EscapeOutputSniff.php b/WordPress/Sniffs/Security/EscapeOutputSniff.php index a4dd060cb2..9a1feaa857 100644 --- a/WordPress/Sniffs/Security/EscapeOutputSniff.php +++ b/WordPress/Sniffs/Security/EscapeOutputSniff.php @@ -169,15 +169,13 @@ class EscapeOutputSniff extends Sniff { */ public function register() { - $tokens = array( + return array( \T_ECHO, \T_PRINT, \T_EXIT, \T_STRING, \T_OPEN_TAG_WITH_ECHO, ); - - return $tokens; } /** diff --git a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php index 792d62c3e6..5891f54181 100644 --- a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php +++ b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php @@ -27,7 +27,7 @@ class ValidVariableNameUnitTest extends AbstractSniffUnitTest { * @return array => */ public function getErrorList() { - $errors = array( + return array( 2 => 1, 5 => 1, 8 => 1, @@ -74,8 +74,6 @@ public function getErrorList() { 145 => 1, 160 => 1, ); - - return $errors; } /** diff --git a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php index a928640dc3..1da0d8fbeb 100644 --- a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php +++ b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php @@ -84,7 +84,7 @@ public function getWarningList( $testFile = '' ) { ); case 'PrecisionAlignmentUnitTest.5.inc': - $warnings = array( + return array( 9 => 1, 14 => 1, 19 => 1, @@ -98,8 +98,6 @@ public function getWarningList( $testFile = '' ) { 58 => 1, ); - return $warnings; - case 'PrecisionAlignmentUnitTest.6.inc': return array( 4 => 1, From e0966832668c3f16f1ea0bab4bfc92d46bdc20d3 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 25 Dec 2018 16:34:58 +0100 Subject: [PATCH 064/241] DiscouragedConstants: make the error codes more modular This sniff is based on an array of constants the sniff looks for. Previously, the sniff had two distinct error codes for the different use-cases in which the constant could be found (use of vs declaration). This change makes the error codes unique to the constant found, making it easier to silence the error message(s) for just one particular constant. --- WordPress/Sniffs/WP/DiscouragedConstantsSniff.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php b/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php index e55254b749..00e1e8efa8 100644 --- a/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php +++ b/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php @@ -173,7 +173,7 @@ public function process_arbitrary_tstring( $stackPtr ) { $this->phpcsFile->addWarning( 'Found usage of constant "%s". Use %s instead.', $stackPtr, - 'UsageFound', + $this->string_to_errorcode( $content . 'UsageFound' ), array( $content, $this->discouraged_constants[ $content ], @@ -208,7 +208,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p $this->phpcsFile->addWarning( 'Found declaration of constant "%s". Use %s instead.', $stackPtr, - 'DeclarationFound', + $this->string_to_errorcode( $raw_content . 'DeclarationFound' ), array( $raw_content, $this->discouraged_constants[ $raw_content ], From a22db480799242deaf941bc16d6b4bf649422b7a Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 22 Dec 2018 17:06:56 +0100 Subject: [PATCH 065/241] Contributing: update the documentation about installing and running the unit tests --- .github/CONTRIBUTING.md | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index babd323861..2a6e2d2496 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -49,16 +49,22 @@ When you introduce new `public` sniff properties, or your sniff extends a class * PHP_CodeSniffer 3.3.1 or higher * PHPUnit 4.x, 5.x, 6.x or 7.x -The WordPress Coding Standards use the PHP_CodeSniffer native unit test suite for unit testing the sniffs. +The WordPress Coding Standards use the `PHP_CodeSniffer` native unit test suite for unit testing the sniffs. -Presuming you have installed PHP_CodeSniffer and the WordPress-Coding-Standards as [noted in the README](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards#how-to-use-this), all you need now is `PHPUnit`. +Presuming you have installed `PHP_CodeSniffer` and the WordPress-Coding-Standards as [noted in the README](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards#how-to-use-this), all you need now is `PHPUnit`. -N.B.: If you installed WPCS using Composer, make sure you used `--prefer-source` or run `composer install --prefer-source` now to make sure the unit tests are available. +> N.B.: If you installed WPCS using Composer, make sure you used `--prefer-source` or run `composer install --prefer-source` now to make sure the unit tests are available. +> Other than that, you're all set already as Composer will have installed PHPUnit for you. If you already have PHPUnit installed on your system: Congrats, you're all set. -If not, you can navigate to the directory where the `PHP_CodeSniffer` repo is checked out and do `composer install` to install the `dev` dependencies. -Alternatively, you can [install PHPUnit](https://phpunit.readthedocs.io/en/7.4/installation.html) as a PHAR file. +## Installing PHPUnit + +N.B.: _If you used Composer to install the WordPress Coding Standards, you can skip this step._ + +You can either navigate to the directory where the `PHP_CodeSniffer` repo is checked out and do `composer install` to install the `dev` dependencies or you can [install PHPUnit](https://phpunit.readthedocs.io/en/7.4/installation.html) as a PHAR file. + +You may want to add the directory where PHPUnit is installed to a `PATH` environment variable for your operating system to make the command available everywhere on your system. ## Before running the unit tests @@ -66,7 +72,8 @@ N.B.: _If you used Composer to install the WordPress Coding Standards, you can s For the unit tests to work, you need to make sure PHPUnit can find your `PHP_CodeSniffer` install. -The easiest way to do this is to add a `phpunit.xml` file to the root of your WPCS installation and set a `PHPCS_DIR` environment variable from within this file. Copy the existing `phpunit.xml.dist` file and add the below `` directive within the `` section. Make sure to adjust the path to reflect your local setup. +The easiest way to do this is to add a `phpunit.xml` file to the root of your WPCS installation and set a `PHPCS_DIR` environment variable from within this file. +Copy the existing `phpunit.xml.dist` file and add the below `` directive within the `` section. Make sure to adjust the path to reflect your local setup. ```xml @@ -75,7 +82,7 @@ The easiest way to do this is to add a `phpunit.xml` file to the root of your WP ## Running the unit tests -* Make sure you have registered the directory in which you installed WPCS with PHPCS using; +* If you didn't install WPCS using Composer, make sure you have registered the directory in which you installed WPCS with PHPCS using: ```sh phpcs --config-set installed_paths path/to/WPCS ``` @@ -95,13 +102,13 @@ PHPUnit 7.5.0 by Sebastian Bergmann and contributors. Runtime: PHP 7.2.13 Configuration: /WordPressCS/phpunit.xml -............................................................ 60 / 60 (100%) +........................................................ 56 / 56 (100%) -156 sniff test files generated 490 unique error codes; 59 were fixable (12.04%) +152 sniff test files generated 487 unique error codes; 52 were fixable (10.68%) -Time: 18.02 seconds, Memory: 22.00MB +Time: 21.36 seconds, Memory: 22.00MB -OK (60 tests, 0 assertions) +OK (56 tests, 0 assertions) ``` [![asciicast](https://asciinema.org/a/98078.png)](https://asciinema.org/a/98078) From 46e1a8ae68c0e0d308ece69e29c3dba549a7f159 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 27 Dec 2018 03:57:29 +0100 Subject: [PATCH 066/241] ValidFunctionName: sync in fixes from upstream This adds similar fixes which were made to the upstream `PEAR` sniff to the WPCS native version of the sniff in as far applicable. * The `WordPress.NamingConventions.ValidFunctionName` sniff would throw the same error twice for functions in nested classes. The reasoning and solution used is the same as applied upstream. > Turns out the `processTokensWithinScope()` method gets called for each whitelisted scope a `T_FUNCTION` token exists in. > > In effect, this means that the first time it gets called for the `nestedFunction()` method, it is because it is within the scope of the `Nested` class, the second time the function gets called, it is for the method being in the scope of the anonymous class. > > The fix I've now applied checks that the scope for which the method is called is actually the deepest scope first and bows out if it's not. This fixes the error messages being thrown twice. * For methods in anonymous classes, the error message would read `Method name "nestedFunction" in class is not ....` (take note of the missing class name) which could be considered confusing. I've changed this to now read: `read `Method name "nestedFunction" in class [Anonymous class] is not ` * Class and method names in PHP are case _in_sensitive. While the sniff took that into account for the magic methods, it did not when checking for PHP4 style constructors/destructors. This has now been fixed by lowercasing both the class name as well as the function name before comparing them. Includes unit tests. --- .../ValidFunctionNameSniff.php | 33 +++++++++++++++---- .../ValidFunctionNameUnitTest.inc | 14 ++++++++ .../ValidFunctionNameUnitTest.php | 2 ++ 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php index 3ee7c2ab31..96db318d9f 100644 --- a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -22,7 +22,7 @@ * @since 0.1.0 * @since 0.13.0 Class name changed: this class is now namespaced. * - * Last synced with parent class July 2016 up to commit 4fea2e651109e41066a81e22e004d851fb1287f6. + * Last synced with parent class December 2018 up to commit ee167761d7756273b8ad0ad68bf3db1f2c211bb8. * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidFunctionNameSniff.php * * {@internal While this class extends the PEAR parent, it does not actually use the checks @@ -75,10 +75,12 @@ protected function processTokenOutsideScope( File $phpcsFile, $stackPtr ) { return; } + $functionNameLc = strtolower( $functionName ); + // Is this a magic function ? I.e., it is prefixed with "__" ? // Outside class scope this basically just means __autoload(). if ( 0 === strpos( $functionName, '__' ) ) { - $magicPart = strtolower( substr( $functionName, 2 ) ); + $magicPart = substr( $functionNameLc, 2 ); if ( isset( $this->magicFunctions[ $magicPart ] ) ) { return; } @@ -88,7 +90,7 @@ protected function processTokenOutsideScope( File $phpcsFile, $stackPtr ) { $phpcsFile->addError( $error, $stackPtr, 'FunctionDoubleUnderscore', $errorData ); } - if ( strtolower( $functionName ) !== $functionName ) { + if ( $functionNameLc !== $functionName ) { $error = 'Function name "%s" is not in snake case format, try "%s"'; $errorData = array( $functionName, @@ -109,6 +111,17 @@ protected function processTokenOutsideScope( File $phpcsFile, $stackPtr ) { * @return void */ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currScope ) { + + $tokens = $phpcsFile->getTokens(); + + // Determine if this is a function which needs to be examined. + $conditions = $tokens[ $stackPtr ]['conditions']; + end( $conditions ); + $deepestScope = key( $conditions ); + if ( $deepestScope !== $currScope ) { + return; + } + $methodName = $phpcsFile->getDeclarationName( $stackPtr ); if ( ! isset( $methodName ) ) { @@ -117,6 +130,12 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco } $className = $phpcsFile->getDeclarationName( $currScope ); + if ( isset( $className ) === false ) { + $className = '[Anonymous Class]'; + } + + $methodNameLc = strtolower( $methodName ); + $classNameLc = strtolower( $className ); // Ignore special functions. if ( '' === ltrim( $methodName, '_' ) ) { @@ -124,12 +143,12 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco } // PHP4 constructors are allowed to break our rules. - if ( $methodName === $className ) { + if ( $methodNameLc === $classNameLc ) { return; } // PHP4 destructors are allowed to break our rules. - if ( '_' . $className === $methodName ) { + if ( '_' . $classNameLc === $methodNameLc ) { return; } @@ -143,7 +162,7 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco // Is this a magic method ? I.e. is it prefixed with "__" ? if ( 0 === strpos( $methodName, '__' ) ) { - $magicPart = strtolower( substr( $methodName, 2 ) ); + $magicPart = substr( $methodNameLc, 2 ); if ( isset( $this->magicMethods[ $magicPart ] ) || isset( $this->methodsDoubleUnderscore[ $magicPart ] ) ) { return; } @@ -154,7 +173,7 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco } // Check for all lowercase. - if ( strtolower( $methodName ) !== $methodName ) { + if ( $methodNameLc !== $methodName ) { $error = 'Method name "%s" in class %s is not in snake case format, try "%s"'; $errorData = array( $methodName, diff --git a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc index 228d4348d0..642fe78a80 100644 --- a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc +++ b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc @@ -109,3 +109,17 @@ function __MyTemplateTags() {} // Bad x 2. interface MyInterface extends InterfaceA, InterfaceB { function __MyTemplateTags(); // OK. } + +class Nested { + public function get_anonymous_class() { + return new class() { + public function nestedFunction() {} + protected function __something() {} + }; + } +} + +abstract class My_Class { + public function my_Class() {} + public function _MY_CLASS() {} +} diff --git a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php index dc239337bc..10649e220d 100644 --- a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php +++ b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php @@ -44,6 +44,8 @@ public function getErrorList() { 88 => 2, 89 => 2, 106 => 2, + 116 => 1, + 117 => 1, ); } From e7d544700b84c69598b57611e3ed955b57dfd3a5 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 27 Dec 2018 04:21:00 +0100 Subject: [PATCH 067/241] ValidFunctionName: remove redundant code As the "method name" check exist out if it finds an extended class or implemented interface anyway, checking the name of underscore magic methods which are only used in extended classes is redundant. --- .../ValidFunctionNameSniff.php | 25 +------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php index 96db318d9f..298c14681d 100644 --- a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -30,29 +30,6 @@ */ class ValidFunctionNameSniff extends PHPCS_PEAR_ValidFunctionNameSniff { - /** - * Additional double underscore prefixed methods specific to certain PHP native extensions. - * - * Currently only handles the SoapClient Extension. - * - * @link http://php.net/manual/en/class.soapclient.php - * - * @var array => - */ - private $methodsDoubleUnderscore = array( - 'doRequest' => 'SoapClient', - 'getFunctions' => 'SoapClient', - 'getLastRequest' => 'SoapClient', - 'getLastRequestHeaders' => 'SoapClient', - 'getLastResponse' => 'SoapClient', - 'getLastResponseHeaders' => 'SoapClient', - 'getTypes' => 'SoapClient', - 'setCookie' => 'SoapClient', - 'setLocation' => 'SoapClient', - 'setSoapHeaders' => 'SoapClient', - 'soapCall' => 'SoapClient', - ); - /** * Processes the tokens outside the scope. * @@ -163,7 +140,7 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco // Is this a magic method ? I.e. is it prefixed with "__" ? if ( 0 === strpos( $methodName, '__' ) ) { $magicPart = substr( $methodNameLc, 2 ); - if ( isset( $this->magicMethods[ $magicPart ] ) || isset( $this->methodsDoubleUnderscore[ $magicPart ] ) ) { + if ( isset( $this->magicMethods[ $magicPart ] ) ) { return; } From 7a013b05604126b3ba67ca810bd269f0b411c54c Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 27 Dec 2018 18:39:54 +0100 Subject: [PATCH 068/241] ValidFunctionName: move `get_name_suggestion()` to the Sniff base class ... rename it to `get_snake_case_name_suggestion()` and make it a static method so it's also available to sniffs extending upstream sniffs. --- WordPress/Sniff.php | 19 +++++++++++++++++ .../ValidFunctionNameSniff.php | 21 +++++-------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 245f7d8443..721e85ecba 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -942,6 +942,25 @@ protected function string_to_errorcode( $base_string ) { return preg_replace( '`[^a-z0-9_]`i', '_', $base_string ); } + /** + * Transform the name of a PHP construct (function, variable etc) to one in snake_case. + * + * @since 2.0.0 Moved from the `WordPress.NamingConventions.ValidFunctionName` sniff + * to this class, renamed from `get_name_suggestion` and made static + * so it can also be used by classes which don't extend this class. + * + * @param string $name The construct name. + * + * @return string + */ + public static function get_snake_case_name_suggestion( $name ) { + $suggested = preg_replace( '`([A-Z])`', '_$1', $name ); + $suggested = strtolower( $suggested ); + $suggested = str_replace( '__', '_', $suggested ); + $suggested = trim( $suggested, '_' ); + return $suggested; + } + /** * Merge a pre-set array with a ruleset provided array. * diff --git a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php index 298c14681d..645bed3d9d 100644 --- a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -11,6 +11,7 @@ use PHP_CodeSniffer\Standards\PEAR\Sniffs\NamingConventions\ValidFunctionNameSniff as PHPCS_PEAR_ValidFunctionNameSniff; use PHP_CodeSniffer\Files\File; +use WordPressCS\WordPress\Sniff; /** * Enforces WordPress function name and method name format, based upon Squiz code. @@ -21,6 +22,8 @@ * * @since 0.1.0 * @since 0.13.0 Class name changed: this class is now namespaced. + * @since 2.0.0 The `get_name_suggestion()` method has been moved to the + * WordPress native `Sniff` base class as `get_snake_case_name_suggestion()`. * * Last synced with parent class December 2018 up to commit ee167761d7756273b8ad0ad68bf3db1f2c211bb8. * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -71,7 +74,7 @@ protected function processTokenOutsideScope( File $phpcsFile, $stackPtr ) { $error = 'Function name "%s" is not in snake case format, try "%s"'; $errorData = array( $functionName, - $this->get_name_suggestion( $functionName ), + Sniff::get_snake_case_name_suggestion( $functionName ), ); $phpcsFile->addError( $error, $stackPtr, 'FunctionNameInvalid', $errorData ); } @@ -155,24 +158,10 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco $errorData = array( $methodName, $className, - $this->get_name_suggestion( $methodName ), + Sniff::get_snake_case_name_suggestion( $methodName ), ); $phpcsFile->addError( $error, $stackPtr, 'MethodNameInvalid', $errorData ); } } - /** - * Transform the existing function/method name to one which complies with the naming conventions. - * - * @param string $name The function/method name. - * @return string - */ - protected function get_name_suggestion( $name ) { - $suggested = preg_replace( '/([A-Z])/', '_$1', $name ); - $suggested = strtolower( $suggested ); - $suggested = str_replace( '__', '_', $suggested ); - $suggested = trim( $suggested, '_' ); - return $suggested; - } - } From ccae00cfc043fcc58025ae4388b644ed89d8b9e2 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 27 Dec 2018 18:54:30 +0100 Subject: [PATCH 069/241] ValidVariableName: adjust error messages and codes * Adjusts the error messages to include an alternative name suggestion in snake_case. * Adds back the previously stripped `$` to the variable name for the error message. * Adjusts the error messages the sniff throws to be more consistent. Fixes 1280 --- .../ValidVariableNameSniff.php | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index 2b39460432..0b5cb047f3 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -23,7 +23,8 @@ * * @since 0.9.0 * @since 0.13.0 Class name changed: this class is now namespaced. - * @since 2.0.0 Defers to the upstream `$phpReservedVars` property. + * @since 2.0.0 - Defers to the upstream `$phpReservedVars` property. + * - Now offers name suggestions for variables in violation. * * Last synced with base class June 2018 at commit 78ddbae97cac078f09928bf89e3ab9e53ad2ace0. * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -139,9 +140,12 @@ protected function processVariable( File $phpcs_file, $stack_ptr ) { } if ( ! isset( $this->whitelisted_mixed_case_member_var_names[ $obj_var_name ] ) && self::isSnakeCase( $obj_var_name ) === false ) { - $error = 'Object property "%s" is not in valid snake_case format'; - $data = array( $original_var_name ); - $phpcs_file->addError( $error, $var, 'NotSnakeCaseMemberVar', $data ); + $error = 'Object property "$%s" is not in valid snake_case format, try "$%s"'; + $data = array( + $original_var_name, + Sniff::get_snake_case_name_suggestion( $original_var_name ), + ); + $phpcs_file->addError( $error, $var, 'UsedPropertyNotSnakeCase', $data ); } } } @@ -165,15 +169,18 @@ protected function processVariable( File $phpcs_file, $stack_ptr ) { if ( self::isSnakeCase( $var_name ) === false ) { if ( $in_class && ! isset( $this->whitelisted_mixed_case_member_var_names[ $var_name ] ) ) { - $error = 'Object property "%s" is not in valid snake_case format'; - $error_name = 'NotSnakeCaseMemberVar'; + $error = 'Object property "$%s" is not in valid snake_case format, try "$%s"'; + $error_name = 'UsedPropertyNotSnakeCase'; } elseif ( ! $in_class ) { - $error = 'Variable "%s" is not in valid snake_case format'; - $error_name = 'NotSnakeCase'; + $error = 'Variable "$%s" is not in valid snake_case format, try "$%s"'; + $error_name = 'VariableNotSnakeCase'; } if ( isset( $error, $error_name ) ) { - $data = array( $original_var_name ); + $data = array( + $original_var_name, + Sniff::get_snake_case_name_suggestion( $original_var_name ), + ); $phpcs_file->addError( $error, $stack_ptr, $error_name, $data ); } } @@ -205,10 +212,13 @@ protected function processMemberVar( File $phpcs_file, $stack_ptr ) { // Merge any custom variables with the defaults. $this->mergeWhiteList(); - $error_data = array( $var_name ); if ( ! isset( $this->whitelisted_mixed_case_member_var_names[ $var_name ] ) && false === self::isSnakeCase( $var_name ) ) { - $error = 'Member variable "%s" is not in valid snake_case format.'; - $phpcs_file->addError( $error, $stack_ptr, 'MemberNotSnakeCase', $error_data ); + $error = 'Member variable "$%s" is not in valid snake_case format, try "$%s"'; + $data = array( + $var_name, + Sniff::get_snake_case_name_suggestion( $var_name ), + ); + $phpcs_file->addError( $error, $stack_ptr, 'PropertyNotSnakeCase', $data ); } } @@ -242,9 +252,12 @@ protected function processVariableInString( File $phpcs_file, $stack_ptr ) { } if ( false === self::isSnakeCase( $var_name ) ) { - $error = 'Variable "%s" is not in valid snake_case format'; - $data = array( $var_name ); - $phpcs_file->addError( $error, $stack_ptr, 'StringNotSnakeCase', $data ); + $error = 'Variable "$%s" is not in valid snake_case format, try "$%s"'; + $data = array( + $var_name, + Sniff::get_snake_case_name_suggestion( $var_name ), + ); + $phpcs_file->addError( $error, $stack_ptr, 'InterpolatedVariableNotSnakeCase', $data ); } } } From e5cc4b00730ab1c631b5b3aed575c0e316e0f0cf Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 27 Dec 2018 18:56:33 +0100 Subject: [PATCH 070/241] ValidVariableName: minor tweaks Minor changes missed in PR 1586. * Update the class documentation. * Remove a, now unused, property array key. --- .../Sniffs/NamingConventions/ValidVariableNameSniff.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index 0b5cb047f3..0b9422796a 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -28,8 +28,8 @@ * * Last synced with base class June 2018 at commit 78ddbae97cac078f09928bf89e3ab9e53ad2ace0. * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php - * One change from upstream deferred till later (PHPCS 3.3.0+): - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1048#issuecomment-364282100 + * + * @uses PHP_CodeSniffer\Sniffs\AbstractVariableSniff::$phpReservedVars */ class ValidVariableNameSniff extends PHPCS_AbstractVariableSniff { @@ -92,7 +92,6 @@ class ValidVariableNameSniff extends PHPCS_AbstractVariableSniff { */ protected $addedCustomProperties = array( 'properties' => null, - 'variables' => null, ); /** From 56bcfd9683afa9de18696ff92f142743ef185bc4 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 27 Dec 2018 18:59:11 +0100 Subject: [PATCH 071/241] ValidVariableName: add some additional unit tests ... to confirm that the sniff handles multi-variable/property declarations correctly. (some of these would have failed prior to PHPCS 3.3.0) --- .../ValidVariableNameUnitTest.inc | 19 +++++++++++++++++++ .../ValidVariableNameUnitTest.php | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.inc b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.inc index f510d74d57..0186491d75 100644 --- a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.inc +++ b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.inc @@ -167,3 +167,22 @@ echo ClassName $var_name2 // More sillyness. ['test']; + +class MultiVarDeclarations { + public $multiVar1, $multiVar2, // Bad x 2. + $multiVar3, // Bad. + // Some comment. + $multiVar4, // Bad. + $multiVar5 = false, // Bad. + $multiVar6 = 123, // Bad. + $multi_var7 = 'string'; // Ok. + + public function testMultiGlobalAndStatic() { + global $multiGlobal1, $multi_global2, // Bad x 1. + $multiGlobal3; // Bad. + + static $multiStatic1, $multi_static2 = false, // Bad x 1. + // Comment. + $multiStatic3 = ''; // Bad. + } +} diff --git a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php index 5891f54181..934826f5d4 100644 --- a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php +++ b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php @@ -73,6 +73,15 @@ public function getErrorList() { 138 => 1, 145 => 1, 160 => 1, + 172 => 2, + 173 => 1, + 175 => 1, + 176 => 1, + 177 => 1, + 181 => 1, + 182 => 1, + 184 => 1, + 186 => 1, ); } From 9b17fe2e52facdf77d1766605855ca1ad4085cfa Mon Sep 17 00:00:00 2001 From: Juliette <663378+jrfnl@users.noreply.github.com> Date: Sun, 30 Dec 2018 19:16:01 +0100 Subject: [PATCH 072/241] Changelog for WPCS version 2.0.0-RC1 (#1610) Changelog for WPCS version 2.0.0-RC1 * Release date set at this Monday December 31.. * Includes all currently merged changes. --- CHANGELOG.md | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97a14f7ab8..5413967824 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,150 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a _No documentation available about unreleased changes as of yet._ +## [2.0.0-RC1] - 2018-12-31 + +### Important information about this release: + +This is the first release candidate for WordPressCS 2.0.0. +WordPressCS 2.0.0 contains breaking changes, both for people using custom rulesets as well as for sniff developers who maintain a custom PHPCS standard based on WordPressCS. + +Support for `PHP_CodeSniffer` 2.x has been dropped, the new minimum `PHP_CodeSniffer` version is 3.3.1. +Also, all previously deprecated sniffs, properties and methods have been removed. + +Please read the complete changelog carefully before you upgrade. + +If you are a maintainer of an external standard based on WordPressCS and any of your custom sniffs are based on or extend WPCS sniffs, please read the [Developers Upgrade Guide to WordPressCS 2.0.0](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Upgrade-Guide-to-WordPressCS-2.0.0-for-Developers-of-external-standards). + +### Added +- `Generic.PHP.DiscourageGoto`, `Generic.PHP.LowerCaseType`, `Generic.WhiteSpace.ArbitraryParenthesesSpacing` and `PSR12.Keywords.ShortFormTypeKeywords` to the `WordPress-Core` ruleset. +- Checking the spacing around the `instanceof` operator to the `WordPress.WhiteSpace.OperatorSpacing` sniff. + +### Changed +- The minimum required `PHP_CodeSniffer` version to 3.3.1 (was 2.9.0). +- The namespace used by WordPressCS has been changed from `WordPress` to `WordPressCS\WordPress`. + This was not possible while `PHP_CodeSniffer` 2.x was still supported, but WordPressCS, as a good Open Source citizen, does not want to occupy the `WordPress` namespace and is releasing its use of it now this is viable. +- The `WordPress.DB.PreparedSQL` sniff used the same error code for two different errors. + The `NotPrepared` error code remains, however an additional `InterpolatedNotPrepared` error code has been added for the second error. + If you are referencing the old error code in a ruleset XML file or in inline annotations, you may need to update it. +- The `WordPress.NamingConventions.PrefixAllGlobals` sniff used the same error code for some errors as well as warnings. + The `NonPrefixedConstantFound` error code remains for the related error, but the warning will now use the new `VariableConstantNameFound` error code. + The `NonPrefixedHooknameFound` error code remains for the related error, but the warning will now use the new `DynamicHooknameFound` error code. + If you are referencing the old error codes in a ruleset XML file or in inline annotations, you may need to update these to use the new codes instead. +- `WordPress.NamingConventions.ValidVariableName`: the error messages and error codes used by this sniff have been changed for improved usability and consistency. + - The error messages will now show a suggestion for a valid alternative name for the variable. + - The `NotSnakeCaseMemberVar` error code has been renamed to `UsedPropertyNotSnakeCase`. + - The `NotSnakeCase` error code has been renamed to `VariableNotSnakeCase`. + - The `MemberNotSnakeCase` error code has been renamed to `PropertyNotSnakeCase`. + - The `StringNotSnakeCase` error code has been renamed to `InterpolatedVariableNotSnakeCase`. + If you are referencing the old error codes in a ruleset XML file or in inline annotations, you may need to update these to use the new codes instead. +- The `WordPress.Security.NonceVerification` sniff used the same error code for both an error as well as a warning. + The old error code `NoNonceVerification` is no longer used. + The `error` now uses the `Missing` error code, while the `warning` now uses the `Recommended` error code. + If you are referencing the old error code in a ruleset XML file or in inline annotations, please update these to use the new codes instead. +- The `WordPress.WP.DiscouragedConstants` sniff used to have two error codes `UsageFound` and `DeclarationFound`. + These error codes will now be prefixed by the name of the constant found to allow for more fine-grained excluding/ignoring of warnings generated by this sniff. + If you are referencing the old error codes in a ruleset XML file or in inline annotations, you may need to update these to use the new codes instead. +- The `WordPress.WP.GlobalVariablesOverride.OverrideProhibited` error code has been replaced by the `WordPress.WP.GlobalVariablesOverride.Prohibited` error code. + If you are referencing the old error code in a ruleset XML file or in inline annotations, you may need to update it. +- `WordPress-Extra`: Replaced the inclusion of the `Generic.Files.OneClassPerFile`, `Generic.Files.OneInterfacePerFile` and the `Generic.Files.OneTraitPerFile` sniffs with the new `Generic.Files.OneObjectStructurePerFile` sniff. +- `WordPress-Extra`: Replaced the inclusion of the `Squiz.WhiteSpace.LanguageConstructSpacing` sniff with the new `Generic.WhiteSpace.LanguageConstructSpacing` sniff. +- `WordPress-Extra`: Replaced the inclusion of the `Squiz.Scope.MemberVarScope` sniff with the more comprehensive `PSR2.Classes.PropertyDeclaration` sniff. +- `WordPress.NamingConventions.ValidFunctionName`: Added a unit test confirming support for interfaces extending multiple interfaces. +- `WordPress.NamingConventions.ValidVariableName`: Added unit tests confirming support for multi-variable/property declarations. +- The `get_name_suggestion()` method has been moved from the `WordPress.NamingConventions.ValidFunctionName` sniff to the base `Sniff` class, renamed to `get_snake_case_name_suggestion()` and made static. +- The rulesets are now validated against the `PHP_CodeSniffer` XSD schema. +- Updated the [custom ruleset example](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/phpcs.xml.dist.sample) to use the recommended ruleset syntax for `PHP_CodeSniffer` 3.3.1+, including using the new [array property format](https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.3.0) which is now supported. +- Dev: The command to run the unit tests has changed. Please see the updated instructions in the [CONTRIBUTING.md](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/.github/CONTRIBUTING.md) file. + The `bin/pre-commit` example git hook has been updated to match. Additionally a `run-tests` script has been added to the `composer.json` file for your convenience. + To facilitate this, PHPUnit has been added to `require-dev`, even though it is strictly speaking a dependency of PHPCS, not of WPCS. +- Dev: The DealerDirect PHPCS Composer plugin has been added to `require-dev`. +- Various code tweaks and clean up. +- User facing documentation, including the wiki, as well as inline documentation has been updated for all the changes contained in WordPressCS 2.0 and other recommended best practices for `PHP_CodeSniffer` 3.3.1+. + +### Deprecated +- The use of the [WordPressCS native whitelist comments](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Whitelisting-code-which-flags-errors), which were introduced in WPCS 0.4.0, have been deprecated and support will be removed in WPCS 3.0.0. + The WordPressCS native whitelist comments will continue to work for now, but a deprecation warning will be thrown when they are encountered. + You are encouraged to upgrade our whitelist comment to use the [PHPCS native selective ignore annotations}(https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.2.0) as introduced in `PHP_CodeSniffer` 3.2.0, as soon as possible. + +### Removed +- Support for PHP 5.3. PHP 5.4 is the minimum requirement for `PHP_CodeSniffer` 3.x. + Includes removing any and all workarounds which were in place to still support PHP 5.3. +- Support for `PHP_CodeSniffer` < 3.3.1. + Includes removing any and all workarounds which were in place for supporting older `PHP_CodeSniffer` versions. +- The `WordPress-VIP` standard which was deprecated since WordPressCS 1.0.0. + For checking a theme/plugin for hosting on the WordPress.com VIP platform, please use the [Automattic VIP coding standards](https://github.com/Automattic/VIP-Coding-Standards) instead. +- Support for array properties set in a custom ruleset without the `type="array"` attribute. + Support for this was deprecated in WPCS 1.0.0. + If in doubt about how properties should be set in your custom ruleset, please refer to the [Customizable sniff properties](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties) wiki page which contains XML code examples for setting each and every WPCS native sniff property. + As the minimum `PHP_CodeSniffer` version is now 3.3.1, you can now also use the [new format for setting array properties](https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.3.0), so this would be a great moment to review and update your custom ruleset. + Note: the ability to set select properties from the command-line as comma-delimited strings is _not_ affected by this change. +- The following sniffs have been removed outright without deprecation. + If you are referencing these sniffs in a ruleset XML file or in inline annotations, please update these to reference the replacement sniffs instead. + - `WordPress.Functions.FunctionCallSignatureNoParams` - superseded by a bug fix in the upstream `PEAR.Functions.FunctionCallSignature` sniff. + - `WordPress.PHP.DiscourageGoto` - replaced by the same sniff which is now available upstream: `Generic.PHP.DiscourageGoto`. + - `WordPress.WhiteSpace.SemicolonSpacing` - superseded by a bug fix in the upstream `Squiz.WhiteSpace.SemicolonSpacing` sniff. + - `WordPress.WhiteSpace.ArbitraryParenthesesSpacing` - replaced by the same sniff which is now available upstream: `Generic.WhiteSpace.ArbitraryParenthesesSpacing`. +- The following "base" sniffs which were previously already deprecated and turned into abstract base classes, have been removed: + - `WordPress.Arrays.ArrayAssignmentRestrictions` - use the `AbstractArrayAssignmentRestrictionsSniff` class instead. + - `WordPress.Functions.FunctionRestrictions` - use the `AbstractFunctionRestrictionsSniff` class instead. + - `WordPress.Variables.VariableRestrictions` without replacement. +- The following sniffs which were previously deprecated, have been removed: + - `WordPress.Arrays.ArrayDeclaration` - use the other sniffs in the `WordPress.Arrays` category instead. + - `WordPress.CSRF.NonceVerification` - use `WordPress.Security.NonceVerification` instead. + - `WordPress.Functions.DontExtract` - use `WordPress.PHP.DontExtract` instead. + - `WordPress.Variables.GlobalVariables` - use `WordPress.WP.GlobalVariablesOverride` instead. + - `WordPress.VIP.CronInterval` - use `WordPress.WP.CronInterval` instead. + - `WordPress.VIP.DirectDatabaseQuery` - use `WordPress.DB.DirectDatabaseQuery` instead. + - `WordPress.VIP.PluginMenuSlug` - use `WordPress.Security.PluginMenuSlug` instead. + - `WordPress.VIP.SlowDBQuery` - use `WordPress.DB.SlowDBQuery` instead. + - `WordPress.VIP.TimezoneChange` - use `WordPress.WP.TimezoneChange` instead. + - `WordPress.VIP.ValidatedSanitizedInput` - use `WordPress.Security.ValidatedSanitizedInput` instead. + - `WordPress.WP.PreparedSQL` - use `WordPress.DB.PreparedSQL` instead. + - `WordPress.XSS.EscapeOutput` - use `WordPress.Security.EscapeOutput` instead. + - `WordPress.PHP.DiscouragedFunctions` without direct replacement. + The checks previously contained in this sniff were moved to separate sniffs in WPCS 0.11.0. + - `WordPress.Variables.VariableRestrictions` without replacement. + - `WordPress.VIP.AdminBarRemoval` without replacement. + - `WordPress.VIP.FileSystemWritesDisallow` without replacement. + - `WordPress.VIP.OrderByRand` without replacement. + - `WordPress.VIP.PostsPerPage` without replacement. + Part of the previous functionality was split off in WPCS 1.0.0 to the `WordPress.WP.PostsPerPage` sniff. + - `WordPress.VIP.RestrictedFunctions` without replacement. + - `WordPress.VIP.RestrictedVariables` without replacement. + - `WordPress.VIP.SessionFunctionsUsage` without replacement. + - `WordPress.VIP.SessionVariableUsage` without replacement. + - `WordPress.VIP.SuperGlobalInputUsage` without replacement. +- The `WordPress.DB.SlowDBQuery.DeprecatedWhitelistFlagFound` error code which is superseded by the blanket deprecation warning for using the now deprecated WPCS native whitelist comments. +- The `WordPress.PHP.TypeCasts.NonLowercaseFound` error code which has been replaced by the upstream `Generic.PHP.LowerCaseType` sniff. +- The `WordPress.PHP.TypeCasts.LongBoolFound` and `WordPress.PHP.TypeCasts.LongIntFound` error codes which has been replaced by the new upstream `PSR12.Keywords.ShortFormTypeKeywords` sniff. +- The `WordPress.Security.EscapeOutput.OutputNotEscapedShortEcho` error code which was only ever used if WPCS was run on PHP 5.3 with the `short_open_tag` ini directive set to `off`. +- The following sniff categories which were previously deprecated, have been removed, though select categories may be reinstated in the future: + - `CSRF` + - `Functions` + - `Variables` + - `VIP` + - `XSS` +- `WordPress.NamingConventions.ValidVariableName`: The `customVariableWhitelist` property, which had been deprecated since WordPressCS 0.11.0. Use the `customPropertiesWhitelist` property instead. +- `WordPress.Security.EscapeOutput`: The `customSanitizingFunctions` property, which had been deprecated since WordPressCS 0.5.0. Use the `customEscapingFunctions` property instead. +- `WordPress.Security.NonceVerification`: The `errorForSuperGlobals` and `warnForSuperGlobals` properties, which had been deprecated since WordPressCS 0.12.0. +- The `vip_powered_wpcom` function from the `Sniff::$autoEscapedFunctions` list which is used by the `WordPress.Security.EscapeOutput` sniff. +- The `AbstractVariableRestrictionsSniff` class, which was deprecated since WordPressCS 1.0.0. +- The `Sniff::has_html_open_tag()` utility method, which was deprecated since WordPressCS 1.0.0. +- The internal `$php_reserved_vars` property from the `WordPress.NamingConventions.ValidVariableName` sniff in favour of using a PHPCS native property which is now available. +- The class aliases and WPCS native autoloader used for PHPCS cross-version support. +- The unit test framework workarounds for PHPCS cross-version unit testing. +- Support for the `@codingStandardsChangeSetting` annotation, which is generally only used in unit tests. +- The old generic GitHub issue template which was replaced by more specific issue templates in WPCS 1.2.0. + +### Fixed +- Support for PHP 7.3. + `PHP_CodeSniffer` < 3.3.1 was not fully compatible with PHP 7.3. Now the minimum required PHPCS has been upped to `PHP_CodeSniffer` 3.3.1, WordPressCS will run on PHP 7.3 without issue. +- `WordPress.Arrays.ArrayDeclarationSpacing`: improved fixing of the placement of array items following an array item with a trailing multi-line comment. +- `WordPress.NamingConventions.ValidFunctionName`: the sniff will no longer throw false positives nor duplicate errors for methods declared in nested anonymous classes. + The error message has also been improved for methods in anonymous classes. +- `WordPress.NamingConventions.ValidFunctionName`: the sniff will no longer throw false positives for PHP 4-style class constructors/destructors where the name of the constructor/destructor method did not use the same case as the class name. + + ## [1.2.1] - 2018-12-18 Note: This will be the last release supporting PHP_CodeSniffer 2.x. @@ -826,6 +970,7 @@ See the comparison for full list. Initial tagged release. [Unreleased]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/master...HEAD +[2.0.0-RC1]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.2.1...2.0.0-RC1 [1.2.1]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.2.0...1.2.1 [1.2.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.1.0...1.2.0 [1.1.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.0.0...1.1.0 From 06b78a51747e97773699e2f6321789ecea84d19a Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 7 Jan 2019 00:10:59 +0100 Subject: [PATCH 073/241] Revert "Extra: Use the new `Generic.WhiteSpace.LanguageConstructSpacing` sniff (PHPCS 3.3.0)" This effectively reverts PR 1585 as the PEAR installation of PHPCS will not work with WPCS 2..0.0 if we leave this in. Once upstream PR squizlabs/PHP_CodeSniffer 2340 has been merged, a new PHPCS version tagged & released and WPCS is ready & willing to upgrade that version, this change should be made anew as the new sniff is definitely better than the old version, but until that time, it is not important enough to allow WPCS to be broken for anyone using a PEAR install of PHPCS. Fixes 1614 --- WordPress-Extra/ruleset.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index ad65a65568..b03af3ee86 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -56,7 +56,7 @@ - + From 25393d32d50d65cc8ad05058c20a266571ff88ac Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 31 Dec 2018 00:32:06 +0100 Subject: [PATCH 074/241] Changelog for WPCS 2.0.0 * Release date set at this **Wednesday January 16th**. * Includes all currently merged changes. --- CHANGELOG.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5413967824..96b8b726e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,30 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a _No documentation available about unreleased changes as of yet._ +## [2.0.0] - 2019-01-16 + +### Important information about this release: + +WordPressCS 2.0.0 contains breaking changes, both for people using custom rulesets as well as for sniff developers who maintain a custom PHPCS standard based on WordPressCS. + +Support for `PHP_CodeSniffer` 2.x has been dropped, the new minimum `PHP_CodeSniffer` version is 3.3.1. +Also, all previously deprecated sniffs, properties and methods have been removed. + +Please read the complete changelog carefully before you upgrade. + +If you are a maintainer of an external standard based on WordPressCS and any of your custom sniffs are based on or extend WPCS sniffs, please read the [Developers Upgrade Guide to WordPressCS 2.0.0](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Upgrade-Guide-to-WordPressCS-2.0.0-for-Developers-of-external-standards). + +### Changes since 2.0.0-RC1 + +#### Fixed + +- `WordPress-Extra`: Reverted back to including the `Squiz.WhiteSpace.LanguageConstructSpacing` sniff instead of the new `Generic.WhiteSpace.LanguageConstructSpacing` sniff as the new sniff is not (yet) available when the PEAR install of PHPCS is used. + +### Changes since 1.2.1 +For a full list of changes from the 1.2.1 version, please review the following changelog: +* https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/releases/tag/2.0.0-RC1 + + ## [2.0.0-RC1] - 2018-12-31 ### Important information about this release: @@ -71,7 +95,7 @@ If you are a maintainer of an external standard based on WordPressCS and any of ### Deprecated - The use of the [WordPressCS native whitelist comments](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Whitelisting-code-which-flags-errors), which were introduced in WPCS 0.4.0, have been deprecated and support will be removed in WPCS 3.0.0. The WordPressCS native whitelist comments will continue to work for now, but a deprecation warning will be thrown when they are encountered. - You are encouraged to upgrade our whitelist comment to use the [PHPCS native selective ignore annotations}(https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.2.0) as introduced in `PHP_CodeSniffer` 3.2.0, as soon as possible. + You are encouraged to upgrade our whitelist comment to use the [PHPCS native selective ignore annotations](https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.2.0) as introduced in `PHP_CodeSniffer` 3.2.0, as soon as possible. ### Removed - Support for PHP 5.3. PHP 5.4 is the minimum requirement for `PHP_CodeSniffer` 3.x. @@ -970,6 +994,7 @@ See the comparison for full list. Initial tagged release. [Unreleased]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/master...HEAD +[2.0.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/2.0.0-RC1...2.0.0 [2.0.0-RC1]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.2.1...2.0.0-RC1 [1.2.1]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.2.0...1.2.1 [1.2.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.1.0...1.2.0 From 83f445f407b49164011b782379ba74e712ff2489 Mon Sep 17 00:00:00 2001 From: Andrey Savchenko Date: Wed, 16 Jan 2019 15:48:26 +0200 Subject: [PATCH 075/241] Bumped suggested installer version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7e6f35545b..f306ca7bdc 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." + "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." }, "minimum-stability": "RC", "scripts": { From 97167b228a7e6cb753c369a656ad9c8adf7a9f3b Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 22 Jan 2019 17:14:03 +0100 Subject: [PATCH 076/241] PrefixAllGlobals: prevent false negatives for autoloaded user-defined global functions The `PrefixAllGlobals` sniff verifies that functions declared in the global namespace are prefixed with one of the whitelisted prefixes as passed to the sniff in the `prefixes` property in a custom ruleset. The sniff prevents false positives for polyfills for PHP native functions - which should be named exactly as named in PHP without prefix for them to be usable as a polyfill - by checking that the function didn't exist. Generally speaking this works fine in 95% of all cases as PHPCS is normally run stand-alone and doesn't contain any functions defined in the global namespace. Similarly, when PHPCS is installed via Composer, this would normally work fine as the commonly used `autoload` options are `PSR-0`, `PSR-4` and `classmap` which are all based on code being in classes. However, if the Composer `autoload` `files` option is used to load, for instance, a functions file declaring functions in the global namespace, this "polyfill false positive prevention" would incorrectly cause errors _not_ to be thrown for functions declared in the global namespace which were now autoloaded via Composer. I have now fixed this by, instead of using `function_exists()`, using a check against a functions list retrieved via `get_defined_functions()`. This change does not have unit tests as: * Preventing false positives for polyfills is already unit tested. * Checking that autoloaded user defined functions are not recognized as PHP native functions is not something which can be unit tested as such. This would need an integration test including a composer setup to be tested. Based on the test case provided in the issue which originally reported this, I have confirmed that this PR fixes the issue though. Fixes 1632 --- .../PrefixAllGlobalsSniff.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index 1dd90a3fb8..f40894f08e 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -173,6 +173,18 @@ class PrefixAllGlobalsSniff extends AbstractFunctionParameterSniff { 'WP_DEFAULT_THEME' => true, ); + /** + * List of all PHP native functions. + * + * Using this list rather than a call to `function_exists()` prevents + * false negatives from user-defined functions when those would be + * autoloaded via a Composer autoload files directives. + * + * @var array + */ + private $built_in_functions; + + /** * Returns an array of tokens this test wants to listen for. * @@ -181,6 +193,11 @@ class PrefixAllGlobalsSniff extends AbstractFunctionParameterSniff { * @return array */ public function register() { + // Get a list of all PHP native functions. + $all_functions = get_defined_functions(); + $this->built_in_functions = array_flip( $all_functions['internal'] ); + + // Set the sniff targets. $targets = array( \T_NAMESPACE => \T_NAMESPACE, \T_FUNCTION => \T_FUNCTION, @@ -345,7 +362,7 @@ public function process_token( $stackPtr ) { } $item_name = $this->phpcsFile->getDeclarationName( $stackPtr ); - if ( function_exists( '\\' . $item_name ) ) { + if ( isset( $this->built_in_functions[ $item_name ] ) ) { // Backfill for PHP native function. return; } From b5acadbac6e8c0603d93d1cabad11e0292e42b96 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 23 Jan 2019 06:07:06 +0100 Subject: [PATCH 077/241] ValidatedSanitizedInput: only recognize a variable as validated if the correct variable is examined The `Sniff::is_validated()` method did not check whether the variable being validated was in actual fact the same variable as the one for which validation was needed. This could cause false negatives for the `InputNotValidated` error if an array key in, for instance, `$_GET` was validated, but that same array key was later requested - without validation - from `$_POST`. --- WordPress/Sniff.php | 4 ++++ .../Tests/Security/ValidatedSanitizedInputUnitTest.inc | 7 ++++++- .../Tests/Security/ValidatedSanitizedInputUnitTest.php | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 721e85ecba..98830cecc4 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1772,6 +1772,10 @@ protected function is_validated( $stackPtr, $array_key = null, $in_condition_onl continue; } + if ( $this->tokens[ $stackPtr ]['content'] !== $this->tokens[ $i ]['content'] ) { + continue; + } + // If we're checking for a specific array key (ex: 'hello' in // $_POST['hello']), that must match too. Quote-style, however, doesn't matter. if ( isset( $array_key ) diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc index 9a8e6c4844..d5f6eafa4f 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc @@ -85,7 +85,7 @@ echo array_map( array( $obj, 'sanitize_text_field' ), wp_unslash( $_GET['test'] $foo = (int) $_POST['foo6']; // Bad. // Non-assignment checks are OK. -if ( 'bar' === $_POST['foo'] ) {} // Ok. +if ( isset( $_POST['foo'] ) && 'bar' === $_POST['foo'] ) {} // Ok. if ( $_GET['test'] != 'a' ) {} // Ok. if ( 'bar' === do_something( wp_unslash( $_POST['foo'] ) ) ) {} // Bad. @@ -183,3 +183,8 @@ function barfoo() { if ( isset( $_POST[ 'currentid' ] ) ){ $id = (int) $_POST[ "currentid" ]; // OK. } + +// Only recognize validation if the correct superglobal is examined. +if ( isset ( $_POST['thisisnotget'] ) ) { + $get = (int) $_GET['thisisnotget']; // Bad. +} diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php index 02b7e9d4ae..49a4a09076 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php @@ -54,6 +54,7 @@ public function getErrorList() { 138 => 1, 150 => 2, 160 => 2, + 189 => 1, ); } From 44e5857686de2fedcf7b2912d84e1f33cf7c48dd Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 23 Jan 2019 06:12:42 +0100 Subject: [PATCH 078/241] ValidatedSanitizedInput: add tests validating variables with array_key_exists() --- .../ValidatedSanitizedInputUnitTest.inc | 21 +++++++++++++++++++ .../ValidatedSanitizedInputUnitTest.php | 3 +++ 2 files changed, 24 insertions(+) diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc index d5f6eafa4f..da3be11da1 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc @@ -188,3 +188,24 @@ if ( isset( $_POST[ 'currentid' ] ) ){ if ( isset ( $_POST['thisisnotget'] ) ) { $get = (int) $_GET['thisisnotget']; // Bad. } + +// Recognize PHP native array_key_exists() as validation function. +if ( array_key_exists( 'my_field1', $_POST ) ) { + $id = (int) $_POST['my_field1']; // OK. +} + +if ( \array_key_exists( 'my_field2', $_POST ) ) { + $id = (int) $_POST['my_field2']; // OK. +} + +if ( \Some\ClassName\array_key_exists( 'my_field3', $_POST ) ) { + $id = (int) $_POST['my_field3']; // Bad. +} + +if ( $obj->array_key_exists( 'my_field4', $_POST ) ) { + $id = (int) $_POST['my_field4']; // Bad. +} + +if ( ClassName::array_key_exists( 'my_field5', $_POST ) ) { + $id = (int) $_POST['my_field5']; // Bad. +} diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php index 49a4a09076..46ab050e97 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php @@ -55,6 +55,9 @@ public function getErrorList() { 150 => 2, 160 => 2, 189 => 1, + 202 => 1, + 206 => 1, + 210 => 1, ); } From 4e8d27f7910d2d0601b3cdfb9f0f593faee98c54 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 23 Jan 2019 06:13:04 +0100 Subject: [PATCH 079/241] Sniff::is_in_isset_or_empty(): allow for array_key_exists() Just like, `isset()` and `empty()`, `array_key_exists()` is a way to validate a variable exists and should therefore be recognized by this function. --- WordPress/Sniff.php | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 98830cecc4..53a8799ff7 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1428,9 +1428,11 @@ protected function has_nonce_check( $stackPtr ) { } /** - * Check if a token is inside of an isset() or empty() statement. + * Check if a token is inside of an isset(), empty() or array_key_exists() statement. * * @since 0.5.0 + * @since 2.0.1 Now checks for the token being used as the array parameter + * in function calls to array_key_exists() as well. * * @param int $stackPtr The index of the token in the stack. * @@ -1448,7 +1450,42 @@ protected function is_in_isset_or_empty( $stackPtr ) { $open_parenthesis = key( $nested_parenthesis ); $previous_non_empty = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $open_parenthesis - 1 ), null, true, null, true ); - return in_array( $this->tokens[ $previous_non_empty ]['code'], array( \T_ISSET, \T_EMPTY ), true ); + if ( false === $previous_non_empty ) { + return false; + } + + $previous_code = $this->tokens[ $previous_non_empty ]['code']; + if ( \T_ISSET === $previous_code || \T_EMPTY === $previous_code ) { + return true; + } + + if ( \T_STRING === $previous_code && 'array_key_exists' === $this->tokens[ $previous_non_empty ]['content'] ) { + $before_function = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $previous_non_empty - 1 ), null, true, null, true ); + + if ( false !== $before_function ) { + if ( \T_OBJECT_OPERATOR === $this->tokens[ $before_function ]['code'] + || \T_DOUBLE_COLON === $this->tokens[ $before_function ]['code'] + ) { + // Method call. + return false; + } + + if ( \T_NS_SEPARATOR === $this->tokens[ $before_function ]['code'] ) { + $before_before = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $before_function - 1 ), null, true, null, true ); + if ( false !== $before_before && \T_STRING === $this->tokens[ $before_before ]['code'] ) { + // Namespaced function call. + return false; + } + } + } + + $second_param = $this->get_function_call_parameter( $previous_non_empty, 2 ); + if ( $stackPtr >= $second_param['start'] && $stackPtr <= $second_param['end'] ) { + return true; + } + } + + return false; } /** From 5f3905a1203b60dd1173c706fef4817c3a40c2ce Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 23 Jan 2019 06:14:54 +0100 Subject: [PATCH 080/241] Sniff::is_validated(): allow for array_key_exists() Just like, `isset()` and `empty()`, `array_key_exists()` is a way to validate a variable exists and should therefore be recognized by this function. --- WordPress/Sniff.php | 97 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 78 insertions(+), 19 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 53a8799ff7..7f39609418 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1703,7 +1703,7 @@ protected function get_array_access_key( $stackPtr ) { } /** - * Check if the existence of a variable is validated with isset() or empty(). + * Check if the existence of a variable is validated with isset(), empty() or array_key_exists(). * * When $in_condition_only is false, (which is the default), this is considered * valid: @@ -1726,6 +1726,7 @@ protected function get_array_access_key( $stackPtr ) { * ``` * * @since 0.5.0 + * @since 2.0.1 Now recognizes array_key_exists() as a validation function. * * @param int $stackPtr The index of this token in the stack. * @param string $array_key An array key to check for ("bar" in $foo['bar']). @@ -1791,36 +1792,94 @@ protected function is_validated( $stackPtr, $array_key = null, $in_condition_onl } $bare_array_key = $this->strip_quotes( $array_key ); + $targets = array( + \T_ISSET => 'construct', + \T_EMPTY => 'construct', + \T_UNSET => 'construct', + \T_STRING => 'function_call', + ); // phpcs:ignore Generic.CodeAnalysis.JumbledIncrementer.Found -- On purpose, see below. for ( $i = ( $scope_start + 1 ); $i < $scope_end; $i++ ) { - if ( ! \in_array( $this->tokens[ $i ]['code'], array( \T_ISSET, \T_EMPTY, \T_UNSET ), true ) ) { + if ( isset( $targets[ $this->tokens[ $i ]['code'] ] ) === false ) { continue; } - $issetOpener = $this->phpcsFile->findNext( \T_OPEN_PARENTHESIS, $i ); - $issetCloser = $this->tokens[ $issetOpener ]['parenthesis_closer']; + switch ( $targets[ $this->tokens[ $i ]['code'] ] ) { + case 'construct': + $issetOpener = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), null, true, null, true ); + if ( false === $issetOpener || \T_OPEN_PARENTHESIS !== $this->tokens[ $issetOpener ]['code'] ) { + // Parse error or live coding. + continue 2; + } - // Look for this variable. We purposely stomp $i from the parent loop. - for ( $i = ( $issetOpener + 1 ); $i < $issetCloser; $i++ ) { + $issetCloser = $this->tokens[ $issetOpener ]['parenthesis_closer']; - if ( \T_VARIABLE !== $this->tokens[ $i ]['code'] ) { - continue; - } + // Look for this variable. We purposely stomp $i from the parent loop. + for ( $i = ( $issetOpener + 1 ); $i < $issetCloser; $i++ ) { - if ( $this->tokens[ $stackPtr ]['content'] !== $this->tokens[ $i ]['content'] ) { - continue; - } + if ( \T_VARIABLE !== $this->tokens[ $i ]['code'] ) { + continue; + } - // If we're checking for a specific array key (ex: 'hello' in - // $_POST['hello']), that must match too. Quote-style, however, doesn't matter. - if ( isset( $array_key ) - && $this->strip_quotes( $this->get_array_access_key( $i ) ) !== $bare_array_key ) { - continue; - } + if ( $this->tokens[ $stackPtr ]['content'] !== $this->tokens[ $i ]['content'] ) { + continue; + } - return true; + // If we're checking for a specific array key (ex: 'hello' in + // $_POST['hello']), that must match too. Quote-style, however, doesn't matter. + if ( isset( $array_key ) + && $this->strip_quotes( $this->get_array_access_key( $i ) ) !== $bare_array_key ) { + continue; + } + + return true; + } + + break; + + case 'function_call': + // Only check calls to array_key_exists(). + if ( 'array_key_exists' !== $this->tokens[ $i ]['content'] ) { + continue 2; + } + + $next_non_empty = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), null, true, null, true ); + if ( false === $next_non_empty || \T_OPEN_PARENTHESIS !== $this->tokens[ $next_non_empty ]['code'] ) { + // Not a function call. + continue 2; + } + + $previous_non_empty = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $i - 1 ), null, true, null, true ); + if ( false !== $previous_non_empty ) { + if ( \T_OBJECT_OPERATOR === $this->tokens[ $previous_non_empty ]['code'] + || \T_DOUBLE_COLON === $this->tokens[ $previous_non_empty ]['code'] + ) { + // Method call. + continue 2; + } + + if ( \T_NS_SEPARATOR === $this->tokens[ $previous_non_empty ]['code'] ) { + $pprev = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $previous_non_empty - 1 ), null, true, null, true ); + if ( false !== $pprev && \T_STRING === $this->tokens[ $pprev ]['code'] ) { + // Namespaced function call. + continue 2; + } + } + } + + $params = $this->get_function_call_parameters( $i ); + if ( $params[2]['raw'] !== $this->tokens[ $stackPtr ]['content'] ) { + continue 2; + } + + if ( isset( $array_key ) + && $this->strip_quotes( $params[1]['raw'] ) !== $bare_array_key ) { + continue 2; + } + + return true; } } From 71ace5641638b607cfc080ebd312acbf5ace64e7 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 28 Jan 2019 16:51:06 +0100 Subject: [PATCH 081/241] Sniff::$test_class_whitelist: add newly added base test class to the list See: https://core.trac.wordpress.org/changeset/44701 --- WordPress/Sniff.php | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 98830cecc4..69fa88726a 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -770,6 +770,7 @@ abstract class Sniff implements PHPCS_Sniff { * @var string[] */ protected $test_class_whitelist = array( + 'WP_UnitTestCase_Base' => true, 'WP_UnitTestCase' => true, 'WP_Ajax_UnitTestCase' => true, 'WP_Canonical_UnitTestCase' => true, From ca209e78e1ea40970c1282fd57e7f9cc2ce328f6 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 11 Feb 2019 17:46:35 +0100 Subject: [PATCH 082/241] Travis: test builds against PHP 7.4 Nightly has become PHP 8.0 since PHP 7.4 has been branched, so to continue to also test against PHP 7.4, it needs to be added separately. Refs: * https://twitter.com/nikita_ppv/status/1089839541828112384 * https://twitter.com/nikita_ppv/status/1094897743594770433 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 64fe800947..9fd375f3de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,7 @@ php: - 7.1 - 7.2 - 7.3 + - "7.4snapshot" - nightly env: @@ -42,6 +43,7 @@ matrix: allow_failures: # Allow failures for unstable builds. + - php: "7.4snapshot" - php: nightly before_install: From 4426a06ce160dbd807a113e9682ec2625995eb71 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 11 Feb 2019 17:53:17 +0100 Subject: [PATCH 083/241] Travis: work around PHPUnit 8.x on PHP >= 7.2 images As of recently, the Travis images for PHP 7.2+ ship with PHPUnit 8.x. The PHPCS native test framework is not compatible with PHPUnit 8.x and won't be able to be made compatible with it until the minimum PHP version would be raised to PHP 7.1. So for the unit tests to be able to run on PHP 7.2+, we need to explicitly require PHPUnit 7.x for those builds. This has been implemented in the same way as a similar requirement was previously implemented fo HHVM. As for nightly: there is no PHPUnit version which is currently compatible with PHP 8. As that either mean that the builds for `nightly` would always fail or - if the unit tests would be skipped -, the only check executed on `nightly` would be linting the files, I've elected to remove build testing against `nightly` for the time being. --- .travis.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9fd375f3de..a272e7ef9d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,6 @@ php: - 7.2 - 7.3 - "7.4snapshot" - - nightly env: # `master` is now 3.x. @@ -44,7 +43,6 @@ matrix: allow_failures: # Allow failures for unstable builds. - php: "7.4snapshot" - - php: nightly before_install: # Speed up build time by disabling Xdebug. @@ -62,12 +60,20 @@ before_install: # The above require already does the install. $(pwd)/vendor/bin/phpcs --config-set installed_paths $(pwd) fi + # Download PHPUnit 7.x for builds on PHP >= 7.2 as the PHPCS + # test suite is currently not compatible with PHPUnit 8.x. + - if [[ ${TRAVIS_PHP_VERSION:0:3} > "7.1" ]]; then wget -P $PHPUNIT_DIR https://phar.phpunit.de/phpunit-7.phar && chmod +x $PHPUNIT_DIR/phpunit-7.phar; fi script: # Lint the PHP files against parse errors. - if [[ "$LINT" == "1" ]]; then if find . -path ./vendor -prune -o -path ./bin -prune -o -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi; fi # Run the unit tests. - - phpunit --filter WordPress --bootstrap="$(pwd)/vendor/squizlabs/php_codesniffer/tests/bootstrap.php" $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php + - | + if [[ ${TRAVIS_PHP_VERSION:0:3} > "7.1" ]]; then + php $PHPUNIT_DIR/phpunit-7.phar --filter WordPress --bootstrap="$(pwd)/vendor/squizlabs/php_codesniffer/tests/bootstrap.php" $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php + else + phpunit --filter WordPress --bootstrap="$(pwd)/vendor/squizlabs/php_codesniffer/tests/bootstrap.php" $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php + fi # Test for fixer conflicts by running the auto-fixers of the complete WPCS over the test case files. # This is not an exhaustive test, but should give an early indication for typical fixer conflicts. # For the first run, the exit code will be 1 (= all fixable errors fixed). From 7529b4d5bb9fa67f3a3f471db1710baafa0233e7 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 13 Feb 2019 04:20:32 +0100 Subject: [PATCH 084/241] WP.EnqueuedResources: bug fix Identified by joyously in the ThemeReviewCS repo: WPTRT/WPThemeReview 202 When inline JQuery is used to reference a stylesheet link tag, the sniff misidentifies this as a stylesheet which needs to be enqueued. This very simple fix should prevent that, at least for the reported cases. Includes unit test. --- WordPress/Sniffs/WP/EnqueuedResourcesSniff.php | 2 +- WordPress/Tests/WP/EnqueuedResourcesUnitTest.inc | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php index 1473eac208..e8d0333ad4 100644 --- a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php +++ b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php @@ -44,7 +44,7 @@ public function register() { public function process_token( $stackPtr ) { $token = $this->tokens[ $stackPtr ]; - if ( preg_match( '#rel=\\\\?[\'"]?stylesheet\\\\?[\'"]?#', $token['content'] ) > 0 ) { + if ( preg_match( '# rel=\\\\?[\'"]?stylesheet\\\\?[\'"]?#', $token['content'] ) > 0 ) { $this->phpcsFile->addError( 'Stylesheets must be registered/enqueued via wp_enqueue_style', $stackPtr, diff --git a/WordPress/Tests/WP/EnqueuedResourcesUnitTest.inc b/WordPress/Tests/WP/EnqueuedResourcesUnitTest.inc index 941eacd779..3b5ec4f191 100644 --- a/WordPress/Tests/WP/EnqueuedResourcesUnitTest.inc +++ b/WordPress/Tests/WP/EnqueuedResourcesUnitTest.inc @@ -30,3 +30,9 @@ $head = <<<'EOD' EOD; + +?> + +jQuery( document ).ready( function() { + $('link[rel="stylesheet"]:not([data-inprogress])').forEach(StyleFix.link); +}); From 0f425fbeb303893358516d2855b342e4aac58dbf Mon Sep 17 00:00:00 2001 From: Stephen Edgar Date: Fri, 15 Feb 2019 14:02:36 +1100 Subject: [PATCH 085/241] Remove `sudo: false` --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a272e7ef9d..bb60dd86aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,3 @@ -sudo: false - dist: trusty cache: From 76011f6d214ccd439b93ea2ec4de248bf33263be Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 18 Feb 2019 22:06:30 +0100 Subject: [PATCH 086/241] PrefixAllGlobals: improve error message clarity When people run the sniffs without the `-s` option, the messages for some of the errors in this sniff were not specific enough as the "Prefix**AllGlobals**" part would not be seen. I considered adjusting the error message template `ERROR_MSG`, however, this would cause more confusion as, for instance, namespace declarations will **always** be in the global namespace. So, I've opted to adjust select error messages instead. --- .../Sniffs/NamingConventions/PrefixAllGlobalsSniff.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index f40894f08e..de46e0bdae 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -367,7 +367,7 @@ public function process_token( $stackPtr ) { return; } - $error_text = 'Functions declared'; + $error_text = 'Functions declared in the global namespace'; $error_code = 'NonPrefixedFunctionFound'; break; @@ -555,7 +555,7 @@ protected function process_variable_variable( $stackPtr ) { $stackPtr, 'NonPrefixedVariableFound', array( - 'Variables defined', + 'Global variables defined', $variable_name, ) ); @@ -705,7 +705,7 @@ protected function process_variable_assignment( $stackPtr ) { $is_error, 'NonPrefixedVariableFound', array( - 'Variables defined', + 'Global variables defined', '$' . $variable_name, ) ); From a392d28c878f1be470e082c0cdb9d20c6298daa3 Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Wed, 20 Feb 2019 13:08:16 +0100 Subject: [PATCH 087/241] Fixes #1447, adds new sniff for blacklisted ini_set directives. --- .../PHP/DiscouragedPHPFunctionsSniff.php | 1 - WordPress/Sniffs/PHP/IniSetSniff.php | 173 ++++++++++++++++++ .../PHP/DiscouragedPHPFunctionsUnitTest.inc | 1 - WordPress/Tests/PHP/IniSetUnitTest.inc | 28 +++ WordPress/Tests/PHP/IniSetUnitTest.php | 61 ++++++ 5 files changed, 262 insertions(+), 2 deletions(-) create mode 100644 WordPress/Sniffs/PHP/IniSetSniff.php create mode 100644 WordPress/Tests/PHP/IniSetUnitTest.inc create mode 100644 WordPress/Tests/PHP/IniSetUnitTest.php diff --git a/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php b/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php index f7d613df83..62102f3c39 100644 --- a/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php @@ -61,7 +61,6 @@ public function getGroups() { 'error_reporting', 'ini_alter', 'ini_restore', - 'ini_set', 'apache_setenv', 'putenv', 'set_include_path', diff --git a/WordPress/Sniffs/PHP/IniSetSniff.php b/WordPress/Sniffs/PHP/IniSetSniff.php new file mode 100644 index 0000000000..40188062bb --- /dev/null +++ b/WordPress/Sniffs/PHP/IniSetSniff.php @@ -0,0 +1,173 @@ + array(), + ); + + /** + * Array of options that are allowed to be manipulated + * + * @since x.x.x + * + * @var array Multidimensional array with parameter details. + * $whitelisted_options = array( + * (string) option name. = array( + * (string[]) 'valid_values' = array() + * ) + * ); + */ + protected $whitelisted_options = array( + 'auto_detect_line_endings'=>array(), + 'highlight.bg'=>array(), + 'highlight.comment'=>array(), + 'highlight.default'=>array(), + 'highlight.html'=>array(), + 'highlight.keyword'=>array(), + 'highlight.string'=>array(), + 'short_open_tag'=>array( + 'valid_values'=>array('true', '1', 'On') + ), + ); + + /** + * Array of options that are not allowed to be manipulated + * + * @since x.x.x + * + * @var array Multidimensional array with parameter details. + * $blacklisted_options = array( + * (string) option name. = array( + * (string[]) 'invalid_values' = array() + * (string) 'message' + * ) + * ); + */ + protected $blacklisted_options = array( + 'max_execution_time'=>array( + 'message'=>'Use `set_time_limit()` instead.' + ), + 'short_open_tag'=>array( + 'invalid_values'=>array('false', '0', 'Off'), + 'message'=>'Turning off short_open_tag is prohibited as it might possibily break other plugins.', + ), + 'bcmath.scale'=>array( + 'message'=>'Use `bcscale()` instead.' + ), + 'display_errors'=>array( + 'message'=>'Use `WP_DEBUG_DISPLAY` instead.' + ), + 'error_reporting'=>array( + 'message'=>'Use `WP_DEBUG` instead.' + ), + 'filter.default'=>array( + 'message'=>'Use the filter flag constants when calling the functions instead (as you will possibly break other plugins if you change this).' + ), + 'filter.default_flags'=>array( + 'message'=>'Use the filter flag constants when calling the functions instead (as you will possibly break other plugins if you change this).' + ), + 'iconv.input_encoding'=>array( + 'message'=>'PHP < 5.6 only - use `iconv_set_encoding()` instead.' + ), + 'iconv.internal_encoding'=>array( + 'message'=>'PHP < 5.6 only - use `iconv_set_encoding()` instead.' + ), + 'iconv.output_encoding'=>array( + 'message'=>'PHP < 5.6 only - use `iconv_set_encoding()` instead.' + ), + 'ignore_user_abort'=>array( + 'message'=>'Use `ignore_user_abort()` instead.' + ), + 'log_errors'=>array( + 'message'=>'Use `WP_DEBUG_LOG` instead.' + ), + 'memory_limit'=>array( + 'message'=>'Use `wp_raise_memory_limit()` or hook into the filters in that function.' + ), + ); + + /** + * Process the parameter of a matched function. Errors if an option + * is found in the blacklist. Warns as 'risky' when the option is not + * found in the whitelist. + * + * @since x.x.x + * + * @param int $stackPtr The position of the current token in the stack. + * @param array $group_name The name of the group which was matched. + * @param string $matched_content The token content (function name) which was matched. + * @param array $parameters Array with information about the parameters. + * + * @return void + */ + public function process_parameters( $stackPtr, $group_name, $matched_content, $parameters ){ + $ini_set_function = $this->tokens[ $stackPtr ]; + $option_name = $this->strip_quotes($parameters[1]['raw']); + $option_value = $this->strip_quotes($parameters[2]['raw']); + if(array_key_exists($option_name, $this->whitelisted_options)){ + $whitelisted_option = $this->whitelisted_options[$option_name]; + if(!isset($whitelisted_option['valid_values']) || in_array($option_value, $whitelisted_option['valid_values'], true) ){ + return; + } + } + + if(array_key_exists($option_name, $this->blacklisted_options)){ + $blacklisted_option = $this->blacklisted_options[$option_name]; + if(!isset($blacklisted_option['invalid_values']) || in_array($option_value, $blacklisted_option['invalid_values'], true) ){ + $this->phpcsFile->addError( + '%s(%s, %s) found. %s', + $stackPtr, + 'Blacklisted', + array( + $ini_set_function['content'], + $parameters[1]['raw'], + $parameters[2]['raw'], + $blacklisted_option['message'] + ) + ); + return; + } + } + $this->phpcsFile->addWarning( + '%s(%s, %s) found. Changing these configuration values at runtime is rarely necessary.', + $stackPtr, + 'Risky', + array( + $ini_set_function['content'], + $parameters[1]['raw'], + $parameters[2]['raw'] + ) + ); + return; + } +} diff --git a/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.inc b/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.inc index 792b0cad31..5a6e9a5577 100644 --- a/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.inc +++ b/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.inc @@ -16,7 +16,6 @@ dl(); // Warning. error_reporting(); // Warning. ini_alter(); // Warning. ini_restore(); // Warning. -ini_set(); // Warning. magic_quotes_runtime(); // Warning. set_magic_quotes_runtime(); // Warning. apache_setenv(); // Warning. diff --git a/WordPress/Tests/PHP/IniSetUnitTest.inc b/WordPress/Tests/PHP/IniSetUnitTest.inc new file mode 100644 index 0000000000..ef198be6a6 --- /dev/null +++ b/WordPress/Tests/PHP/IniSetUnitTest.inc @@ -0,0 +1,28 @@ + => + */ + public function getErrorList() { + return array( + 12 => 1, + 13 => 1, + 14 => 1, + 15 => 1, + 16 => 1, + 17 => 1, + 18 => 1, + 19 => 1, + 20 => 1, + 21 => 1, + 22 => 1, + 23 => 1, + 24 => 1, + 25 => 1, + ); + } + + /** + * Returns the lines where warnings should occur. + * + * @return array => + */ + public function getWarningList() { + return array( + 27 => 1, + 28 => 1, + ); + } + +} From bb93c38c29d9f16bed536050577cad8bf9392cf2 Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Wed, 20 Feb 2019 13:21:27 +0100 Subject: [PATCH 088/241] Fixes unit-test for removed ini_set check --- WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php b/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php index db73fe44bd..5470314fb6 100644 --- a/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php @@ -50,18 +50,17 @@ public function getWarningList() { 22 => 1, 23 => 1, 24 => 1, - 25 => 1, + 27 => 1, 28 => 1, 29 => 1, 30 => 1, 31 => 1, - 32 => 1, + 34 => 1, 35 => 1, 36 => 1, 37 => 1, 38 => 1, 39 => 1, - 40 => 1, ); } From 1650b77d0e662dc8daea3e9aaeec5c2eb0ab1eba Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Wed, 20 Feb 2019 14:32:45 +0100 Subject: [PATCH 089/241] Fixes codestyle --- WordPress/Sniffs/PHP/IniSetSniff.php | 94 ++++++++++++++-------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/WordPress/Sniffs/PHP/IniSetSniff.php b/WordPress/Sniffs/PHP/IniSetSniff.php index 40188062bb..f4c5475c9a 100644 --- a/WordPress/Sniffs/PHP/IniSetSniff.php +++ b/WordPress/Sniffs/PHP/IniSetSniff.php @@ -48,15 +48,15 @@ class IniSetSniff extends AbstractFunctionParameterSniff { * ); */ protected $whitelisted_options = array( - 'auto_detect_line_endings'=>array(), - 'highlight.bg'=>array(), - 'highlight.comment'=>array(), - 'highlight.default'=>array(), - 'highlight.html'=>array(), - 'highlight.keyword'=>array(), - 'highlight.string'=>array(), - 'short_open_tag'=>array( - 'valid_values'=>array('true', '1', 'On') + 'auto_detect_line_endings' => array(), + 'highlight.bg' => array(), + 'highlight.comment' => array(), + 'highlight.default' => array(), + 'highlight.html' => array(), + 'highlight.keyword' => array(), + 'highlight.string' => array(), + 'short_open_tag' => array( + 'valid_values' => array( 'true', '1', 'On' ), ), ); @@ -74,45 +74,45 @@ class IniSetSniff extends AbstractFunctionParameterSniff { * ); */ protected $blacklisted_options = array( - 'max_execution_time'=>array( - 'message'=>'Use `set_time_limit()` instead.' + 'max_execution_time' => array( + 'message' => 'Use `set_time_limit()` instead.', ), - 'short_open_tag'=>array( - 'invalid_values'=>array('false', '0', 'Off'), - 'message'=>'Turning off short_open_tag is prohibited as it might possibily break other plugins.', + 'short_open_tag' => array( + 'invalid_values' => array( 'false', '0', 'Off' ), + 'message' => 'Turning off short_open_tag is prohibited as it might possibily break other plugins.', ), - 'bcmath.scale'=>array( - 'message'=>'Use `bcscale()` instead.' + 'bcmath.scale' => array( + 'message' => 'Use `bcscale()` instead.', ), - 'display_errors'=>array( - 'message'=>'Use `WP_DEBUG_DISPLAY` instead.' + 'display_errors' => array( + 'message' => 'Use `WP_DEBUG_DISPLAY` instead.', ), - 'error_reporting'=>array( - 'message'=>'Use `WP_DEBUG` instead.' + 'error_reporting' => array( + 'message' => 'Use `WP_DEBUG` instead.', ), - 'filter.default'=>array( - 'message'=>'Use the filter flag constants when calling the functions instead (as you will possibly break other plugins if you change this).' + 'filter.default' => array( + 'message' => 'Use the filter flag constants when calling the functions instead (as you will possibly break other plugins if you change this).', ), - 'filter.default_flags'=>array( - 'message'=>'Use the filter flag constants when calling the functions instead (as you will possibly break other plugins if you change this).' + 'filter.default_flags' => array( + 'message' => 'Use the filter flag constants when calling the functions instead (as you will possibly break other plugins if you change this).', ), - 'iconv.input_encoding'=>array( - 'message'=>'PHP < 5.6 only - use `iconv_set_encoding()` instead.' + 'iconv.input_encoding' => array( + 'message' => 'PHP < 5.6 only - use `iconv_set_encoding()` instead.', ), - 'iconv.internal_encoding'=>array( - 'message'=>'PHP < 5.6 only - use `iconv_set_encoding()` instead.' + 'iconv.internal_encoding' => array( + 'message' => 'PHP < 5.6 only - use `iconv_set_encoding()` instead.', ), - 'iconv.output_encoding'=>array( - 'message'=>'PHP < 5.6 only - use `iconv_set_encoding()` instead.' + 'iconv.output_encoding' => array( + 'message' => 'PHP < 5.6 only - use `iconv_set_encoding()` instead.', ), - 'ignore_user_abort'=>array( - 'message'=>'Use `ignore_user_abort()` instead.' + 'ignore_user_abort' => array( + 'message' => 'Use `ignore_user_abort()` instead.', ), - 'log_errors'=>array( - 'message'=>'Use `WP_DEBUG_LOG` instead.' + 'log_errors' => array( + 'message' => 'Use `WP_DEBUG_LOG` instead.', ), - 'memory_limit'=>array( - 'message'=>'Use `wp_raise_memory_limit()` or hook into the filters in that function.' + 'memory_limit' => array( + 'message' => 'Use `wp_raise_memory_limit()` or hook into the filters in that function.', ), ); @@ -130,20 +130,20 @@ class IniSetSniff extends AbstractFunctionParameterSniff { * * @return void */ - public function process_parameters( $stackPtr, $group_name, $matched_content, $parameters ){ + public function process_parameters( $stackPtr, $group_name, $matched_content, $parameters ) { $ini_set_function = $this->tokens[ $stackPtr ]; - $option_name = $this->strip_quotes($parameters[1]['raw']); - $option_value = $this->strip_quotes($parameters[2]['raw']); - if(array_key_exists($option_name, $this->whitelisted_options)){ - $whitelisted_option = $this->whitelisted_options[$option_name]; - if(!isset($whitelisted_option['valid_values']) || in_array($option_value, $whitelisted_option['valid_values'], true) ){ + $option_name = $this->strip_quotes( $parameters[1]['raw'] ); + $option_value = $this->strip_quotes( $parameters[2]['raw'] ); + if ( array_key_exists( $option_name, $this->whitelisted_options ) ) { + $whitelisted_option = $this->whitelisted_options[ $option_name ]; + if ( ! isset( $whitelisted_option['valid_values'] ) || in_array( $option_value, $whitelisted_option['valid_values'], true ) ) { return; } } - if(array_key_exists($option_name, $this->blacklisted_options)){ - $blacklisted_option = $this->blacklisted_options[$option_name]; - if(!isset($blacklisted_option['invalid_values']) || in_array($option_value, $blacklisted_option['invalid_values'], true) ){ + if ( array_key_exists( $option_name, $this->blacklisted_options ) ) { + $blacklisted_option = $this->blacklisted_options[ $option_name ]; + if ( ! isset( $blacklisted_option['invalid_values'] ) || in_array( $option_value, $blacklisted_option['invalid_values'], true ) ) { $this->phpcsFile->addError( '%s(%s, %s) found. %s', $stackPtr, @@ -152,7 +152,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p $ini_set_function['content'], $parameters[1]['raw'], $parameters[2]['raw'], - $blacklisted_option['message'] + $blacklisted_option['message'], ) ); return; @@ -165,7 +165,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p array( $ini_set_function['content'], $parameters[1]['raw'], - $parameters[2]['raw'] + $parameters[2]['raw'], ) ); return; From 55c08d7b6ec4be992792f2c7c9361802d8a7d243 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 20 Feb 2019 15:35:34 +0100 Subject: [PATCH 090/241] AlternativeFunctions: allow for php://input used by file_get_contents() Reported by remcotolsma in 49e7700073b7486077c95b37afe55d129b3e4881#commitcomment-32391794 While a little esoteric in a WP context, using the WP File Wrapper functions is not a suitable alternative when `php://input` is being read. Includes unit test. --- WordPress/Sniffs/WP/AlternativeFunctionsSniff.php | 8 +++++++- WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php index 68092de5d0..675189b9b9 100644 --- a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php +++ b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php @@ -202,7 +202,13 @@ public function process_matched_token( $stackPtr, $group_name, $matched_content return; } - unset( $params ); + $raw_stripped = $this->strip_quotes( $params[1]['raw'] ); + if ( 'php://input' === $raw_stripped ) { + // This is not a file, but the read-only raw data stream from the request body. + return; + } + + unset( $params, $raw_stripped ); break; } diff --git a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc index ca2989c033..0f6974dcb6 100644 --- a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc +++ b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc @@ -50,3 +50,4 @@ file_get_contents(MYABSPATH . 'plugin-file.json'); // Warning. file_get_contents( MUPLUGINDIR . 'some-file.xml' ); // OK. file_get_contents( plugin_dir_path( __FILE__ ) . 'subfolder/*.conf' ); // OK. file_get_contents(WP_Upload_Dir()['path'] . 'subdir/file.inc'); // OK. +file_get_contents( 'php://input' ); // OK. From d3536cfbb4273220af59884ab8a5fa909885a654 Mon Sep 17 00:00:00 2001 From: Juliette <663378+jrfnl@users.noreply.github.com> Date: Wed, 20 Feb 2019 21:05:43 +0100 Subject: [PATCH 091/241] Update WordPress/Sniffs/PHP/IniSetSniff.php Co-Authored-By: NielsdeBlaauw --- WordPress/Sniffs/PHP/IniSetSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/Sniffs/PHP/IniSetSniff.php b/WordPress/Sniffs/PHP/IniSetSniff.php index f4c5475c9a..b8ccafac63 100644 --- a/WordPress/Sniffs/PHP/IniSetSniff.php +++ b/WordPress/Sniffs/PHP/IniSetSniff.php @@ -159,7 +159,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p } } $this->phpcsFile->addWarning( - '%s(%s, %s) found. Changing these configuration values at runtime is rarely necessary.', + '%s(%s, %s) found. Changing configuration values at runtime is rarely necessary.', $stackPtr, 'Risky', array( From 18a5cccb909b772ca491cf620df4914251608ce5 Mon Sep 17 00:00:00 2001 From: Juliette <663378+jrfnl@users.noreply.github.com> Date: Wed, 20 Feb 2019 21:05:51 +0100 Subject: [PATCH 092/241] Update WordPress/Tests/PHP/IniSetUnitTest.php Co-Authored-By: NielsdeBlaauw --- WordPress/Tests/PHP/IniSetUnitTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/Tests/PHP/IniSetUnitTest.php b/WordPress/Tests/PHP/IniSetUnitTest.php index 09ebff5095..b09e2f81d9 100644 --- a/WordPress/Tests/PHP/IniSetUnitTest.php +++ b/WordPress/Tests/PHP/IniSetUnitTest.php @@ -12,7 +12,7 @@ use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; /** - * Unit test class for the DontExtract sniff. + * Unit test class for the IniSet sniff. * * @package WPCS\WordPressCodingStandards * From 8d7593e9eb0804896da53f241f224f29215b432c Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Wed, 20 Feb 2019 21:17:12 +0100 Subject: [PATCH 093/241] Adds ini_alter checks --- WordPress/Sniff.php | 118 +++++++++--------- .../PHP/DiscouragedPHPFunctionsSniff.php | 1 - WordPress/Sniffs/PHP/IniSetSniff.php | 4 +- .../PHP/DiscouragedPHPFunctionsUnitTest.inc | 2 +- .../PHP/DiscouragedPHPFunctionsUnitTest.php | 1 - WordPress/Tests/PHP/IniSetUnitTest.inc | 4 + WordPress/Tests/PHP/IniSetUnitTest.php | 2 + 7 files changed, 68 insertions(+), 64 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 7d5de2c044..4d72469145 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -175,65 +175,65 @@ abstract class Sniff implements PHPCS_Sniff { * @var array */ protected $autoEscapedFunctions = array( - 'allowed_tags' => true, - 'bloginfo' => true, - 'body_class' => true, - 'calendar_week_mod' => true, - 'category_description' => true, - 'checked' => true, - 'comment_class' => true, - 'count' => true, - 'disabled' => true, - 'do_shortcode' => true, - 'do_shortcode_tag' => true, - 'get_archives_link' => true, - 'get_attachment_link' => true, - 'get_avatar' => true, - 'get_bookmark_field' => true, - 'get_calendar' => true, - 'get_comment_author_link' => true, - 'get_current_blog_id' => true, - 'get_delete_post_link' => true, - 'get_search_form' => true, - 'get_search_query' => true, - 'get_the_author_link' => true, - 'get_the_author' => true, - 'get_the_date' => true, - 'get_the_ID' => true, - 'get_the_post_thumbnail' => true, - 'get_the_term_list' => true, - 'paginate_comments_links' => true, - 'post_type_archive_title' => true, - 'readonly' => true, - 'selected' => true, - 'single_cat_title' => true, - 'single_month_title' => true, - 'single_post_title' => true, - 'single_tag_title' => true, - 'single_term_title' => true, - 'tag_description' => true, - 'term_description' => true, - 'the_author' => true, - 'the_date' => true, - 'the_title_attribute' => true, - 'walk_nav_menu_tree' => true, - 'wp_dropdown_categories' => true, - 'wp_dropdown_users' => true, - 'wp_generate_tag_cloud' => true, - 'wp_get_archives' => true, - 'wp_get_attachment_image' => true, - 'wp_get_attachment_link' => true, - 'wp_link_pages' => true, - 'wp_list_authors' => true, - 'wp_list_bookmarks' => true, - 'wp_list_categories' => true, - 'wp_list_comments' => true, - 'wp_login_form' => true, - 'wp_loginout' => true, - 'wp_nav_menu' => true, - 'wp_register' => true, - 'wp_tag_cloud' => true, - 'wp_title' => true, + 'allowed_tags' => true, + 'bloginfo' => true, + 'body_class' => true, + 'calendar_week_mod' => true, + 'category_description' => true, + 'checked' => true, + 'comment_class' => true, + 'count' => true, + 'disabled' => true, + 'do_shortcode' => true, + 'do_shortcode_tag' => true, + 'get_archives_link' => true, + 'get_attachment_link' => true, + 'get_avatar' => true, + 'get_bookmark_field' => true, + 'get_calendar' => true, + 'get_comment_author_link' => true, + 'get_current_blog_id' => true, + 'get_delete_post_link' => true, + 'get_search_form' => true, + 'get_search_query' => true, + 'get_the_author_link' => true, + 'get_the_author' => true, + 'get_the_date' => true, + 'get_the_ID' => true, + 'get_the_post_thumbnail' => true, + 'get_the_term_list' => true, + 'paginate_comments_links' => true, + 'post_type_archive_title' => true, + 'readonly' => true, + 'selected' => true, + 'single_cat_title' => true, + 'single_month_title' => true, + 'single_post_title' => true, + 'single_tag_title' => true, + 'single_term_title' => true, + 'tag_description' => true, + 'term_description' => true, + 'the_author' => true, + 'the_date' => true, + 'the_title_attribute' => true, + 'walk_nav_menu_tree' => true, + 'wp_dropdown_categories' => true, + 'wp_dropdown_users' => true, + 'wp_generate_tag_cloud' => true, + 'wp_get_archives' => true, + 'wp_get_attachment_image' => true, + 'wp_get_attachment_link' => true, + 'wp_link_pages' => true, + 'wp_list_authors' => true, + 'wp_list_bookmarks' => true, + 'wp_list_categories' => true, + 'wp_list_comments' => true, + 'wp_login_form' => true, + 'wp_loginout' => true, + 'wp_nav_menu' => true, + 'wp_register' => true, + 'wp_tag_cloud' => true, + 'wp_title' => true, ); /** diff --git a/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php b/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php index 62102f3c39..5fb8f9e7b4 100644 --- a/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php @@ -59,7 +59,6 @@ public function getGroups() { 'message' => '%s() found. Changing configuration at runtime is rarely necessary.', 'functions' => array( 'error_reporting', - 'ini_alter', 'ini_restore', 'apache_setenv', 'putenv', diff --git a/WordPress/Sniffs/PHP/IniSetSniff.php b/WordPress/Sniffs/PHP/IniSetSniff.php index b8ccafac63..b271a65fe1 100644 --- a/WordPress/Sniffs/PHP/IniSetSniff.php +++ b/WordPress/Sniffs/PHP/IniSetSniff.php @@ -32,7 +32,8 @@ class IniSetSniff extends AbstractFunctionParameterSniff { * ); */ protected $target_functions = array( - 'ini_set' => array(), + 'ini_set' => array(), + 'ini_alter' => array(), ); /** @@ -168,6 +169,5 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p $parameters[2]['raw'], ) ); - return; } } diff --git a/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.inc b/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.inc index 5a6e9a5577..9a17c8a6d8 100644 --- a/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.inc +++ b/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.inc @@ -14,7 +14,7 @@ rawurlencode(); // Ok. dl(); // Warning. error_reporting(); // Warning. -ini_alter(); // Warning. + ini_restore(); // Warning. magic_quotes_runtime(); // Warning. set_magic_quotes_runtime(); // Warning. diff --git a/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php b/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php index 5470314fb6..0b43deffe5 100644 --- a/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php @@ -42,7 +42,6 @@ public function getWarningList() { 12 => 1, 15 => 1, 16 => 1, - 17 => 1, 18 => 1, 19 => 1, 20 => 1, diff --git a/WordPress/Tests/PHP/IniSetUnitTest.inc b/WordPress/Tests/PHP/IniSetUnitTest.inc index ef198be6a6..5f13927979 100644 --- a/WordPress/Tests/PHP/IniSetUnitTest.inc +++ b/WordPress/Tests/PHP/IniSetUnitTest.inc @@ -26,3 +26,7 @@ ini_set('memory_limit', -1); // Error. ini_set('report_memleaks', true); // Warning. ini_set('short_open_tag', 1230); // Warning. + +ini_alter('auto_detect_line_endings', true); // Ok. +ini_alter('display_errors', false); // Error. +ini_set('report_memleaks', 1230); // Warning. diff --git a/WordPress/Tests/PHP/IniSetUnitTest.php b/WordPress/Tests/PHP/IniSetUnitTest.php index b09e2f81d9..3022eed55a 100644 --- a/WordPress/Tests/PHP/IniSetUnitTest.php +++ b/WordPress/Tests/PHP/IniSetUnitTest.php @@ -43,6 +43,7 @@ public function getErrorList() { 23 => 1, 24 => 1, 25 => 1, + 31 => 1, ); } @@ -55,6 +56,7 @@ public function getWarningList() { return array( 27 => 1, 28 => 1, + 32 => 1, ); } From 43acdd26e709dd29d888e0ede6d24c76511fb95f Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Wed, 20 Feb 2019 21:19:52 +0100 Subject: [PATCH 094/241] Adds test marking variable option name as risky --- WordPress/Tests/PHP/IniSetUnitTest.inc | 1 + WordPress/Tests/PHP/IniSetUnitTest.php | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/WordPress/Tests/PHP/IniSetUnitTest.inc b/WordPress/Tests/PHP/IniSetUnitTest.inc index 5f13927979..9d939d8801 100644 --- a/WordPress/Tests/PHP/IniSetUnitTest.inc +++ b/WordPress/Tests/PHP/IniSetUnitTest.inc @@ -26,6 +26,7 @@ ini_set('memory_limit', -1); // Error. ini_set('report_memleaks', true); // Warning. ini_set('short_open_tag', 1230); // Warning. +ini_set($test, 1230); // Warning. ini_alter('auto_detect_line_endings', true); // Ok. ini_alter('display_errors', false); // Error. diff --git a/WordPress/Tests/PHP/IniSetUnitTest.php b/WordPress/Tests/PHP/IniSetUnitTest.php index 3022eed55a..0f96f571a6 100644 --- a/WordPress/Tests/PHP/IniSetUnitTest.php +++ b/WordPress/Tests/PHP/IniSetUnitTest.php @@ -43,7 +43,7 @@ public function getErrorList() { 23 => 1, 24 => 1, 25 => 1, - 31 => 1, + 32 => 1, ); } @@ -56,7 +56,8 @@ public function getWarningList() { return array( 27 => 1, 28 => 1, - 32 => 1, + 29 => 1, + 33 => 1, ); } From f0b223e6157095734f74f0471791433e91f94289 Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Wed, 20 Feb 2019 21:26:00 +0100 Subject: [PATCH 095/241] Isset instead of array_key_exists --- WordPress/Sniffs/PHP/IniSetSniff.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/Sniffs/PHP/IniSetSniff.php b/WordPress/Sniffs/PHP/IniSetSniff.php index b271a65fe1..c8bab3218e 100644 --- a/WordPress/Sniffs/PHP/IniSetSniff.php +++ b/WordPress/Sniffs/PHP/IniSetSniff.php @@ -135,14 +135,14 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p $ini_set_function = $this->tokens[ $stackPtr ]; $option_name = $this->strip_quotes( $parameters[1]['raw'] ); $option_value = $this->strip_quotes( $parameters[2]['raw'] ); - if ( array_key_exists( $option_name, $this->whitelisted_options ) ) { + if ( isset( $this->whitelisted_options[ $option_name ] ) ) { $whitelisted_option = $this->whitelisted_options[ $option_name ]; if ( ! isset( $whitelisted_option['valid_values'] ) || in_array( $option_value, $whitelisted_option['valid_values'], true ) ) { return; } } - if ( array_key_exists( $option_name, $this->blacklisted_options ) ) { + if ( isset( $this->blacklisted_options[ $option_name ] ) ) { $blacklisted_option = $this->blacklisted_options[ $option_name ]; if ( ! isset( $blacklisted_option['invalid_values'] ) || in_array( $option_value, $blacklisted_option['invalid_values'], true ) ) { $this->phpcsFile->addError( From a8f3f1032083497caa3d68c7e3f867466d2248af Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Wed, 20 Feb 2019 21:33:20 +0100 Subject: [PATCH 096/241] Adds modular sniff name, removes use --- WordPress/Sniffs/PHP/IniSetSniff.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/Sniffs/PHP/IniSetSniff.php b/WordPress/Sniffs/PHP/IniSetSniff.php index c8bab3218e..fdcce52fe9 100644 --- a/WordPress/Sniffs/PHP/IniSetSniff.php +++ b/WordPress/Sniffs/PHP/IniSetSniff.php @@ -10,7 +10,6 @@ namespace WordPressCS\WordPress\Sniffs\PHP; use WordPressCS\WordPress\AbstractFunctionParameterSniff; -use \PHP_CodeSniffer\Util\Tokens; /** * Checks use of ini_set function with a blacklist for errors. @@ -148,7 +147,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p $this->phpcsFile->addError( '%s(%s, %s) found. %s', $stackPtr, - 'Blacklisted', + $this->string_to_errorcode( $option_name . '_Blacklisted' ), array( $ini_set_function['content'], $parameters[1]['raw'], @@ -159,6 +158,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p return; } } + $this->phpcsFile->addWarning( '%s(%s, %s) found. Changing configuration values at runtime is rarely necessary.', $stackPtr, From 1290ca4a8210356f8251357e2bef0ce53e4eaf73 Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Wed, 20 Feb 2019 21:41:00 +0100 Subject: [PATCH 097/241] Adds alternative invalid and valid values --- WordPress/Tests/PHP/IniSetUnitTest.inc | 10 +++++++--- WordPress/Tests/PHP/IniSetUnitTest.php | 14 ++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/WordPress/Tests/PHP/IniSetUnitTest.inc b/WordPress/Tests/PHP/IniSetUnitTest.inc index 9d939d8801..b28fb2eee8 100644 --- a/WordPress/Tests/PHP/IniSetUnitTest.inc +++ b/WordPress/Tests/PHP/IniSetUnitTest.inc @@ -8,9 +8,9 @@ ini_set('highlight.html', '#FFFFFF'); // Ok. ini_set('highlight.keyword', '#FFFFFF'); // Ok. ini_set('highlight.string', '#FFFFFF'); // Ok. ini_set('short_open_tag', true); // Ok. +ini_set('short_open_tag', 1); // Ok. +ini_set('short_open_tag', 'On'); // Ok. -ini_set('max_execution_time', 60); // Error. -ini_set('short_open_tag', false); // Error. ini_set('bcmath.scale', 0); // Error. ini_set('display_errors', 0); // Error. ini_set('error_reporting', 0); // Error. @@ -22,7 +22,11 @@ ini_set('iconv.output_encoding', ''); // Error. ini_set('iconv.output_encoding', ''); // Error. ini_set('ignore_user_abort', true); // Error. ini_set('log_errors', true); // Error. +ini_set('max_execution_time', 60); // Error. ini_set('memory_limit', -1); // Error. +ini_set('short_open_tag', false); // Error. +ini_set('short_open_tag', 0); // Error. +ini_set('short_open_tag', 'Off'); // Error. ini_set('report_memleaks', true); // Warning. ini_set('short_open_tag', 1230); // Warning. @@ -30,4 +34,4 @@ ini_set($test, 1230); // Warning. ini_alter('auto_detect_line_endings', true); // Ok. ini_alter('display_errors', false); // Error. -ini_set('report_memleaks', 1230); // Warning. +ini_alter('report_memleaks', 1230); // Warning. diff --git a/WordPress/Tests/PHP/IniSetUnitTest.php b/WordPress/Tests/PHP/IniSetUnitTest.php index 0f96f571a6..e110217212 100644 --- a/WordPress/Tests/PHP/IniSetUnitTest.php +++ b/WordPress/Tests/PHP/IniSetUnitTest.php @@ -29,8 +29,6 @@ class IniSetUnitTest extends AbstractSniffUnitTest { */ public function getErrorList() { return array( - 12 => 1, - 13 => 1, 14 => 1, 15 => 1, 16 => 1, @@ -43,7 +41,11 @@ public function getErrorList() { 23 => 1, 24 => 1, 25 => 1, - 32 => 1, + 26 => 1, + 27 => 1, + 28 => 1, + 29 => 1, + 36 => 1, ); } @@ -54,10 +56,10 @@ public function getErrorList() { */ public function getWarningList() { return array( - 27 => 1, - 28 => 1, - 29 => 1, + 31 => 1, + 32 => 1, 33 => 1, + 37 => 1, ); } From 8da3b6d96f0508bea090106fe1bc51ae4f286196 Mon Sep 17 00:00:00 2001 From: Juliette <663378+jrfnl@users.noreply.github.com> Date: Wed, 20 Feb 2019 21:45:40 +0100 Subject: [PATCH 098/241] Apply suggestions from code review Co-Authored-By: NielsdeBlaauw --- WordPress/Sniffs/PHP/IniSetSniff.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/WordPress/Sniffs/PHP/IniSetSniff.php b/WordPress/Sniffs/PHP/IniSetSniff.php index fdcce52fe9..4993d056a7 100644 --- a/WordPress/Sniffs/PHP/IniSetSniff.php +++ b/WordPress/Sniffs/PHP/IniSetSniff.php @@ -12,7 +12,11 @@ use WordPressCS\WordPress\AbstractFunctionParameterSniff; /** - * Checks use of ini_set function with a blacklist for errors. + * Detect use of the `ini_set()` function. + * + * - Won't throw notices for "safe" ini directives as listed in the whitelist. + * - Throws errors for ini directives listed in the blacklist. + * - A warning will be thrown in all other cases. * * @package WPCS\WordPressCodingStandards * @@ -21,7 +25,7 @@ class IniSetSniff extends AbstractFunctionParameterSniff { /** - * Array of functions that must be checked + * Array of functions that must be checked. * * @since x.x.x * @@ -36,7 +40,7 @@ class IniSetSniff extends AbstractFunctionParameterSniff { ); /** - * Array of options that are allowed to be manipulated + * Array of PHP configuration options that are allowed to be manipulated. * * @since x.x.x * @@ -61,7 +65,7 @@ class IniSetSniff extends AbstractFunctionParameterSniff { ); /** - * Array of options that are not allowed to be manipulated + * Array of PHP configuration options that are not allowed to be manipulated. * * @since x.x.x * @@ -79,7 +83,7 @@ class IniSetSniff extends AbstractFunctionParameterSniff { ), 'short_open_tag' => array( 'invalid_values' => array( 'false', '0', 'Off' ), - 'message' => 'Turning off short_open_tag is prohibited as it might possibily break other plugins.', + 'message' => 'Turning off short_open_tag is prohibited as it can break other plugins.', ), 'bcmath.scale' => array( 'message' => 'Use `bcscale()` instead.', @@ -91,7 +95,7 @@ class IniSetSniff extends AbstractFunctionParameterSniff { 'message' => 'Use `WP_DEBUG` instead.', ), 'filter.default' => array( - 'message' => 'Use the filter flag constants when calling the functions instead (as you will possibly break other plugins if you change this).', + 'message' => 'Changing the option value can break other plugins. Use the filter flag constants when calling the Filter functions instead.', ), 'filter.default_flags' => array( 'message' => 'Use the filter flag constants when calling the functions instead (as you will possibly break other plugins if you change this).', @@ -149,7 +153,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p $stackPtr, $this->string_to_errorcode( $option_name . '_Blacklisted' ), array( - $ini_set_function['content'], + $matched_content, $parameters[1]['raw'], $parameters[2]['raw'], $blacklisted_option['message'], @@ -164,7 +168,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p $stackPtr, 'Risky', array( - $ini_set_function['content'], + $matched_content, $parameters[1]['raw'], $parameters[2]['raw'], ) From bc8d26a203d46c3f63d0d19091f825e82d0ec36c Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Wed, 20 Feb 2019 21:49:30 +0100 Subject: [PATCH 099/241] Adds @since tags --- WordPress/Sniffs/PHP/IniSetSniff.php | 10 +++++----- WordPress/Tests/PHP/IniSetUnitTest.php | 4 +--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/WordPress/Sniffs/PHP/IniSetSniff.php b/WordPress/Sniffs/PHP/IniSetSniff.php index 4993d056a7..cdf9f6d689 100644 --- a/WordPress/Sniffs/PHP/IniSetSniff.php +++ b/WordPress/Sniffs/PHP/IniSetSniff.php @@ -20,14 +20,14 @@ * * @package WPCS\WordPressCodingStandards * - * @since x.x.x + * @since 2.1.0 */ class IniSetSniff extends AbstractFunctionParameterSniff { /** * Array of functions that must be checked. * - * @since x.x.x + * @since 2.1.0 * * @var array Multidimensional array with parameter details. * $target_functions = array( @@ -42,7 +42,7 @@ class IniSetSniff extends AbstractFunctionParameterSniff { /** * Array of PHP configuration options that are allowed to be manipulated. * - * @since x.x.x + * @since 2.1.0 * * @var array Multidimensional array with parameter details. * $whitelisted_options = array( @@ -67,7 +67,7 @@ class IniSetSniff extends AbstractFunctionParameterSniff { /** * Array of PHP configuration options that are not allowed to be manipulated. * - * @since x.x.x + * @since 2.1.0 * * @var array Multidimensional array with parameter details. * $blacklisted_options = array( @@ -125,7 +125,7 @@ class IniSetSniff extends AbstractFunctionParameterSniff { * is found in the blacklist. Warns as 'risky' when the option is not * found in the whitelist. * - * @since x.x.x + * @since 2.1.0 * * @param int $stackPtr The position of the current token in the stack. * @param array $group_name The name of the group which was matched. diff --git a/WordPress/Tests/PHP/IniSetUnitTest.php b/WordPress/Tests/PHP/IniSetUnitTest.php index e110217212..938f7cac93 100644 --- a/WordPress/Tests/PHP/IniSetUnitTest.php +++ b/WordPress/Tests/PHP/IniSetUnitTest.php @@ -16,9 +16,7 @@ * * @package WPCS\WordPressCodingStandards * - * @since 0.10.0 - * @since 0.13.0 Class name changed: this class is now namespaced. - * @since 1.0.0 This sniff has been moved from the `Functions` category to the `PHP` category. + * @since 2.1.0 */ class IniSetUnitTest extends AbstractSniffUnitTest { From 6d54ff399533d94a6155061c89c3166b9b5f5015 Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Wed, 20 Feb 2019 22:03:05 +0100 Subject: [PATCH 100/241] Adds sniff to WP-extra, doc fixes and unused statement removed --- WordPress-Extra/ruleset.xml | 4 ++++ WordPress/Sniffs/PHP/IniSetSniff.php | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index b03af3ee86..6ff9b6cf42 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -113,6 +113,10 @@ https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/242 --> + + + diff --git a/WordPress/Sniffs/PHP/IniSetSniff.php b/WordPress/Sniffs/PHP/IniSetSniff.php index cdf9f6d689..72cacaea32 100644 --- a/WordPress/Sniffs/PHP/IniSetSniff.php +++ b/WordPress/Sniffs/PHP/IniSetSniff.php @@ -121,9 +121,10 @@ class IniSetSniff extends AbstractFunctionParameterSniff { ); /** - * Process the parameter of a matched function. Errors if an option - * is found in the blacklist. Warns as 'risky' when the option is not - * found in the whitelist. + * Process the parameter of a matched function. + * + * Errors if an option is found in the blacklist. Warns as + * 'risky' when the option is not found in the whitelist. * * @since 2.1.0 * @@ -135,9 +136,8 @@ class IniSetSniff extends AbstractFunctionParameterSniff { * @return void */ public function process_parameters( $stackPtr, $group_name, $matched_content, $parameters ) { - $ini_set_function = $this->tokens[ $stackPtr ]; - $option_name = $this->strip_quotes( $parameters[1]['raw'] ); - $option_value = $this->strip_quotes( $parameters[2]['raw'] ); + $option_name = $this->strip_quotes( $parameters[1]['raw'] ); + $option_value = $this->strip_quotes( $parameters[2]['raw'] ); if ( isset( $this->whitelisted_options[ $option_name ] ) ) { $whitelisted_option = $this->whitelisted_options[ $option_name ]; if ( ! isset( $whitelisted_option['valid_values'] ) || in_array( $option_value, $whitelisted_option['valid_values'], true ) ) { From 5e5a8710fb106293f723b2bf22f2738038045c30 Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Fri, 22 Feb 2019 20:18:01 +0100 Subject: [PATCH 101/241] Better wording for warning message --- WordPress/Sniffs/PHP/IniSetSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/Sniffs/PHP/IniSetSniff.php b/WordPress/Sniffs/PHP/IniSetSniff.php index 72cacaea32..06532461bf 100644 --- a/WordPress/Sniffs/PHP/IniSetSniff.php +++ b/WordPress/Sniffs/PHP/IniSetSniff.php @@ -164,7 +164,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p } $this->phpcsFile->addWarning( - '%s(%s, %s) found. Changing configuration values at runtime is rarely necessary.', + '%s(%s, %s) found. Changing configuration values at runtime is strongly discouraged.', $stackPtr, 'Risky', array( From 51331e11bd24dddc2863d43a4103682c39fa1d75 Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Fri, 22 Feb 2019 20:21:36 +0100 Subject: [PATCH 102/241] Consistent wording for the discouraged PHP functions --- WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php b/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php index 5fb8f9e7b4..e2691c2e60 100644 --- a/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php @@ -56,7 +56,7 @@ public function getGroups() { 'runtime_configuration' => array( 'type' => 'warning', - 'message' => '%s() found. Changing configuration at runtime is rarely necessary.', + 'message' => '%s() found. Changing configuration values at runtime is strongly discouraged.', 'functions' => array( 'error_reporting', 'ini_restore', From 72353264505f698c65c66f543e970736c0eb764a Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Fri, 22 Feb 2019 20:28:00 +0100 Subject: [PATCH 103/241] Array in target_functions had no use, replaced with true --- WordPress/Sniffs/PHP/IniSetSniff.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/Sniffs/PHP/IniSetSniff.php b/WordPress/Sniffs/PHP/IniSetSniff.php index 06532461bf..243a4f7ba5 100644 --- a/WordPress/Sniffs/PHP/IniSetSniff.php +++ b/WordPress/Sniffs/PHP/IniSetSniff.php @@ -35,8 +35,8 @@ class IniSetSniff extends AbstractFunctionParameterSniff { * ); */ protected $target_functions = array( - 'ini_set' => array(), - 'ini_alter' => array(), + 'ini_set' => true, + 'ini_alter' => true, ); /** From d97fba416df7c750ccd3d6da8af423b94351b577 Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Fri, 22 Feb 2019 20:31:27 +0100 Subject: [PATCH 104/241] Alphabetical ordering for blacklisted_options --- WordPress/Sniffs/PHP/IniSetSniff.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/WordPress/Sniffs/PHP/IniSetSniff.php b/WordPress/Sniffs/PHP/IniSetSniff.php index 243a4f7ba5..71dbcbaa8a 100644 --- a/WordPress/Sniffs/PHP/IniSetSniff.php +++ b/WordPress/Sniffs/PHP/IniSetSniff.php @@ -78,13 +78,6 @@ class IniSetSniff extends AbstractFunctionParameterSniff { * ); */ protected $blacklisted_options = array( - 'max_execution_time' => array( - 'message' => 'Use `set_time_limit()` instead.', - ), - 'short_open_tag' => array( - 'invalid_values' => array( 'false', '0', 'Off' ), - 'message' => 'Turning off short_open_tag is prohibited as it can break other plugins.', - ), 'bcmath.scale' => array( 'message' => 'Use `bcscale()` instead.', ), @@ -115,9 +108,16 @@ class IniSetSniff extends AbstractFunctionParameterSniff { 'log_errors' => array( 'message' => 'Use `WP_DEBUG_LOG` instead.', ), + 'max_execution_time' => array( + 'message' => 'Use `set_time_limit()` instead.', + ), 'memory_limit' => array( 'message' => 'Use `wp_raise_memory_limit()` or hook into the filters in that function.', ), + 'short_open_tag' => array( + 'invalid_values' => array( 'false', '0', 'Off' ), + 'message' => 'Turning off short_open_tag is prohibited as it can break other plugins.', + ), ); /** From 029f02e76af6a6c37562f44d7b887e32f78a79e7 Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Fri, 22 Feb 2019 20:34:17 +0100 Subject: [PATCH 105/241] Better message for filter.default_flags --- WordPress/Sniffs/PHP/IniSetSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/Sniffs/PHP/IniSetSniff.php b/WordPress/Sniffs/PHP/IniSetSniff.php index 71dbcbaa8a..2f768a3970 100644 --- a/WordPress/Sniffs/PHP/IniSetSniff.php +++ b/WordPress/Sniffs/PHP/IniSetSniff.php @@ -91,7 +91,7 @@ class IniSetSniff extends AbstractFunctionParameterSniff { 'message' => 'Changing the option value can break other plugins. Use the filter flag constants when calling the Filter functions instead.', ), 'filter.default_flags' => array( - 'message' => 'Use the filter flag constants when calling the functions instead (as you will possibly break other plugins if you change this).', + 'message' => 'Changing the option value can break other plugins. Use the filter flag constants when calling the Filter functions instead.', ), 'iconv.input_encoding' => array( 'message' => 'PHP < 5.6 only - use `iconv_set_encoding()` instead.', From be87a89e650ef35a962eaa3c0f689488880fdb8a Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Fri, 22 Feb 2019 20:40:20 +0100 Subject: [PATCH 106/241] Resets phpcbf on Sniff.php --- WordPress/Sniff.php | 118 ++++++++++++++++++++++---------------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 4d72469145..7d5de2c044 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -175,65 +175,65 @@ abstract class Sniff implements PHPCS_Sniff { * @var array */ protected $autoEscapedFunctions = array( - 'allowed_tags' => true, - 'bloginfo' => true, - 'body_class' => true, - 'calendar_week_mod' => true, - 'category_description' => true, - 'checked' => true, - 'comment_class' => true, - 'count' => true, - 'disabled' => true, - 'do_shortcode' => true, - 'do_shortcode_tag' => true, - 'get_archives_link' => true, - 'get_attachment_link' => true, - 'get_avatar' => true, - 'get_bookmark_field' => true, - 'get_calendar' => true, - 'get_comment_author_link' => true, - 'get_current_blog_id' => true, - 'get_delete_post_link' => true, - 'get_search_form' => true, - 'get_search_query' => true, - 'get_the_author_link' => true, - 'get_the_author' => true, - 'get_the_date' => true, - 'get_the_ID' => true, - 'get_the_post_thumbnail' => true, - 'get_the_term_list' => true, - 'paginate_comments_links' => true, - 'post_type_archive_title' => true, - 'readonly' => true, - 'selected' => true, - 'single_cat_title' => true, - 'single_month_title' => true, - 'single_post_title' => true, - 'single_tag_title' => true, - 'single_term_title' => true, - 'tag_description' => true, - 'term_description' => true, - 'the_author' => true, - 'the_date' => true, - 'the_title_attribute' => true, - 'walk_nav_menu_tree' => true, - 'wp_dropdown_categories' => true, - 'wp_dropdown_users' => true, - 'wp_generate_tag_cloud' => true, - 'wp_get_archives' => true, - 'wp_get_attachment_image' => true, - 'wp_get_attachment_link' => true, - 'wp_link_pages' => true, - 'wp_list_authors' => true, - 'wp_list_bookmarks' => true, - 'wp_list_categories' => true, - 'wp_list_comments' => true, - 'wp_login_form' => true, - 'wp_loginout' => true, - 'wp_nav_menu' => true, - 'wp_register' => true, - 'wp_tag_cloud' => true, - 'wp_title' => true, + 'allowed_tags' => true, + 'bloginfo' => true, + 'body_class' => true, + 'calendar_week_mod' => true, + 'category_description' => true, + 'checked' => true, + 'comment_class' => true, + 'count' => true, + 'disabled' => true, + 'do_shortcode' => true, + 'do_shortcode_tag' => true, + 'get_archives_link' => true, + 'get_attachment_link' => true, + 'get_avatar' => true, + 'get_bookmark_field' => true, + 'get_calendar' => true, + 'get_comment_author_link' => true, + 'get_current_blog_id' => true, + 'get_delete_post_link' => true, + 'get_search_form' => true, + 'get_search_query' => true, + 'get_the_author_link' => true, + 'get_the_author' => true, + 'get_the_date' => true, + 'get_the_ID' => true, + 'get_the_post_thumbnail' => true, + 'get_the_term_list' => true, + 'paginate_comments_links' => true, + 'post_type_archive_title' => true, + 'readonly' => true, + 'selected' => true, + 'single_cat_title' => true, + 'single_month_title' => true, + 'single_post_title' => true, + 'single_tag_title' => true, + 'single_term_title' => true, + 'tag_description' => true, + 'term_description' => true, + 'the_author' => true, + 'the_date' => true, + 'the_title_attribute' => true, + 'walk_nav_menu_tree' => true, + 'wp_dropdown_categories' => true, + 'wp_dropdown_users' => true, + 'wp_generate_tag_cloud' => true, + 'wp_get_archives' => true, + 'wp_get_attachment_image' => true, + 'wp_get_attachment_link' => true, + 'wp_link_pages' => true, + 'wp_list_authors' => true, + 'wp_list_bookmarks' => true, + 'wp_list_categories' => true, + 'wp_list_comments' => true, + 'wp_login_form' => true, + 'wp_loginout' => true, + 'wp_nav_menu' => true, + 'wp_register' => true, + 'wp_tag_cloud' => true, + 'wp_title' => true, ); /** From 9f6c94baf5b6aa26f007f555ce5ac7b84ae770ae Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Sun, 24 Feb 2019 10:45:36 +0100 Subject: [PATCH 107/241] Adds more testcases. Option value is no longer case sensitive --- WordPress/Sniffs/PHP/IniSetSniff.php | 8 ++++---- WordPress/Tests/PHP/IniSetUnitTest.inc | 6 ++++++ WordPress/Tests/PHP/IniSetUnitTest.php | 16 ++++++++++------ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/WordPress/Sniffs/PHP/IniSetSniff.php b/WordPress/Sniffs/PHP/IniSetSniff.php index 2f768a3970..afd58f1bf8 100644 --- a/WordPress/Sniffs/PHP/IniSetSniff.php +++ b/WordPress/Sniffs/PHP/IniSetSniff.php @@ -60,7 +60,7 @@ class IniSetSniff extends AbstractFunctionParameterSniff { 'highlight.keyword' => array(), 'highlight.string' => array(), 'short_open_tag' => array( - 'valid_values' => array( 'true', '1', 'On' ), + 'valid_values' => array( 'true', '1', 'on' ), ), ); @@ -115,7 +115,7 @@ class IniSetSniff extends AbstractFunctionParameterSniff { 'message' => 'Use `wp_raise_memory_limit()` or hook into the filters in that function.', ), 'short_open_tag' => array( - 'invalid_values' => array( 'false', '0', 'Off' ), + 'invalid_values' => array( 'false', '0', 'off' ), 'message' => 'Turning off short_open_tag is prohibited as it can break other plugins.', ), ); @@ -140,14 +140,14 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p $option_value = $this->strip_quotes( $parameters[2]['raw'] ); if ( isset( $this->whitelisted_options[ $option_name ] ) ) { $whitelisted_option = $this->whitelisted_options[ $option_name ]; - if ( ! isset( $whitelisted_option['valid_values'] ) || in_array( $option_value, $whitelisted_option['valid_values'], true ) ) { + if ( ! isset( $whitelisted_option['valid_values'] ) || in_array( strtolower( $option_value ), $whitelisted_option['valid_values'], true ) ) { return; } } if ( isset( $this->blacklisted_options[ $option_name ] ) ) { $blacklisted_option = $this->blacklisted_options[ $option_name ]; - if ( ! isset( $blacklisted_option['invalid_values'] ) || in_array( $option_value, $blacklisted_option['invalid_values'], true ) ) { + if ( ! isset( $blacklisted_option['invalid_values'] ) || in_array( strtolower( $option_value ), $blacklisted_option['invalid_values'], true ) ) { $this->phpcsFile->addError( '%s(%s, %s) found. %s', $stackPtr, diff --git a/WordPress/Tests/PHP/IniSetUnitTest.inc b/WordPress/Tests/PHP/IniSetUnitTest.inc index b28fb2eee8..b39d3e1a3b 100644 --- a/WordPress/Tests/PHP/IniSetUnitTest.inc +++ b/WordPress/Tests/PHP/IniSetUnitTest.inc @@ -1,6 +1,7 @@ 1, - 15 => 1, 16 => 1, 17 => 1, 18 => 1, @@ -43,7 +41,12 @@ public function getErrorList() { 27 => 1, 28 => 1, 29 => 1, - 36 => 1, + 30 => 1, + 31 => 1, + 32 => 1, + 33 => 1, + 34 => 1, + 42 => 1, ); } @@ -54,10 +57,11 @@ public function getErrorList() { */ public function getWarningList() { return array( - 31 => 1, - 32 => 1, - 33 => 1, + 36 => 1, 37 => 1, + 38 => 1, + 39 => 1, + 43 => 1, ); } From b417db32694ea08fa88ff5a63d0a2863cb89f6a8 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 6 Mar 2019 18:28:26 +0100 Subject: [PATCH 108/241] WP/AlternativeFunctions: allow for more input streams with file related functions Similar to 1649 which allowed for using `php://input` with `file_get_contents()` and surprisingly inspired by the closing of issue 295. This PR expands on the earlier work done in relation to the PHP native input streams by: * recognizing more PHP native input streams; * recognizing the PHP input stream constants; * allowing for these in a number of the `file_system_read` group functions as well as for the `file_get_contents` function. Refs: * http://php.net/manual/en/wrappers.php.php * http://php.net/manual/en/features.commandline.io-streams.php Includes unit tests. Related 1649 Related 295 Notes: * I have not checked the WP FileSystem to see if it even could handle these input streams. If it can, we may need to discuss what is the preferred option in that case. Personally, this to me seems like something for which the WP FileSystem would be overkill/superfluous. * At a later point in time, the new method + properties could be a candidate for moving to `Sniff` or a separate utility class. As no other sniffs currently need them though, this is not necessary at this moment and could possible be combined with/actioned when 1465 comes into play. --- .../Sniffs/WP/AlternativeFunctionsSniff.php | 101 ++++++++++++++++-- .../Tests/WP/AlternativeFunctionsUnitTest.inc | 15 +++ .../Tests/WP/AlternativeFunctionsUnitTest.php | 8 +- 3 files changed, 111 insertions(+), 13 deletions(-) diff --git a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php index 675189b9b9..556f3f90e6 100644 --- a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php +++ b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php @@ -25,6 +25,47 @@ */ class AlternativeFunctionsSniff extends AbstractFunctionRestrictionsSniff { + /** + * Local input streams which should not be flagged for the file system function checks. + * + * @link http://php.net/manual/en/wrappers.php.php + * + * @var array + */ + protected $allowed_local_streams = array( + 'php://input' => true, + 'php://output' => true, + 'php://stdin' => true, + 'php://stdout' => true, + 'php://stderr' => true, + ); + + /** + * Local input streams which should not be flagged for the file system function checks if + * the $filename starts with them. + * + * @link http://php.net/manual/en/wrappers.php.php + * + * @var array + */ + protected $allowed_local_stream_partials = array( + 'php://temp/', + 'php://fd/', + ); + + /** + * Local input stream constants which should not be flagged for the file system function checks. + * + * @link http://php.net/manual/en/wrappers.php.php + * + * @var array + */ + protected $allowed_local_stream_constants = array( + 'STDIN' => true, + 'STDOUT' => true, + 'STDERR' => true, + ); + /** * Groups of functions to restrict. * @@ -83,13 +124,13 @@ public function getGroups() { 'since' => '2.5.0', 'functions' => array( 'readfile', - 'fopen', - 'fsockopen', - 'pfsockopen', 'fclose', + 'fopen', 'fread', 'fwrite', 'file_put_contents', + 'fsockopen', + 'pfsockopen', ), ), @@ -202,13 +243,34 @@ public function process_matched_token( $stackPtr, $group_name, $matched_content return; } - $raw_stripped = $this->strip_quotes( $params[1]['raw'] ); - if ( 'php://input' === $raw_stripped ) { - // This is not a file, but the read-only raw data stream from the request body. + if ( $this->is_local_data_stream( $params[1]['raw'] ) === true ) { + // Local data stream. return; } - unset( $params, $raw_stripped ); + unset( $params ); + + break; + + case 'readfile': + case 'fopen': + case 'file_put_contents': + /* + * Allow for handling raw data streams from the request body. + */ + $first_param = $this->get_function_call_parameter( $stackPtr, 1 ); + + if ( false === $first_param ) { + // If the file to work with is not set, local data streams don't come into play. + break; + } + + if ( $this->is_local_data_stream( $first_param['raw'] ) === true ) { + // Local data stream. + return; + } + + unset( $first_param ); break; } @@ -223,4 +285,29 @@ public function process_matched_token( $stackPtr, $group_name, $matched_content } } + /** + * Determine based on the "raw" parameter value, whether a file parameter points to + * a local data stream. + * + * @param string $raw_param_value Raw parameter value. + * + * @return bool True if this is a local data stream. False otherwise. + */ + protected function is_local_data_stream( $raw_param_value ) { + + $raw_stripped = $this->strip_quotes( $raw_param_value ); + if ( isset( $this->allowed_local_streams[ $raw_stripped ] ) + || isset( $this->allowed_local_stream_constants[ $raw_param_value ] ) + ) { + return true; + } + + foreach ( $this->allowed_local_stream_partials as $partial ) { + if ( strpos( $raw_stripped, $partial ) === 0 ) { + return true; + } + } + + return false; + } } diff --git a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc index 0f6974dcb6..7b18dc5e11 100644 --- a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc +++ b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc @@ -51,3 +51,18 @@ file_get_contents( MUPLUGINDIR . 'some-file.xml' ); // OK. file_get_contents( plugin_dir_path( __FILE__ ) . 'subfolder/*.conf' ); // OK. file_get_contents(WP_Upload_Dir()['path'] . 'subdir/file.inc'); // OK. file_get_contents( 'php://input' ); // OK. + +// Loosely related to issue 295. +file_get_contents( 'php://stdin' ); // OK. +$input_stream = fopen( 'php://stdin', 'w' ); // OK. +$csv_ar = fopen(STDIN); // OK. + +$output_stream = fopen( 'php://output', 'w' ); // OK. +$output_stream = fopen( 'php://stdout', 'w' ); // OK. +$output_stream = fopen( 'php://stderr', 'w' ); // OK. +$output_stream = fopen( STDOUT, 'w' ); // OK. +$output_stream = fopen( STDERR, 'w' ); // OK. +$output_stream = fopen( 'php://fd/3', 'w' ); // OK. +$fp = fopen("php://temp/maxmemory:$fiveMBs", 'r+'); // OK. +readfile( 'php://filter/resource=http://www.example.com' ); // Warning. +file_put_contents("php://filter/write=string.rot13/resource=example.txt","Hello World"); // Warning. diff --git a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php index 36ea1bcb51..55107f0f6a 100644 --- a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php +++ b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php @@ -40,13 +40,9 @@ public function getWarningList() { 5 => 1, 6 => 1, 7 => 1, - 10 => 1, - 12 => 1, - 14 => 1, - 16 => 1, 17 => 1, 18 => 1, @@ -60,13 +56,13 @@ public function getWarningList() { 26 => 1, 27 => 1, 28 => 1, - 40 => 1, - 44 => 1, 46 => 1, 47 => 1, 49 => 1, + 67 => 1, + 68 => 1, ); } From b1f321005613925c2eacc4cef537ce742b1d8a25 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 7 Mar 2019 05:23:18 +0100 Subject: [PATCH 109/241] Docs: exclude the `InlineComment.SpacingAfter` errorcode Fixes 1534 --- WordPress-Docs/ruleset.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WordPress-Docs/ruleset.xml b/WordPress-Docs/ruleset.xml index fb74597d76..f029649646 100644 --- a/WordPress-Docs/ruleset.xml +++ b/WordPress-Docs/ruleset.xml @@ -71,6 +71,8 @@ + + From d30d22fc12493dd5b5a8e1add8a8d1a54b202ee5 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 7 Mar 2019 05:26:59 +0100 Subject: [PATCH 110/241] Docs: make the inclusion of the Generic sniff slightly more specific The `Generic.Commenting` category has three sniffs: * `DocComment` * `Todo` * `Fixme` As WP allows to do's and has no opinion on `FIXME` comments, we may as well just include the one sniff we actually need. --- WordPress-Docs/ruleset.xml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/WordPress-Docs/ruleset.xml b/WordPress-Docs/ruleset.xml index fb74597d76..b11dcb06bc 100644 --- a/WordPress-Docs/ruleset.xml +++ b/WordPress-Docs/ruleset.xml @@ -86,7 +86,7 @@ - + @@ -103,8 +103,5 @@ - - - From a6dbd886d10caedc25ee06f8c68f12a1564393f7 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 7 Mar 2019 07:24:19 +0100 Subject: [PATCH 111/241] WP/AlternativeFunctions: allow calling `curl_version()` `curl_version()` doesn't create or need a cURL resource, so is perfectly fine to use. Ref: http://php.net/manual/en/function.curl-version.php --- WordPress/Sniffs/WP/AlternativeFunctionsSniff.php | 4 ++++ WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc | 2 ++ 2 files changed, 6 insertions(+) diff --git a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php index 556f3f90e6..52e1356f21 100644 --- a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php +++ b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php @@ -273,6 +273,10 @@ public function process_matched_token( $stackPtr, $group_name, $matched_content unset( $first_param ); break; + + case 'curl_version': + // Curl version doesn't actually create a connection. + return; } if ( ! isset( $this->groups[ $group_name ]['since'] ) ) { diff --git a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc index 7b18dc5e11..a9646d98e9 100644 --- a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc +++ b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc @@ -66,3 +66,5 @@ $output_stream = fopen( 'php://fd/3', 'w' ); // OK. $fp = fopen("php://temp/maxmemory:$fiveMBs", 'r+'); // OK. readfile( 'php://filter/resource=http://www.example.com' ); // Warning. file_put_contents("php://filter/write=string.rot13/resource=example.txt","Hello World"); // Warning. + +curl_version(); // OK. From d43381a2a57f2e30b68355daf99f3ac590d9deb6 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 28 Mar 2019 04:41:50 +0100 Subject: [PATCH 112/241] Sniff::is_sanitized(): make the method more code style independent Whether people comply with the WP style rules regarding whitespace and such, is irrelevant for determining whether or not a value is sanitized/unslashed. This fixed a false positive where superglobals which were correctly unslashed/sanitized were not being recognized as such. Includes unit test in the `ValidatedSanitizedInput` sniff. --- WordPress/Sniff.php | 27 ++++++++++--------- .../ValidatedSanitizedInputUnitTest.inc | 2 ++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 7d5de2c044..caf12632b2 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1572,46 +1572,47 @@ protected function is_sanitized( $stackPtr, $require_unslash = false ) { if ( $require_unslash ) { $this->add_unslash_error( $stackPtr ); } + return false; } // Get the function that it's in. $nested_parenthesis = $this->tokens[ $stackPtr ]['nested_parenthesis']; - $function_closer = end( $nested_parenthesis ); - $function_opener = key( $nested_parenthesis ); - $function = $this->tokens[ ( $function_opener - 1 ) ]; + $nested_openers = array_keys( $nested_parenthesis ); + $function_opener = array_pop( $nested_openers ); + $functionPtr = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $function_opener - 1 ), null, true, null, true ); // If it is just being unset, the value isn't used at all, so it's safe. - if ( \T_UNSET === $function['code'] ) { + if ( \T_UNSET === $this->tokens[ $functionPtr ]['code'] ) { return true; } - // If this isn't a call to a function, it sure isn't sanitizing function. - if ( \T_STRING !== $function['code'] ) { + // If this isn't a call to a function, it sure isn't a sanitizing function. + if ( \T_STRING !== $this->tokens[ $functionPtr ]['code'] ) { if ( $require_unslash ) { $this->add_unslash_error( $stackPtr ); } + return false; } - $functionName = $function['content']; + $functionName = $this->tokens[ $functionPtr ]['content']; // Check if wp_unslash() is being used. if ( 'wp_unslash' === $functionName ) { $is_unslashed = true; - $function_closer = prev( $nested_parenthesis ); + $function_opener = array_pop( $nested_openers ); // If there is no other function being used, this value is unsanitized. - if ( ! $function_closer ) { + if ( ! isset( $function_opener ) ) { return false; } - $function_opener = key( $nested_parenthesis ); - $functionName = $this->tokens[ ( $function_opener - 1 ) ]['content']; + $functionPtr = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $function_opener - 1 ), null, true, null, true ); + $functionName = $this->tokens[ $functionPtr ]['content']; } else { - $is_unslashed = false; } @@ -1619,7 +1620,7 @@ protected function is_sanitized( $stackPtr, $require_unslash = false ) { if ( 'array_map' === $functionName ) { // Get the first parameter. - $callback = $this->get_function_call_parameter( ( $function_opener - 1 ), 1 ); + $callback = $this->get_function_call_parameter( $functionPtr, 1 ); if ( ! empty( $callback ) ) { /* diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc index da3be11da1..d9671b4dfb 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc @@ -209,3 +209,5 @@ if ( $obj->array_key_exists( 'my_field4', $_POST ) ) { if ( ClassName::array_key_exists( 'my_field5', $_POST ) ) { $id = (int) $_POST['my_field5']; // Bad. } + +echo sanitize_text_field (wp_unslash ($_GET['test'])); // OK. From 2600112fd16d2b2d4a609c94613bb5c50e1921aa Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 28 Mar 2019 06:32:24 +0100 Subject: [PATCH 113/241] GlobalVariablesOverride: implement the Sniff::is_foreach_as() method Removing some code duplication. --- .../Sniffs/WP/GlobalVariablesOverrideSniff.php | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php index 4485c027ad..6a23ab6370 100644 --- a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php +++ b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php @@ -321,17 +321,8 @@ protected function process_global_statement( $stackPtr, $in_function_scope ) { } // Check if this is a variable assignment within a `foreach()` declaration. - if ( isset( $this->tokens[ $ptr ]['nested_parenthesis'] ) ) { - $nested_parenthesis = $this->tokens[ $ptr ]['nested_parenthesis']; - $close_parenthesis = end( $nested_parenthesis ); - if ( isset( $this->tokens[ $close_parenthesis ]['parenthesis_owner'] ) - && \T_FOREACH === $this->tokens[ $this->tokens[ $close_parenthesis ]['parenthesis_owner'] ]['code'] - && ( false !== $previous - && ( \T_DOUBLE_ARROW === $this->tokens[ $previous ]['code'] - || \T_AS === $this->tokens[ $previous ]['code'] ) ) - ) { - $this->maybe_add_error( $ptr ); - } + if ( $this->is_foreach_as( $ptr ) === true ) { + $this->maybe_add_error( $ptr ); } } } From 0a18e6bd5d6d4e37edf6184cd54a29c8fba3f757 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 28 Mar 2019 08:05:34 +0100 Subject: [PATCH 114/241] Clean up: use array_change_key_case() You learn something new every day. Never came across this function before, but simplifies a few code snippets. Ref: https://php.net/manual/en/function.array-change-key-case.php --- WordPress/Sniffs/WP/DeprecatedClassesSniff.php | 6 ++---- WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/WordPress/Sniffs/WP/DeprecatedClassesSniff.php b/WordPress/Sniffs/WP/DeprecatedClassesSniff.php index 69894fb644..cd69ba988b 100644 --- a/WordPress/Sniffs/WP/DeprecatedClassesSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedClassesSniff.php @@ -58,13 +58,11 @@ class DeprecatedClassesSniff extends AbstractClassRestrictionsSniff { */ public function getGroups() { // Make sure all array keys are lowercase. - $keys = array_keys( $this->deprecated_classes ); - $keys = array_map( 'strtolower', $keys ); - $this->deprecated_classes = array_combine( $keys, $this->deprecated_classes ); + $this->deprecated_classes = array_change_key_case( $this->deprecated_classes, CASE_LOWER ); return array( 'deprecated_classes' => array( - 'classes' => $keys, + 'classes' => array_keys( $this->deprecated_classes ), ), ); } diff --git a/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php b/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php index 7270899004..5c2be16c07 100644 --- a/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php @@ -1339,13 +1339,11 @@ class DeprecatedFunctionsSniff extends AbstractFunctionRestrictionsSniff { */ public function getGroups() { // Make sure all array keys are lowercase. - $keys = array_keys( $this->deprecated_functions ); - $keys = array_map( 'strtolower', $keys ); - $this->deprecated_functions = array_combine( $keys, $this->deprecated_functions ); + $this->deprecated_functions = array_change_key_case( $this->deprecated_functions, CASE_LOWER ); return array( 'deprecated_functions' => array( - 'functions' => $keys, + 'functions' => array_keys( $this->deprecated_functions ), ), ); } From d392c45ddf3c07e76a5336edcae5a70d9745f0c7 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 28 Mar 2019 05:38:25 +0100 Subject: [PATCH 115/241] Sniff: add two new utility methods `is_class_object_call()` and `is_token_namespaced()` These should help make the checking of whether or not a function call is a global function, method call or a namespaced function call more consistent. These functions will be unit tested by the implementations in various other places and the fact that the existing unit tests still pass after that. --- WordPress/Sniff.php | 65 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index caf12632b2..05c71d84f5 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1489,6 +1489,71 @@ protected function is_in_isset_or_empty( $stackPtr ) { return false; } + /** + * Check if a particular token is a (static or non-static) call to a class method or property. + * + * @internal Note: this may still mistake a namespaced function imported via a `use` statement for + * a global function! + * + * @since 2.1.0 + * + * @param int $stackPtr The index of the token in the stack. + * + * @return bool + */ + protected function is_class_object_call( $stackPtr ) { + $before = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true, null, true ); + + if ( false === $before ) { + return false; + } + + if ( \T_OBJECT_OPERATOR !== $this->tokens[ $before ]['code'] + && \T_DOUBLE_COLON !== $this->tokens[ $before ]['code'] + ) { + return false; + } + + return true; + } + + /** + * Check if a particular token is prefixed with a namespace. + * + * @internal This will give a false positive if the file is not namespaced and the token is prefixed + * with `namespace\`. + * + * @since 2.1.0 + * + * @param int $stackPtr The index of the token in the stack. + * + * @return bool + */ + protected function is_token_namespaced( $stackPtr ) { + $prev = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true, null, true ); + + if ( false === $prev ) { + return false; + } + + if ( \T_NS_SEPARATOR !== $this->tokens[ $prev ]['code'] ) { + return false; + } + + $before_prev = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $prev - 1 ), null, true, null, true ); + if ( false === $before_prev ) { + return false; + } + + if ( \T_STRING !== $this->tokens[ $before_prev ]['code'] + && \T_NAMESPACE !== $this->tokens[ $before_prev ]['code'] + ) { + return false; + } + + return true; + } + /** * Check if something is only being sanitized. * From 7c1b6f82de4a7ac93407313a854c1fcfa9059f72 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 28 Mar 2019 05:39:05 +0100 Subject: [PATCH 116/241] Sniff::is_in_isset_or_empty(): implement is_class_object_call() and is_token_namespaced() --- WordPress/Sniff.php | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 05c71d84f5..f53d525b66 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1461,23 +1461,12 @@ protected function is_in_isset_or_empty( $stackPtr ) { } if ( \T_STRING === $previous_code && 'array_key_exists' === $this->tokens[ $previous_non_empty ]['content'] ) { - $before_function = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $previous_non_empty - 1 ), null, true, null, true ); - - if ( false !== $before_function ) { - if ( \T_OBJECT_OPERATOR === $this->tokens[ $before_function ]['code'] - || \T_DOUBLE_COLON === $this->tokens[ $before_function ]['code'] - ) { - // Method call. - return false; - } + if ( $this->is_class_object_call( $previous_non_empty ) === true ) { + return false; + } - if ( \T_NS_SEPARATOR === $this->tokens[ $before_function ]['code'] ) { - $before_before = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $before_function - 1 ), null, true, null, true ); - if ( false !== $before_before && \T_STRING === $this->tokens[ $before_before ]['code'] ) { - // Namespaced function call. - return false; - } - } + if ( $this->is_token_namespaced( $previous_non_empty ) === true ) { + return false; } $second_param = $this->get_function_call_parameter( $previous_non_empty, 2 ); From e5c6ecb9e762f0ab16b9d24b16206e590d189f92 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 28 Mar 2019 05:47:05 +0100 Subject: [PATCH 117/241] Sniff::is_validated(): implement is_class_object_call() and is_token_namespaced() --- WordPress/Sniff.php | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index f53d525b66..02b25928ee 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1907,22 +1907,14 @@ protected function is_validated( $stackPtr, $array_key = null, $in_condition_onl continue 2; } - $previous_non_empty = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $i - 1 ), null, true, null, true ); - if ( false !== $previous_non_empty ) { - if ( \T_OBJECT_OPERATOR === $this->tokens[ $previous_non_empty ]['code'] - || \T_DOUBLE_COLON === $this->tokens[ $previous_non_empty ]['code'] - ) { - // Method call. - continue 2; - } + if ( $this->is_class_object_call( $i ) === true ) { + // Method call. + continue 2; + } - if ( \T_NS_SEPARATOR === $this->tokens[ $previous_non_empty ]['code'] ) { - $pprev = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $previous_non_empty - 1 ), null, true, null, true ); - if ( false !== $pprev && \T_STRING === $this->tokens[ $pprev ]['code'] ) { - // Namespaced function call. - continue 2; - } - } + if ( $this->is_token_namespaced( $i ) === true ) { + // Namespaced function call. + continue 2; } $params = $this->get_function_call_parameters( $i ); From a55e3e08ac8dd1eb5ee07591c415caa8960cd898 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 28 Mar 2019 06:13:21 +0100 Subject: [PATCH 118/241] Sniff::is_use_of_global_constant(): implement is_token_namespaced() --- WordPress/Sniff.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 02b25928ee..7359f145df 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -2726,10 +2726,7 @@ public function is_use_of_global_constant( $stackPtr ) { return false; } - if ( false !== $prev - && \T_NS_SEPARATOR === $this->tokens[ $prev ]['code'] - && \T_STRING === $this->tokens[ ( $prev - 1 ) ]['code'] - ) { + if ( $this->is_token_namespaced( $stackPtr ) === true ) { // Namespaced constant of the same name. return false; } From c98ecc258b8ada9889d59436c17117c4fc59dcae Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 28 Mar 2019 05:55:50 +0100 Subject: [PATCH 119/241] AbstractFunctionRestrictions: implement Sniff::is_class_object_call() and Sniff::is_token_namespaced() --- .../AbstractFunctionRestrictionsSniff.php | 20 +++++++++---------- .../PHP/DevelopmentFunctionsUnitTest.inc | 5 +++++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/WordPress/AbstractFunctionRestrictionsSniff.php b/WordPress/AbstractFunctionRestrictionsSniff.php index 5b11af4dad..4553e3f472 100644 --- a/WordPress/AbstractFunctionRestrictionsSniff.php +++ b/WordPress/AbstractFunctionRestrictionsSniff.php @@ -213,7 +213,15 @@ public function process_token( $stackPtr ) { public function is_targetted_token( $stackPtr ) { // Exclude function definitions, class methods, and namespaced calls. - if ( \T_STRING === $this->tokens[ $stackPtr ]['code'] && isset( $this->tokens[ ( $stackPtr - 1 ) ] ) ) { + if ( \T_STRING === $this->tokens[ $stackPtr ]['code'] ) { + if ( $this->is_class_object_call( $stackPtr ) === true ) { + return false; + } + + if ( $this->is_token_namespaced( $stackPtr ) === true ) { + return false; + } + $prev = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true ); if ( false !== $prev ) { @@ -222,21 +230,11 @@ public function is_targetted_token( $stackPtr ) { \T_FUNCTION => \T_FUNCTION, \T_CLASS => \T_CLASS, \T_AS => \T_AS, // Use declaration alias. - \T_DOUBLE_COLON => \T_DOUBLE_COLON, - \T_OBJECT_OPERATOR => \T_OBJECT_OPERATOR, ); if ( isset( $skipped[ $this->tokens[ $prev ]['code'] ] ) ) { return false; } - - // Skip namespaced functions, ie: \foo\bar() not \bar(). - if ( \T_NS_SEPARATOR === $this->tokens[ $prev ]['code'] ) { - $pprev = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $prev - 1 ), null, true ); - if ( false !== $pprev && \T_STRING === $this->tokens[ $pprev ]['code'] ) { - return false; - } - } } return true; diff --git a/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc b/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc index 5039be590e..b07e7a8ce6 100644 --- a/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc +++ b/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc @@ -32,3 +32,8 @@ phpinfo(); // Ok - within excluded group. // phpcs:set WordPress.PHP.DevelopmentFunctions exclude[] trigger_error(); // Error. phpinfo(); // Error. + +Wrapper_Class::var_dump(); // OK, not the native PHP function. +$wrapper ->var_dump(); // OK, not the native PHP function. +namespace\var_dump(); // OK as long as the file is namespaced. +MyNamespace\var_dump(); // OK, namespaced function. From 374691c9c39d457f8b3c239d7c4455020d86b9ef Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 28 Mar 2019 05:59:11 +0100 Subject: [PATCH 120/241] GlobalVariablesOverride: implement Sniff::is_class_object_call() --- WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php index 6a23ab6370..57b64d07a5 100644 --- a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php +++ b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php @@ -310,8 +310,7 @@ protected function process_global_statement( $stackPtr, $in_function_scope ) { } // Don't throw false positives for static class properties. - $previous = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $ptr - 1 ), null, true, null, true ); - if ( false !== $previous && \T_DOUBLE_COLON === $this->tokens[ $previous ]['code'] ) { + if ( $this->is_class_object_call( $ptr ) === true ) { continue; } From 08f4a7ff6abfcc91f90c42d76b4e5630b71b1abf Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 28 Mar 2019 06:09:07 +0100 Subject: [PATCH 121/241] DiscouragedConstants: implement Sniff::is_token_namespaced() --- WordPress/Sniffs/WP/DiscouragedConstantsSniff.php | 5 +---- WordPress/Tests/WP/DiscouragedConstantsUnitTest.inc | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php b/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php index 00e1e8efa8..6539b49cc5 100644 --- a/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php +++ b/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php @@ -124,10 +124,7 @@ public function process_arbitrary_tstring( $stackPtr ) { return; } - if ( false !== $prev - && \T_NS_SEPARATOR === $this->tokens[ $prev ]['code'] - && \T_STRING === $this->tokens[ ( $prev - 1 ) ]['code'] - ) { + if ( $this->is_token_namespaced( $stackPtr ) === true ) { // Namespaced constant of the same name. return; } diff --git a/WordPress/Tests/WP/DiscouragedConstantsUnitTest.inc b/WordPress/Tests/WP/DiscouragedConstantsUnitTest.inc index d5e5f3a689..4949a9557a 100644 --- a/WordPress/Tests/WP/DiscouragedConstantsUnitTest.inc +++ b/WordPress/Tests/WP/DiscouragedConstantsUnitTest.inc @@ -42,7 +42,7 @@ define( 'My\STYLESHEETPATH', 'something' ); if ( defined( 'STYLESHEETPATH' ) ) { // Ok. // Do something unrelated. } - +echo namespace\STYLESHEETPATH; // "Magic" namespace operator. /* * These are all bad. From 7d01ff3f06c4b6b92d8e0ced29d9c4b5955df270 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 28 Mar 2019 02:34:30 +0100 Subject: [PATCH 122/241] New utility method `Sniff::is_in_function_call()` Allows for checking whether a token is (part of) a parameter passed to a specific (set of) function(s). Optionally checks whether the function call is to a global function. Optionally only checks the "deepest" function call. Returns the stack pointer to the `T_STRING` token for the function call or `false`. --- WordPress/Sniff.php | 69 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 7359f145df..c1ea6f2577 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1543,6 +1543,75 @@ protected function is_token_namespaced( $stackPtr ) { return true; } + /** + * Check if a token is (part of) a parameter for a function call to a select list of functions. + * + * @since 2.1.0 + * + * @param int $stackPtr The index of the token in the stack. + * @param array $valid_functions List of valid function names. + * Note: The keys to this array should be the function names + * in lowercase. Values are irrelevant. + * @param bool $global Optional. Whether to make sure that the function call is + * to a global function. If `false`, methods and namespaced + * function calls will also be allowed. + * Defaults to `true`. + * @param bool $allow_nested Optional. Whether to allow for nested function calls within the + * call to this function. + * I.e. when checking whether a token is within a function call + * to `strtolower()`, whether to accept `strtolower( trim( $var ) )` + * or only `strtolower( $var )`. + * Defaults to `false`. + * + * @return int|bool Stack pointer to the function call T_STRING token or false otherwise. + */ + protected function is_in_function_call( $stackPtr, $valid_functions, $global = true, $allow_nested = false ) { + if ( ! isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) { + return false; + } + + $nested_parenthesis = $this->tokens[ $stackPtr ]['nested_parenthesis']; + if ( false === $allow_nested ) { + $nested_parenthesis = array_reverse( $nested_parenthesis, true ); + } + + foreach ( $nested_parenthesis as $open => $close ) { + + $prev_non_empty = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $open - 1 ), null, true, null, true ); + if ( false === $prev_non_empty || \T_STRING !== $this->tokens[ $prev_non_empty ]['code'] ) { + continue; + } + + if ( isset( $valid_functions[ strtolower( $this->tokens[ $prev_non_empty ]['content'] ) ] ) === false ) { + if ( false === $allow_nested ) { + // Function call encountered, but not to one of the allowed functions. + return false; + } + + continue; + } + + if ( false === $global ) { + return $prev_non_empty; + } + + /* + * Now, make sure it is a global function. + */ + if ( $this->is_class_object_call( $prev_non_empty ) === true ) { + continue; + } + + if ( $this->is_token_namespaced( $prev_non_empty ) === true ) { + continue; + } + + return $prev_non_empty; + } + + return false; + } + /** * Check if something is only being sanitized. * From 95e3a3d634b6c00e391d68813b70f48df9b08541 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 28 Mar 2019 10:14:20 +0100 Subject: [PATCH 123/241] Sniff::is_in_isset_or_empty(): implement new `is_in_function_call()` method This fixes potential false negatives when a method/namespaced function mirroring the name of the PHP array_key_exists() function would be used. --- WordPress/Sniff.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index c1ea6f2577..9eb605d789 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1460,16 +1460,9 @@ protected function is_in_isset_or_empty( $stackPtr ) { return true; } - if ( \T_STRING === $previous_code && 'array_key_exists' === $this->tokens[ $previous_non_empty ]['content'] ) { - if ( $this->is_class_object_call( $previous_non_empty ) === true ) { - return false; - } - - if ( $this->is_token_namespaced( $previous_non_empty ) === true ) { - return false; - } - - $second_param = $this->get_function_call_parameter( $previous_non_empty, 2 ); + $functionPtr = $this->is_in_function_call( $stackPtr, array( 'array_key_exists' => true ) ); + if ( false !== $functionPtr ) { + $second_param = $this->get_function_call_parameter( $functionPtr, 2 ); if ( $stackPtr >= $second_param['start'] && $stackPtr <= $second_param['end'] ) { return true; } From 6e470dec3441c038fda3cbf007fbc18732069f56 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 28 Mar 2019 04:46:40 +0100 Subject: [PATCH 124/241] Sniff::is_sanitized(): implement new `is_in_function_call()` method This fixes potential false negatives when a method/namespaced function mirroring the name of the WP unslashing/sanitization functions would be used. Includes unit test. --- WordPress/Sniff.php | 25 +++++++++++++------ .../ValidatedSanitizedInputUnitTest.inc | 5 ++++ .../ValidatedSanitizedInputUnitTest.php | 2 ++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 9eb605d789..5fa62c1310 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1703,9 +1703,16 @@ protected function is_sanitized( $stackPtr, $require_unslash = false ) { return true; } - // If this isn't a call to a function, it sure isn't a sanitizing function. - if ( \T_STRING !== $this->tokens[ $functionPtr ]['code'] ) { - if ( $require_unslash ) { + $valid_functions = $this->sanitizingFunctions; + $valid_functions += $this->unslashingSanitizingFunctions; + $valid_functions['wp_unslash'] = true; + $valid_functions['array_map'] = true; + + $functionPtr = $this->is_in_function_call( $stackPtr, $valid_functions ); + + // If this isn't a call to one of the valid functions, it sure isn't a sanitizing function. + if ( false === $functionPtr ) { + if ( true === $require_unslash ) { $this->add_unslash_error( $stackPtr ); } @@ -1717,15 +1724,17 @@ protected function is_sanitized( $stackPtr, $require_unslash = false ) { // Check if wp_unslash() is being used. if ( 'wp_unslash' === $functionName ) { - $is_unslashed = true; - $function_opener = array_pop( $nested_openers ); + $is_unslashed = true; + + unset( $valid_functions['wp_unslash'] ); + $higherFunctionPtr = $this->is_in_function_call( $functionPtr, $valid_functions ); - // If there is no other function being used, this value is unsanitized. - if ( ! isset( $function_opener ) ) { + // If there is no other valid function being used, this value is unsanitized. + if ( false === $higherFunctionPtr ) { return false; } - $functionPtr = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $function_opener - 1 ), null, true, null, true ); + $functionPtr = $higherFunctionPtr; $functionName = $this->tokens[ $functionPtr ]['content']; } else { diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc index d9671b4dfb..57db08843f 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc @@ -211,3 +211,8 @@ if ( ClassName::array_key_exists( 'my_field5', $_POST ) ) { } echo sanitize_text_field (wp_unslash ($_GET['test'])); // OK. + +if ( isset( $_GET['unslash_check'] ) ) { + $clean = sanitize_text_field( WP_Faker::wp_unslash( $_GET['unslash_check'] ) ); // Bad x1 - unslash. + $clean = WP_Faker\sanitize_text_field( wp_unslash( $_GET['unslash_check'] ) ); // Bad x1 - sanitize. +} diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php index 46ab050e97..430b278b81 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php @@ -58,6 +58,8 @@ public function getErrorList() { 202 => 1, 206 => 1, 210 => 1, + 216 => 1, + 217 => 1, ); } From 91b053fd9a50577a272f34ac94601f5278b1bee3 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 28 Mar 2019 03:28:23 +0100 Subject: [PATCH 125/241] CronInterval: implement new `Sniff::is_in_function_call()` method This fixes some potential false positives. Includes unit tests. --- WordPress/Sniffs/WP/CronIntervalSniff.php | 18 ++++++++++++++++-- WordPress/Tests/WP/CronIntervalUnitTest.inc | 7 ++++++- WordPress/Tests/WP/CronIntervalUnitTest.php | 1 - 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/WordPress/Sniffs/WP/CronIntervalSniff.php b/WordPress/Sniffs/WP/CronIntervalSniff.php index d7c81c2bb4..d7e91b8321 100644 --- a/WordPress/Sniffs/WP/CronIntervalSniff.php +++ b/WordPress/Sniffs/WP/CronIntervalSniff.php @@ -55,6 +55,15 @@ class CronIntervalSniff extends Sniff { 'YEAR_IN_SECONDS' => 31536000, ); + /** + * Function within which the hook should be found. + * + * @var array + */ + protected $valid_functions = array( + 'add_filter' => true, + ); + /** * Returns an array of tokens this test wants to listen for. * @@ -82,8 +91,8 @@ public function process_token( $stackPtr ) { } // If within add_filter. - $functionPtr = $this->phpcsFile->findPrevious( \T_STRING, key( $token['nested_parenthesis'] ) ); - if ( false === $functionPtr || 'add_filter' !== $this->tokens[ $functionPtr ]['content'] ) { + $functionPtr = $this->is_in_function_call( $stackPtr, $this->valid_functions ); + if ( false === $functionPtr ) { return; } @@ -92,6 +101,11 @@ public function process_token( $stackPtr ) { return; } + if ( $stackPtr >= $callback['start'] ) { + // "cron_schedules" found in the second parameter, not the first. + return; + } + // Detect callback function name. $callbackArrayPtr = $this->phpcsFile->findNext( Tokens::$emptyTokens, $callback['start'], ( $callback['end'] + 1 ), true ); diff --git a/WordPress/Tests/WP/CronIntervalUnitTest.inc b/WordPress/Tests/WP/CronIntervalUnitTest.inc index 712eb64072..19b061fe34 100644 --- a/WordPress/Tests/WP/CronIntervalUnitTest.inc +++ b/WordPress/Tests/WP/CronIntervalUnitTest.inc @@ -52,7 +52,7 @@ add_filter( 'cron_schedules' ); // Ignore, no callback parameter. add_filter( 'cron_schedules', [ 'Foo', 'my_add_quicklier' ] ); // Error: 5 min. -// Ignore, not our function. Currently gives false positive, will be fixed later when function call detection utility functions are added. +// Ignore, not our function. My_Custom::add_filter( 'cron_schedules', [ 'Foo', 'my_add_quicklier' ] ); // Deal correctly with the WP time constants. @@ -139,3 +139,8 @@ add_filter( 'cron_schedules', function ( $schedules ) { ); return $schedules; } ); // Error: 9 min. + +Custom::add_filter( 'cron_schedules', array( $class, $method ) ); // OK, not the WP function. +add_filter( 'some_hook', array( $place, 'cron_schedules' ) ); // OK, not the hook we're looking for. +add_filter( function() { return get_hook_name('cron_schedules'); }(), array( $class, $method ) ); // OK, nested in another function call. + diff --git a/WordPress/Tests/WP/CronIntervalUnitTest.php b/WordPress/Tests/WP/CronIntervalUnitTest.php index be5cc9f6b8..704923cc5f 100644 --- a/WordPress/Tests/WP/CronIntervalUnitTest.php +++ b/WordPress/Tests/WP/CronIntervalUnitTest.php @@ -45,7 +45,6 @@ public function getWarningList() { 41 => 1, 43 => 1, 53 => 1, - 56 => 1, // False positive. 67 => 1, 76 => 1, 85 => 1, From 4e05eaa766f8077ec26373d352b633908ae03c5a Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 30 Mar 2019 01:04:08 +0100 Subject: [PATCH 126/241] ValidatedSanitizedInput: minor code readability improvement --- .../Security/ValidatedSanitizedInputSniff.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php b/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php index 5681de7cea..2f5ca051b1 100644 --- a/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php +++ b/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php @@ -133,8 +133,12 @@ function ( $symbol ) { // Check for validation first. if ( ! $this->is_validated( $stackPtr, $array_key, $this->check_validation_in_scope_only ) ) { - $this->phpcsFile->addError( 'Detected usage of a non-validated input variable: %s', $stackPtr, 'InputNotValidated', $error_data ); - // return; // Should we just return and not look for sanitizing functions ? + $this->phpcsFile->addError( + 'Detected usage of a non-validated input variable: %s', + $stackPtr, + 'InputNotValidated', + $error_data + ); } if ( $this->has_whitelist_comment( 'sanitization', $stackPtr ) ) { @@ -150,7 +154,12 @@ function ( $symbol ) { // Now look for sanitizing functions. if ( ! $this->is_sanitized( $stackPtr, true ) ) { - $this->phpcsFile->addError( 'Detected usage of a non-sanitized input variable: %s', $stackPtr, 'InputNotSanitized', $error_data ); + $this->phpcsFile->addError( + 'Detected usage of a non-sanitized input variable: %s', + $stackPtr, + 'InputNotSanitized', + $error_data + ); } } From 5cb689fcee6dc2fb50ea63746682217e87e6e755 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 30 Mar 2019 05:02:51 +0100 Subject: [PATCH 127/241] Sniff::is_comparison(): minor defensive coding tweak There may not be a next token during live coding. This prevents the method from evaluating `false` to `0` and looking at the first token in the file. --- WordPress/Sniff.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 7359f145df..7939004c4f 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1984,7 +1984,7 @@ protected function is_comparison( $stackPtr ) { ); // This might be an opening square bracket in the case of arrays ($var['a']). - while ( \T_OPEN_SQUARE_BRACKET === $this->tokens[ $next_token ]['code'] ) { + while ( false !== $next_token && \T_OPEN_SQUARE_BRACKET === $this->tokens[ $next_token ]['code'] ) { $next_token = $this->phpcsFile->findNext( Tokens::$emptyTokens, @@ -1994,7 +1994,7 @@ protected function is_comparison( $stackPtr ) { ); } - if ( isset( Tokens::$comparisonTokens[ $this->tokens[ $next_token ]['code'] ] ) ) { + if ( false !== $next_token && isset( Tokens::$comparisonTokens[ $this->tokens[ $next_token ]['code'] ] ) ) { return true; } From 1b3cdfc714c00ba9b35df2993da209cd085c7113 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 30 Mar 2019 13:48:55 +0100 Subject: [PATCH 128/241] Sniff::is_assignment(): minor defensive coding tweak There "bracket_closer" index may not be set during live coding/in case of parse errors. This prevents the method from throwing "_Undefined index: bracket_closer_" notices in that case. --- WordPress/Sniff.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 7359f145df..2a4805fdee 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1321,7 +1321,9 @@ protected function is_assignment( $stackPtr ) { } // Check if this is an array assignment, e.g., `$var['key'] = 'val';` . - if ( \T_OPEN_SQUARE_BRACKET === $this->tokens[ $next_non_empty ]['code'] ) { + if ( \T_OPEN_SQUARE_BRACKET === $this->tokens[ $next_non_empty ]['code'] + && isset( $this->tokens[ $next_non_empty ]['bracket_closer'] ) + ) { return $this->is_assignment( $this->tokens[ $next_non_empty ]['bracket_closer'] ); } From 4e143ec158294a9c44b6d29801c0a3d898ac56aa Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 31 Mar 2019 11:57:00 +0200 Subject: [PATCH 129/241] Sniff::is_in_function_call(): expand the function documentation with some examples --- WordPress/Sniff.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 5fa62c1310..171a55fcca 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1539,6 +1539,14 @@ protected function is_token_namespaced( $stackPtr ) { /** * Check if a token is (part of) a parameter for a function call to a select list of functions. * + * This is useful, for instance, when trying to determine the context a variable is used in. + * + * For example: this function could be used to determine if the variable `$foo` is used + * in a global function call to the function `is_foo()`. + * In that case, a call to this function would return the stackPtr to the T_STRING `is_foo` + * for code like: `is_foo( $foo, 'some_other_param' )`, while it would return `false` for + * the following code `is_bar( $foo, 'some_other_param' )`. + * * @since 2.1.0 * * @param int $stackPtr The index of the token in the stack. @@ -1546,8 +1554,10 @@ protected function is_token_namespaced( $stackPtr ) { * Note: The keys to this array should be the function names * in lowercase. Values are irrelevant. * @param bool $global Optional. Whether to make sure that the function call is - * to a global function. If `false`, methods and namespaced - * function calls will also be allowed. + * to a global function. If `false`, calls to methods, be it static + * `Class::method()` or via an object `$obj->method()`, and + * namespaced function calls, like `MyNS\function_name()` will + * also be accepted. * Defaults to `true`. * @param bool $allow_nested Optional. Whether to allow for nested function calls within the * call to this function. From c088b1bcfcb7a97ee7cac89ab59a1675c78f9859 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 28 Mar 2019 01:01:05 +0100 Subject: [PATCH 130/241] Sniff::$unslashingSanitizingFunctions: add doubleval() and count() While `doubleval()` is an alias of `floatval()` and shouldn't be used, for the purposes of the ValidatedSanitizedInput sniff, both functions should be recognized. And as `count()` doesn't actually access the data in the variable, but only counts the number of elements, it is also safe to use without unslashing/sanitizing the variable beforehand. Same goes for the `sizeof()` alias of `count()`. Includes unit tests. Fixes 1659 --- WordPress/Sniff.php | 3 +++ .../Tests/Security/ValidatedSanitizedInputUnitTest.inc | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index b00c25713c..8583d81f8b 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -309,10 +309,13 @@ abstract class Sniff implements PHPCS_Sniff { protected $unslashingSanitizingFunctions = array( 'absint' => true, 'boolval' => true, + 'count' => true, + 'doubleval' => true, 'floatval' => true, 'intval' => true, 'is_array' => true, 'sanitize_key' => true, + 'sizeof' => true, ); /** diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc index 57db08843f..4b42017e65 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc @@ -216,3 +216,12 @@ if ( isset( $_GET['unslash_check'] ) ) { $clean = sanitize_text_field( WP_Faker::wp_unslash( $_GET['unslash_check'] ) ); // Bad x1 - unslash. $clean = WP_Faker\sanitize_text_field( wp_unslash( $_GET['unslash_check'] ) ); // Bad x1 - sanitize. } + +function test_more_safe_functions() { + if ( ! isset( $_GET['test'] ) ) { + return; + } + + $float = doubleval( $_GET['test'] ); // OK. + $count = count( $_GET['test'] ); // Issue #1659; OK. +} From 34920c722d6b82029ccbaad8d3288aecdf48d6dd Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 31 Mar 2019 13:49:29 +0200 Subject: [PATCH 131/241] Update default minimum_supported_version to WP 4.8 The minimum version should be three versions behind the latest WP release, so what with 5.1 being out, it should now be 4.8. Includes updating the list of deprecated functions. Input for this based on @JDGrimes's WP deprecated code scanner. --- WordPress/Sniff.php | 2 +- .../Sniffs/WP/DeprecatedFunctionsSniff.php | 15 +++++++ .../Tests/WP/DeprecatedFunctionsUnitTest.inc | 12 ++++-- .../Tests/WP/DeprecatedFunctionsUnitTest.php | 39 ++++++++++--------- .../Tests/WP/DeprecatedParametersUnitTest.inc | 4 +- .../Tests/WP/DeprecatedParametersUnitTest.php | 3 +- phpcs.xml.dist.sample | 2 +- 7 files changed, 48 insertions(+), 29 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index b00c25713c..b18fed30d6 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -82,7 +82,7 @@ abstract class Sniff implements PHPCS_Sniff { * * @var string WordPress version. */ - public $minimum_supported_version = '4.7'; + public $minimum_supported_version = '4.8'; /** * Custom list of classes which test classes can extend. diff --git a/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php b/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php index 5c2be16c07..8525dc33bb 100644 --- a/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php @@ -579,6 +579,11 @@ class DeprecatedFunctionsSniff extends AbstractFunctionRestrictionsSniff { 'alt' => 'wp_die()', 'version' => '3.0.0', ), + // Verified version & alternative. + 'install_blog_defaults' => array( + 'alt' => 'wp_install_defaults', + 'version' => '3.0.0', + ), 'is_main_blog' => array( 'alt' => 'is_main_site()', 'version' => '3.0.0', @@ -1330,6 +1335,16 @@ class DeprecatedFunctionsSniff extends AbstractFunctionRestrictionsSniff { 'alt' => '', 'version' => '4.9.0', ), + + // WP 5.1.0. + 'insert_blog' => array( + 'alt' => 'wp_insert_site()', + 'version' => '5.1.0', + ), + 'install_blog' => array( + 'alt' => '', + 'version' => '5.1.0', + ), ); /** diff --git a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc index 55b5107e2f..eb0822692e 100644 --- a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc +++ b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc @@ -143,6 +143,7 @@ get_user_details(); get_usermeta(); get_usernumposts(); graceful_fail(); +install_blog_defaults(); is_main_blog(); is_site_admin(); is_taxonomy(); @@ -319,10 +320,6 @@ use function popuplinks as something_else; // Related to issue #1306. post_form_autocomplete_off(); wp_embed_handler_googlevideo(); wp_get_sites(); - -/* - * Warning. - */ /* ============ WP 4.7 ============ */ _sort_nav_menu_items(); _usort_terms_by_ID(); @@ -330,6 +327,10 @@ _usort_terms_by_name(); get_paged_template(); wp_get_network(); wp_kses_js_entities(); + +/* + * Warning. + */ /* ============ WP 4.8 ============ */ wp_dashboard_plugins_output(); /* ============ WP 4.9 ============ */ @@ -337,3 +338,6 @@ get_shortcut_link(); is_user_option_local(); wp_ajax_press_this_add_category(); wp_ajax_press_this_save_post(); +/* ============ WP 5.1 ============ */ +insert_blog(); +install_blog(); diff --git a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php index 5fbce22ce0..c14a79c9bd 100644 --- a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php @@ -28,7 +28,7 @@ class DeprecatedFunctionsUnitTest extends AbstractSniffUnitTest { */ public function getErrorList() { - $errors = array_fill( 8, 314, 1 ); + $errors = array_fill( 8, 322, 1 ); // Unset the lines related to version comments. unset( @@ -45,22 +45,23 @@ public function getErrorList() { $errors[80], $errors[118], $errors[125], - $errors[161], - $errors[174], - $errors[178], - $errors[210], - $errors[233], - $errors[251], - $errors[255], - $errors[262], - $errors[274], - $errors[281], - $errors[285], - $errors[290], - $errors[295], - $errors[303], - $errors[310], - $errors[318] + $errors[162], + $errors[175], + $errors[179], + $errors[211], + $errors[234], + $errors[252], + $errors[256], + $errors[263], + $errors[275], + $errors[282], + $errors[286], + $errors[291], + $errors[296], + $errors[304], + $errors[311], + $errors[319], + $errors[323] ); return $errors; @@ -73,10 +74,10 @@ public function getErrorList() { */ public function getWarningList() { - $warnings = array_fill( 326, 14, 1 ); + $warnings = array_fill( 335, 9, 1 ); // Unset the lines related to version comments. - unset( $warnings[326], $warnings[333], $warnings[335] ); + unset( $warnings[336], $warnings[341] ); return $warnings; } diff --git a/WordPress/Tests/WP/DeprecatedParametersUnitTest.inc b/WordPress/Tests/WP/DeprecatedParametersUnitTest.inc index 7e35ad422a..8022d59bc5 100644 --- a/WordPress/Tests/WP/DeprecatedParametersUnitTest.inc +++ b/WordPress/Tests/WP/DeprecatedParametersUnitTest.inc @@ -48,6 +48,7 @@ the_author( 'deprecated', 'deprecated' ); the_author_posts_link( 'deprecated' ); trackback_rdf( 'deprecated' ); trackback_url( 'deprecated' ); +unregister_setting( '', '', '', 'deprecated' ); update_blog_option( '', '', '', 'deprecated' ); update_user_status( '', '', '', 'deprecated' ); wp_get_http_headers( '', 'deprecated' ); @@ -60,7 +61,6 @@ wp_title_rss( 'deprecated' ); wp_upload_bits( '', 'deprecated' ); xfn_check( '', '', 'deprecated' ); -// All will give an WARNING as they have been deprecated after WP 4.7. +// All will give an WARNING as they have been deprecated after WP 4.8. get_category_parents( '', '', '', '', array( 'deprecated') ); -unregister_setting( '', '', '', 'deprecated' ); diff --git a/WordPress/Tests/WP/DeprecatedParametersUnitTest.php b/WordPress/Tests/WP/DeprecatedParametersUnitTest.php index ffbc573474..77d4d87e88 100644 --- a/WordPress/Tests/WP/DeprecatedParametersUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedParametersUnitTest.php @@ -27,7 +27,7 @@ class DeprecatedParametersUnitTest extends AbstractSniffUnitTest { * @return array => */ public function getErrorList() { - $errors = array_fill( 28, 34, 1 ); + $errors = array_fill( 28, 35, 1 ); $errors[22] = 1; $errors[23] = 1; @@ -47,7 +47,6 @@ public function getErrorList() { */ public function getWarningList() { return array( - 65 => 1, 66 => 1, ); } diff --git a/phpcs.xml.dist.sample b/phpcs.xml.dist.sample index ef8dae68b1..ffe70c7f1a 100644 --- a/phpcs.xml.dist.sample +++ b/phpcs.xml.dist.sample @@ -70,7 +70,7 @@ the wiki: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties --> - + From 38944372232d285de12cd9da9292b0cd7e3dae1e Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 30 Mar 2019 13:33:35 +0100 Subject: [PATCH 132/241] ValidatedSanitizedInput: allow for validation using key_exists() This builds onto the previous enhancement made in 1635 which started recognizing `array_key_exists()` as a way to validate a variable. `key_exists()` is an alias for `array_key_exists()` and while alias functions shouldn't be used, for the purposes of the ValidatedSanitizedInput sniff, both functions should be recognized. Includes unit test. Notes: * Removes the `array_key_exists()` method from the list of `$sanitizingFunctions` as it doesn't belong there and is now handled differently anyway (this should have been removed in 1635). * Updates the version numbers for the change in the method documentation. We never released version 2.0.1, so both this change as well as the one from 1635 will now be released in 2.1.0. --- WordPress/Sniff.php | 23 ++++++++++++------- .../ValidatedSanitizedInputUnitTest.inc | 5 ++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index da69c52adb..69eaddc60c 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -252,7 +252,6 @@ abstract class Sniff implements PHPCS_Sniff { */ protected $sanitizingFunctions = array( '_wp_handle_upload' => true, - 'array_key_exists' => true, 'esc_url_raw' => true, 'filter_input' => true, 'filter_var' => true, @@ -1437,8 +1436,8 @@ protected function has_nonce_check( $stackPtr ) { * Check if a token is inside of an isset(), empty() or array_key_exists() statement. * * @since 0.5.0 - * @since 2.0.1 Now checks for the token being used as the array parameter - * in function calls to array_key_exists() as well. + * @since 2.1.0 Now checks for the token being used as the array parameter + * in function calls to array_key_exists() and key_exists() as well. * * @param int $stackPtr The index of the token in the stack. * @@ -1465,7 +1464,12 @@ protected function is_in_isset_or_empty( $stackPtr ) { return true; } - $functionPtr = $this->is_in_function_call( $stackPtr, array( 'array_key_exists' => true ) ); + $valid_functions = array( + 'array_key_exists' => true, + 'key_exists' => true, // Alias. + ); + + $functionPtr = $this->is_in_function_call( $stackPtr, $valid_functions ); if ( false !== $functionPtr ) { $second_param = $this->get_function_call_parameter( $functionPtr, 2 ); if ( $stackPtr >= $second_param['start'] && $stackPtr <= $second_param['end'] ) { @@ -1845,7 +1849,8 @@ protected function get_array_access_key( $stackPtr ) { } /** - * Check if the existence of a variable is validated with isset(), empty() or array_key_exists(). + * Check if the existence of a variable is validated with isset(), empty(), array_key_exists() + * or key_exists(). * * When $in_condition_only is false, (which is the default), this is considered * valid: @@ -1868,7 +1873,7 @@ protected function get_array_access_key( $stackPtr ) { * ``` * * @since 0.5.0 - * @since 2.0.1 Now recognizes array_key_exists() as a validation function. + * @since 2.1.0 Now recognizes array_key_exists() and key_exists() as validation functions. * * @param int $stackPtr The index of this token in the stack. * @param string $array_key An array key to check for ("bar" in $foo['bar']). @@ -1982,8 +1987,10 @@ protected function is_validated( $stackPtr, $array_key = null, $in_condition_onl break; case 'function_call': - // Only check calls to array_key_exists(). - if ( 'array_key_exists' !== $this->tokens[ $i ]['content'] ) { + // Only check calls to array_key_exists() and key_exists(). + if ( 'array_key_exists' !== $this->tokens[ $i ]['content'] + && 'key_exists' !== $this->tokens[ $i ]['content'] + ) { continue 2; } diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc index 4b42017e65..a4059d5b09 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc @@ -225,3 +225,8 @@ function test_more_safe_functions() { $float = doubleval( $_GET['test'] ); // OK. $count = count( $_GET['test'] ); // Issue #1659; OK. } + +function test_allow_array_key_exists_alias() { + if ( key_exists( 'my_field1', $_POST ) ) { + $id = (int) $_POST['my_field1']; // OK. +} From 866436418cec28311be4b3dd0542e8ba63832a14 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 29 Mar 2019 06:42:52 +0100 Subject: [PATCH 133/241] Sniff: add new get_array_access_keys() utility method ... to retrieve _all_ array keys for a multi-level array access. The original `Sniff::get_array_access_key()` method defers to the new method under the hood, however, the behaviour of that method has not changed. --- WordPress/Sniff.php | 74 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 16 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 69eaddc60c..837d772f99 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1814,12 +1814,66 @@ public function add_unslash_error( $stackPtr ) { ); } + /** + * Get the index keys of an array variable. + * + * E.g., "bar" and "baz" in $foo['bar']['baz']. + * + * @since 2.1.0 + * + * @param int $stackPtr The index of the variable token in the stack. + * @param bool $all Whether to get all keys or only the first. + * Defaults to `true`(= all). + * + * @return array An array of index keys whose value is being accessed. + * or an empty array if this is not array access. + */ + protected function get_array_access_keys( $stackPtr, $all = true ) { + + $keys = array(); + + if ( \T_VARIABLE !== $this->tokens[ $stackPtr ]['code'] ) { + return $keys; + } + + $current = $stackPtr; + + do { + // Find the next non-empty token. + $open_bracket = $this->phpcsFile->findNext( + Tokens::$emptyTokens, + ( $current + 1 ), + null, + true + ); + + // If it isn't a bracket, this isn't an array-access. + if ( false === $open_bracket + || \T_OPEN_SQUARE_BRACKET !== $this->tokens[ $open_bracket ]['code'] + || ! isset( $this->tokens[ $open_bracket ]['bracket_closer'] ) + ) { + break; + } + + $key = $this->phpcsFile->getTokensAsString( + ( $open_bracket + 1 ), + ( $this->tokens[ $open_bracket ]['bracket_closer'] - $open_bracket - 1 ) + ); + + $keys[] = trim( $key ); + $current = $this->tokens[ $open_bracket ]['bracket_closer']; + } while ( isset( $this->tokens[ $current ] ) && true === $all ); + + return $keys; + } + /** * Get the index key of an array variable. * * E.g., "bar" in $foo['bar']. * * @since 0.5.0 + * @since 2.1.0 Now uses get_array_access_keys() under the hood. * * @param int $stackPtr The index of the token in the stack. * @@ -1827,25 +1881,13 @@ public function add_unslash_error( $stackPtr ) { */ protected function get_array_access_key( $stackPtr ) { - // Find the next non-empty token. - $open_bracket = $this->phpcsFile->findNext( - Tokens::$emptyTokens, - ( $stackPtr + 1 ), - null, - true - ); + $keys = $this->get_array_access_keys( $stackPtr, false ); - // If it isn't a bracket, this isn't an array-access. - if ( false === $open_bracket || \T_OPEN_SQUARE_BRACKET !== $this->tokens[ $open_bracket ]['code'] ) { - return false; + if ( isset( $keys[0] ) ) { + return $keys[0]; } - $key = $this->phpcsFile->getTokensAsString( - ( $open_bracket + 1 ), - ( $this->tokens[ $open_bracket ]['bracket_closer'] - $open_bracket - 1 ) - ); - - return trim( $key ); + return false; } /** From a598b08f544155d04f35d9e82e058ae233b894a0 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 29 Mar 2019 08:17:18 +0100 Subject: [PATCH 134/241] ValidatedSanitizedInput/Sniff::is_validated(): allow for multi-level array key check This commit builds onto earlier improvements to this sniff via PR 1634 and 1635 This implements the use of the new `get_array_access_keys()` method in the `WordPress.Security.ValidatedSanitizedInput` sniff and the `Sniff::is_validated()` method. This allow for more precise checking of whether the correct variable has been validated properly before use. This should prevent some false positives as well as false negatives. Includes unit tests. --- WordPress/Sniff.php | 75 +++++++++++++++---- .../Security/ValidatedSanitizedInputSniff.php | 6 +- .../ValidatedSanitizedInputUnitTest.inc | 27 +++++++ .../ValidatedSanitizedInputUnitTest.php | 5 ++ 4 files changed, 94 insertions(+), 19 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 837d772f99..0589796ba5 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1916,17 +1916,20 @@ protected function get_array_access_key( $stackPtr ) { * * @since 0.5.0 * @since 2.1.0 Now recognizes array_key_exists() and key_exists() as validation functions. + * @since 2.1.0 Stricter check on whether the correct variable and the correct + * array keys are being validated. * - * @param int $stackPtr The index of this token in the stack. - * @param string $array_key An array key to check for ("bar" in $foo['bar']). - * @param bool $in_condition_only Whether to require that this use of the - * variable occur within the scope of the - * validating condition, or just in the same - * scope as it (default). + * @param int $stackPtr The index of this token in the stack. + * @param array|string $array_keys An array key to check for ("bar" in $foo['bar']) + * or an array of keys for multi-level array access. + * @param bool $in_condition_only Whether to require that this use of the + * variable occur within the scope of the + * validating condition, or just in the same + * scope as it (default). * * @return bool Whether the var is validated. */ - protected function is_validated( $stackPtr, $array_key = null, $in_condition_only = false ) { + protected function is_validated( $stackPtr, $array_keys = array(), $in_condition_only = false ) { if ( $in_condition_only ) { /* @@ -1977,11 +1980,14 @@ protected function is_validated( $stackPtr, $array_key = null, $in_condition_onl } $scope_end = $stackPtr; + } + if ( ! empty( $array_keys ) && ! is_array( $array_keys ) ) { + $array_keys = (array) $array_keys; } - $bare_array_key = $this->strip_quotes( $array_key ); - $targets = array( + $bare_array_keys = array_map( array( $this, 'strip_quotes' ), $array_keys ); + $targets = array( \T_ISSET => 'construct', \T_EMPTY => 'construct', \T_UNSET => 'construct', @@ -2016,11 +2022,15 @@ protected function is_validated( $stackPtr, $array_key = null, $in_condition_onl continue; } - // If we're checking for a specific array key (ex: 'hello' in + // If we're checking for specific array keys (ex: 'hello' in // $_POST['hello']), that must match too. Quote-style, however, doesn't matter. - if ( isset( $array_key ) - && $this->strip_quotes( $this->get_array_access_key( $i ) ) !== $bare_array_key ) { - continue; + if ( ! empty( $bare_array_keys ) ) { + $found_keys = $this->get_array_access_keys( $i ); + $found_keys = array_map( array( $this, 'strip_quotes' ), $found_keys ); + $diff = array_diff_assoc( $bare_array_keys, $found_keys ); + if ( ! empty( $diff ) ) { + continue; + } } return true; @@ -2053,12 +2063,45 @@ protected function is_validated( $stackPtr, $array_key = null, $in_condition_onl } $params = $this->get_function_call_parameters( $i ); - if ( $params[2]['raw'] !== $this->tokens[ $stackPtr ]['content'] ) { + if ( count( $params ) < 2 ) { continue 2; } - if ( isset( $array_key ) - && $this->strip_quotes( $params[1]['raw'] ) !== $bare_array_key ) { + $param2_first_token = $this->phpcsFile->findNext( Tokens::$emptyTokens, $params[2]['start'], ( $params[2]['end'] + 1 ), true ); + if ( false === $param2_first_token + || \T_VARIABLE !== $this->tokens[ $param2_first_token ]['code'] + || $this->tokens[ $param2_first_token ]['content'] !== $this->tokens[ $stackPtr ]['content'] + ) { + continue 2; + } + + if ( ! empty( $bare_array_keys ) ) { + // Prevent the original array from being altered. + $bare_keys = $bare_array_keys; + $last_key = array_pop( $bare_keys ); + + /* + * For multi-level array access, the complete set of keys could be split between + * the first and the second parameter, but could also be completely in the second + * parameter, so we need to check both options. + */ + + $found_keys = $this->get_array_access_keys( $param2_first_token ); + $found_keys = array_map( array( $this, 'strip_quotes' ), $found_keys ); + + // First try matching the complete set against the second parameter. + $diff = array_diff_assoc( $bare_array_keys, $found_keys ); + if ( empty( $diff ) ) { + return true; + } + + // If that failed, try getting an exact match for the subset against the + // second parameter and the last key against the first. + if ( $bare_keys === $found_keys && $this->strip_quotes( $params[1]['raw'] ) === $last_key ) { + return true; + } + + // Didn't find the correct array keys. continue 2; } diff --git a/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php b/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php index 2f5ca051b1..6fa904bc80 100644 --- a/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php +++ b/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php @@ -123,16 +123,16 @@ function ( $symbol ) { return; } - $array_key = $this->get_array_access_key( $stackPtr ); + $array_keys = $this->get_array_access_keys( $stackPtr ); - if ( empty( $array_key ) ) { + if ( empty( $array_keys ) ) { return; } $error_data = array( $this->tokens[ $stackPtr ]['content'] ); // Check for validation first. - if ( ! $this->is_validated( $stackPtr, $array_key, $this->check_validation_in_scope_only ) ) { + if ( ! $this->is_validated( $stackPtr, $array_keys, $this->check_validation_in_scope_only ) ) { $this->phpcsFile->addError( 'Detected usage of a non-validated input variable: %s', $stackPtr, diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc index a4059d5b09..1cce83dc39 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc @@ -230,3 +230,30 @@ function test_allow_array_key_exists_alias() { if ( key_exists( 'my_field1', $_POST ) ) { $id = (int) $_POST['my_field1']; // OK. } + +function test_correct_multi_level_array_validation() { + if ( isset( $_POST['toplevel']['sublevel'] ) ) { + $id = (int) $_POST['toplevel']; // OK, if a subkey exists, the top level key *must* also exist. + $id = (int) $_POST['toplevel']['sublevel']; // OK. + $id = (int) $_POST['toplevel']['sublevel']['subsub']; // Bad x1 - validate, this sub has not been validated. + } + + if ( array_key_exists( 'bar', $_POST['foo'] ) ) { + $id = (int) $_POST['bar']; // Bad x 1 - validate. + $id = (int) $_POST['foo']; // OK. + $id = (int) $_POST['foo']['bar']; // OK. + $id = (int) $_POST['foo']['bar']['baz']; // Bad x 1 - validate. + } +} + +function test_correct_multi_level_array_validation_key_order() { + if ( isset( $_POST['toplevel']['sublevel'] ) ) { + $id = (int) $_POST['sublevel']['toplevel']; // Bad x 1 - validate - key order is wrong. + } +} + +function test_invalid_array_key_exists_call() { + if ( array_key_exists( 'bar' ) ) { + $id = (int) $_POST['bar']; // Bad x 1 - validate. + } +} diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php index 430b278b81..06886006a1 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php @@ -60,6 +60,11 @@ public function getErrorList() { 210 => 1, 216 => 1, 217 => 1, + 238 => 1, + 242 => 1, + 245 => 1, + 251 => 1, + 257 => 1, ); } From b4fb6babb791b0dfcfe2d9294676b34619cdf34d Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 30 Mar 2019 16:42:00 +0100 Subject: [PATCH 135/241] ValidatedSanitizedInput: make the error messages more informative This changes two things: 1. For both the `InputNotValidated` as well as the `InputNotSanitized` error, it will now display the array keys for the variable triggering the error. Previously, the message would just say `$_POST`, now it will say `$_POST['foo']['bar']`. 2. For the `InputNotValidated`, the error message text has been expanded to make it more obvious how to fix this issue. Fixes 1541 --- WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php b/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php index 6fa904bc80..2e12075997 100644 --- a/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php +++ b/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php @@ -129,12 +129,12 @@ function ( $symbol ) { return; } - $error_data = array( $this->tokens[ $stackPtr ]['content'] ); + $error_data = array( $this->tokens[ $stackPtr ]['content'] . '[' . implode( '][', $array_keys ) . ']' ); // Check for validation first. if ( ! $this->is_validated( $stackPtr, $array_keys, $this->check_validation_in_scope_only ) ) { $this->phpcsFile->addError( - 'Detected usage of a non-validated input variable: %s', + 'Detected usage of a possibly undefined superglobal array index: %s. Use isset() or empty() to check the index exists before using it', $stackPtr, 'InputNotValidated', $error_data From 05a71fff27071017fba48ca0f8b25926c76f35d0 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 28 Mar 2019 01:22:30 +0100 Subject: [PATCH 136/241] Security: allow for type testing superglobals When a superglobal variable is being tested with, for instance, `is_numeric()`, unslashing or sanitization are not needed and it's ok for the nonce check to be done after it. This is completely safe. Ref: https://php.net/manual/en/ref.var.php Using these type testing functions should however not be regarded as a way of sanitizing/unslashing the variable and the variable does still need to be validated before being passed to one of these functions. To test whether a variable is used in one of these functions, a new `is_in_type_test()` method has been added to the `WordPressCS\Sniff` class, along with a `$typeTestFunctions` property containing the names of the functions this applies to. Notes: * The `is_array()` function which was previously, incorrectly, listed in the `$unslashingSanitizingFunctions` list has been moved to the new property. `is_array()` does not unslash or sanitize the contents of a variable, it only checks the variable type. * Implemented the use of the new `Sniff::is_in_type_test()` method in both the `ValidatedSanitizedInput` sniff, as well as in the `Sniff:has_nonce_check()` method for the `NonceVerification` sniff. Includes unit tests via the sniffs. --- WordPress/Sniff.php | 68 +++++++++++++++++-- .../Security/ValidatedSanitizedInputSniff.php | 5 ++ .../Security/NonceVerificationUnitTest.inc | 20 +++++- .../Security/NonceVerificationUnitTest.php | 1 + .../ValidatedSanitizedInputUnitTest.inc | 10 +++ .../ValidatedSanitizedInputUnitTest.php | 1 + 6 files changed, 97 insertions(+), 8 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 0589796ba5..f1dfe5a545 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -312,11 +312,42 @@ abstract class Sniff implements PHPCS_Sniff { 'doubleval' => true, 'floatval' => true, 'intval' => true, - 'is_array' => true, 'sanitize_key' => true, 'sizeof' => true, ); + /** + * List of PHP native functions to test the type of a variable. + * + * Using these functions is safe in combination with superglobals without + * unslashing or sanitization. + * + * They should, however, not be regarded as unslashing or sanitization functions. + * + * @since 2.1.0 + * + * @var array + */ + protected $typeTestFunctions = array( + 'is_array' => true, + 'is_bool' => true, + 'is_callable' => true, + 'is_countable' => true, + 'is_double' => true, + 'is_float' => true, + 'is_int' => true, + 'is_integer' => true, + 'is_iterable' => true, + 'is_long' => true, + 'is_null' => true, + 'is_numeric' => true, + 'is_object' => true, + 'is_real' => true, + 'is_resource' => true, + 'is_scalar' => true, + 'is_string' => true, + ); + /** * Token which when they preceed code indicate the value is safely casted. * @@ -1372,12 +1403,17 @@ protected function has_nonce_check( $stackPtr ) { } } - $in_isset = $this->is_in_isset_or_empty( $stackPtr ); + $allow_nonce_after = false; + if ( $this->is_in_isset_or_empty( $stackPtr ) + || $this->is_in_type_test( $stackPtr ) + ) { + $allow_nonce_after = true; + } - // We allow for isset( $_POST['var'] ) checks to come before the nonce check. - // If this is inside an isset(), check after it as well, all the way to the - // end of the scope. - if ( $in_isset ) { + // We allow for certain actions, such as an isset() check to come before the nonce check. + // If this superglobal is inside such a check, look for the nonce after it as well, + // all the way to the end of the scope. + if ( true === $allow_nonce_after ) { $end = ( 0 === $start ) ? $this->phpcsFile->numTokens : $tokens[ $start ]['scope_closer']; } @@ -1393,7 +1429,7 @@ protected function has_nonce_check( $stackPtr ) { // If we have already found an nonce check in this scope, we just // need to check whether it comes before this token. It is OK if the // check is after the token though, if this was only a isset() check. - return ( $in_isset || $last['nonce_check'] < $stackPtr ); + return ( true === $allow_nonce_after || $last['nonce_check'] < $stackPtr ); } elseif ( $end <= $last['end'] ) { // If not, we can still go ahead and return false if we've already // checked to the end of the search area. @@ -1624,6 +1660,24 @@ protected function is_in_function_call( $stackPtr, $valid_functions, $global = t return false; } + /** + * Check if a token is inside of an is_...() statement. + * + * @since 2.1.0 + * + * @param int $stackPtr The index of the token in the stack. + * + * @return bool Whether the token is being type tested. + */ + protected function is_in_type_test( $stackPtr ) { + /* + * Casting the potential integer stack pointer return value to boolean here is fine. + * The return can never be `0` as there will always be a PHP open tag before the + * function call. + */ + return (bool) $this->is_in_function_call( $stackPtr, $this->typeTestFunctions ); + } + /** * Check if something is only being sanitized. * diff --git a/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php b/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php index 6fa904bc80..b7ac24d329 100644 --- a/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php +++ b/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php @@ -145,6 +145,11 @@ function ( $symbol ) { return; } + // If this variable is being tested with one of the `is_..()` functions, sanitization isn't needed. + if ( $this->is_in_type_test( $stackPtr ) ) { + return; + } + // If this is a comparison ('a' == $_POST['foo']), sanitization isn't needed. if ( $this->is_comparison( $stackPtr ) ) { return; diff --git a/WordPress/Tests/Security/NonceVerificationUnitTest.inc b/WordPress/Tests/Security/NonceVerificationUnitTest.inc index b5387355de..652eb3afa7 100644 --- a/WordPress/Tests/Security/NonceVerificationUnitTest.inc +++ b/WordPress/Tests/Security/NonceVerificationUnitTest.inc @@ -17,7 +17,7 @@ function ajax_process() { } add_action( 'wp_ajax_process', 'ajax_process' ); -// It's also OK to check with isset() before the the nonce check. +// It's also OK to check with isset() before the nonce check. function foo() { if ( ! isset( $_POST['test'] ) || ! wp_verify_nonce( 'some_action' ) ) { exit; @@ -160,3 +160,21 @@ function foo_8() { sanitize_pc( $_POST['bar'] ); // Bad. my_nonce_check( sanitize_twitter( $_POST['tweet'] ) ); // Bad. } + +/* + * Using a superglobal in a is_...() function is OK as long as a nonce check is done + * before the variable is *really* used. + */ +function test_whitelisting_use_in_type_test_functions() { + if ( ! is_numeric ( $_POST['foo'] ) ) { // OK. + return; + } + + wp_verify_nonce( 'some_action' ); +} + +function test_incorrect_use_in_type_test_functions() { + if ( ! is_numeric ( $_POST['foo'] ) ) { // Bad. + return; + } +} diff --git a/WordPress/Tests/Security/NonceVerificationUnitTest.php b/WordPress/Tests/Security/NonceVerificationUnitTest.php index d937edb1e9..63ecbcdf37 100644 --- a/WordPress/Tests/Security/NonceVerificationUnitTest.php +++ b/WordPress/Tests/Security/NonceVerificationUnitTest.php @@ -46,6 +46,7 @@ public function getErrorList() { 159 => 1, 160 => 1, 161 => 1, + 177 => 1, ); } diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc index 1cce83dc39..a607e375d7 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc @@ -257,3 +257,13 @@ function test_invalid_array_key_exists_call() { $id = (int) $_POST['bar']; // Bad x 1 - validate. } } + +function test_ignoring_is_type_function_calls() { + // Usage within variable type tests does not need unslashing or sanitization. + if ( isset( $_POST[ $key ] ) && is_numeric( $_POST[ $key ] ) ) {} // OK. + if ( isset($_POST['plugin']) && is_string( $_POST['plugin'] ) ) {} // OK. + + if ( ! is_null( $_GET['not_set'] ) ) {} // Bad x1 - missing validation. + if ( array_key_exists( 'null', $_GET ) && ! is_null( $_GET['null'] ) ) {} // OK. + if ( array_key_exists( 'null', $_POST ) && $_POST['null'] !== null ) {} // OK. +} diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php index 06886006a1..e96a623db0 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php @@ -65,6 +65,7 @@ public function getErrorList() { 245 => 1, 251 => 1, 257 => 1, + 266 => 1, ); } From 7841dab2325e539e1722d752ca35e9f056d7f0c3 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 30 Mar 2019 15:31:28 +0100 Subject: [PATCH 137/241] Sniff::is_sanitized(): allow for map_deep() to sanitize arrays **Important note:** Functions which alter the array by reference, such as the PHP native `array_walk()` and `array_walk_recursive()` are not listed in the new `$arrayWalkingFunctions` property on purpose. * These cannot easily be used for sanitization as they can't be combined with unslashing, so could only be used in combination with the `$unslashingSanitizingFunctions`. Additionally as they alter the array by reference, at this moment, accessing the array after the sanitization through one of these function would _still_ trigger errors. If at some point in the future, the above combination would be accounted for, preventing these additional errors would also need to be addressed. * Similarly, they cannot be used for late escaping as the return value is a boolean, not the altered array. Also see my comment in the original issue where I go in slightly more detail: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/ 1660#issuecomment-478254403 Includes unit test. Fixes 1660 Fixes 1618 Once this has been merged, the [Sanitizing array input data](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Sanitizing-array-input-data) wiki page should probably be updated (or an issue be opened saying that it should be with a link to this PR and the tickets). --- WordPress/Sniff.php | 29 +++++++++++++++---- .../ValidatedSanitizedInputUnitTest.inc | 9 ++++++ .../ValidatedSanitizedInputUnitTest.php | 1 + 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index f1dfe5a545..7786624c25 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -361,6 +361,25 @@ abstract class Sniff implements PHPCS_Sniff { \T_BOOL_CAST => true, ); + /** + * List of array functions which apply a callback to the array. + * + * These are often used for sanitization/escaping an array variable. + * + * Note: functions which alter the array by reference are not listed here on purpose. + * These cannot easily be used for sanitization as they can't be combined with unslashing. + * Similarly, they cannot be used for late escaping as the return value is a boolean, not + * the altered array. + * + * @since 2.1.0 + * + * @var array => + */ + protected $arrayWalkingFunctions = array( + 'array_map' => 1, + 'map_deep' => 2, + ); + /** * Functions that format strings. * @@ -1778,8 +1797,8 @@ protected function is_sanitized( $stackPtr, $require_unslash = false ) { $valid_functions = $this->sanitizingFunctions; $valid_functions += $this->unslashingSanitizingFunctions; + $valid_functions += $this->arrayWalkingFunctions; $valid_functions['wp_unslash'] = true; - $valid_functions['array_map'] = true; $functionPtr = $this->is_in_function_call( $stackPtr, $valid_functions ); @@ -1814,11 +1833,11 @@ protected function is_sanitized( $stackPtr, $require_unslash = false ) { $is_unslashed = false; } - // Arrays might be sanitized via array_map(). - if ( 'array_map' === $functionName ) { + // Arrays might be sanitized via an array walking function using a callback. + if ( isset( $this->arrayWalkingFunctions[ $functionName ] ) ) { - // Get the first parameter. - $callback = $this->get_function_call_parameter( $functionPtr, 1 ); + // Get the callback parameter. + $callback = $this->get_function_call_parameter( $functionPtr, $this->arrayWalkingFunctions[ $functionName ] ); if ( ! empty( $callback ) ) { /* diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc index a607e375d7..84b4c16fed 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc @@ -267,3 +267,12 @@ function test_ignoring_is_type_function_calls() { if ( array_key_exists( 'null', $_GET ) && ! is_null( $_GET['null'] ) ) {} // OK. if ( array_key_exists( 'null', $_POST ) && $_POST['null'] !== null ) {} // OK. } + +function test_additional_array_walking_functions() { + if ( ! isset( $_GET['test'] ) ) { + return; + } + + $sane = map_deep( wp_unslash( $_GET['test'] ), 'sanitize_text_field' ); // Ok. + $sane = map_deep( wp_unslash( $_GET['test'] ), 'foo' ); // Bad. +} diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php index e96a623db0..74ff09a7d3 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php @@ -66,6 +66,7 @@ public function getErrorList() { 251 => 1, 257 => 1, 266 => 1, + 277 => 1, ); } From d0f7084b4c263ba22f249bf6f0ca02f409ce80f8 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 31 Mar 2019 06:52:46 +0200 Subject: [PATCH 138/241] Sniff::has_nonce_check(): add new `is_class_object_call()` and `is_token_namespaced()` checks This fixes potential false negatives when a method/namespaced function mirroring the name of the WP nonc verification functions would be used. Includes unit tests. --- WordPress/Sniff.php | 11 +++++++++++ .../Tests/Security/NonceVerificationUnitTest.inc | 11 +++++++++++ .../Tests/Security/NonceVerificationUnitTest.php | 2 ++ 3 files changed, 24 insertions(+) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index f1dfe5a545..7b3e29b658 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1457,6 +1457,17 @@ protected function has_nonce_check( $stackPtr ) { // If this is one of the nonce verification functions, we can bail out. if ( isset( $this->nonceVerificationFunctions[ $tokens[ $i ]['content'] ] ) ) { + /* + * Now, make sure it is a call to a global function. + */ + if ( $this->is_class_object_call( $i ) === true ) { + continue; + } + + if ( $this->is_token_namespaced( $i ) === true ) { + continue; + } + $last['nonce_check'] = $i; return true; } diff --git a/WordPress/Tests/Security/NonceVerificationUnitTest.inc b/WordPress/Tests/Security/NonceVerificationUnitTest.inc index 652eb3afa7..d7959cfa95 100644 --- a/WordPress/Tests/Security/NonceVerificationUnitTest.inc +++ b/WordPress/Tests/Security/NonceVerificationUnitTest.inc @@ -178,3 +178,14 @@ function test_incorrect_use_in_type_test_functions() { return; } } + +function fix_false_negatives_userland_method_same_name() { + WP_Faker::check_ajax_referer( 'something' ); + $faker->check_admin_referer( 'something' ); + do_something( $_POST['abc'] ); // Bad. +} + +function fix_false_negatives_namespaced_function_same_name() { + WP_Faker\SecurityBypass\wp_verify_nonce( 'something' ); + do_something( $_POST['abc'] ); // Bad. +} diff --git a/WordPress/Tests/Security/NonceVerificationUnitTest.php b/WordPress/Tests/Security/NonceVerificationUnitTest.php index 63ecbcdf37..0929ffda1c 100644 --- a/WordPress/Tests/Security/NonceVerificationUnitTest.php +++ b/WordPress/Tests/Security/NonceVerificationUnitTest.php @@ -47,6 +47,8 @@ public function getErrorList() { 160 => 1, 161 => 1, 177 => 1, + 185 => 1, + 190 => 1, ); } From e05b727a843699e7ebcfae9f52d0280ff41f7066 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 30 Mar 2019 15:35:47 +0100 Subject: [PATCH 139/241] EscapeOutput: allow for map_deep() to output escape arrays Includes unit test. --- .../Sniffs/Security/EscapeOutputSniff.php | 36 ++++++++++++------- .../Tests/Security/EscapeOutputUnitTest.inc | 3 ++ .../Tests/Security/EscapeOutputUnitTest.php | 1 + 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/WordPress/Sniffs/Security/EscapeOutputSniff.php b/WordPress/Sniffs/Security/EscapeOutputSniff.php index 9a1feaa857..d1dae3af85 100644 --- a/WordPress/Sniffs/Security/EscapeOutputSniff.php +++ b/WordPress/Sniffs/Security/EscapeOutputSniff.php @@ -382,20 +382,32 @@ public function process_token( $stackPtr ) { if ( false !== $function_opener ) { - if ( 'array_map' === $functionName ) { - - // Get the first parameter (name of function being used on the array). - $mapped_function = $this->phpcsFile->findNext( - Tokens::$emptyTokens, - ( $function_opener + 1 ), - $this->tokens[ $function_opener ]['parenthesis_closer'], - true + if ( isset( $this->arrayWalkingFunctions[ $functionName ] ) ) { + + // Get the callback parameter. + $callback = $this->get_function_call_parameter( + $ptr, + $this->arrayWalkingFunctions[ $functionName ] ); - // If we're able to resolve the function name, do so. - if ( $mapped_function && \T_CONSTANT_ENCAPSED_STRING === $this->tokens[ $mapped_function ]['code'] ) { - $functionName = $this->strip_quotes( $this->tokens[ $mapped_function ]['content'] ); - $ptr = $mapped_function; + if ( ! empty( $callback ) ) { + /* + * If this is a function callback (not a method callback array) and we're able + * to resolve the function name, do so. + */ + $mapped_function = $this->phpcsFile->findNext( + Tokens::$emptyTokens, + $callback['start'], + ( $callback['end'] + 1 ), + true + ); + + if ( false !== $mapped_function + && \T_CONSTANT_ENCAPSED_STRING === $this->tokens[ $mapped_function ]['code'] + ) { + $functionName = $this->strip_quotes( $this->tokens[ $mapped_function ]['content'] ); + $ptr = $mapped_function; + } } } diff --git a/WordPress/Tests/Security/EscapeOutputUnitTest.inc b/WordPress/Tests/Security/EscapeOutputUnitTest.inc index bd7adb3930..875f575f23 100644 --- a/WordPress/Tests/Security/EscapeOutputUnitTest.inc +++ b/WordPress/Tests/Security/EscapeOutputUnitTest.inc @@ -289,3 +289,6 @@ echo esc_html( $something ), echo get_the_title(); // Bad. echo wp_kses_post( get_the_title() ); // Ok. echo esc_html( get_the_title() ); // Ok. + +echo implode( '
', map_deep( $items, 'esc_html' ) ); // Ok. +echo implode( '
', map_deep( $items, 'foo' ) ); // Bad. diff --git a/WordPress/Tests/Security/EscapeOutputUnitTest.php b/WordPress/Tests/Security/EscapeOutputUnitTest.php index 6fc0837e54..52b554be55 100644 --- a/WordPress/Tests/Security/EscapeOutputUnitTest.php +++ b/WordPress/Tests/Security/EscapeOutputUnitTest.php @@ -79,6 +79,7 @@ public function getErrorList() { 264 => 1, 266 => 1, 289 => 1, + 294 => 1, ); } From 0934e18a3c1b02d190c2a84b7e8b991ad6284026 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 30 Mar 2019 17:34:53 +0100 Subject: [PATCH 140/241] ValidatedSanitizedInput: treat array-value comparison functions same as other comparisons Whether a comparison is made via a comparison operator or via one of the array-value comparison functions shouldn't make a difference for this sniff. Both ways of making a comparison should be treated the same. This was, so far, not the case. While `in_array()` was listed in the `$sanitizingFunctions` list, the other array-value comparison functions were not. And for `in_array()` a "missing unslash" error would still be thrown, while this doesn't happen when using straight comparisons. This PR fixes that and adds a new `is_in_array_comparison()` utility function to the `Sniff` class. Includes unit tests via the sniff. --- WordPress/Sniff.php | 45 ++++++++++++++++++- .../Security/ValidatedSanitizedInputSniff.php | 5 +++ .../ValidatedSanitizedInputUnitTest.inc | 13 ++++++ .../ValidatedSanitizedInputUnitTest.php | 1 + 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 10ac07bc01..80b24d54d3 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -256,7 +256,6 @@ abstract class Sniff implements PHPCS_Sniff { 'filter_input' => true, 'filter_var' => true, 'hash_equals' => true, - 'in_array' => true, 'is_email' => true, 'number_format' => true, 'sanitize_bookmark_field' => true, @@ -380,6 +379,22 @@ abstract class Sniff implements PHPCS_Sniff { 'map_deep' => 2, ); + /** + * Array functions to compare a $needle to a predefined set of values. + * + * If the value is set to an integer, the function needs to have at least that + * many parameters for it to be considered as a comparison. + * + * @since 2.1.0 + * + * @var array => + */ + protected $arrayCompareFunctions = array( + 'in_array' => true, + 'array_search' => true, + 'array_keys' => 2, + ); + /** * Functions that format strings. * @@ -2263,6 +2278,34 @@ protected function is_comparison( $stackPtr ) { return false; } + /** + * Check if a token is inside of an array-value comparison function. + * + * @since 2.1.0 + * + * @param int $stackPtr The index of the token in the stack. + * + * @return bool Whether the token is (part of) a parameter to an + * array-value comparison function. + */ + protected function is_in_array_comparison( $stackPtr ) { + $function_ptr = $this->is_in_function_call( $stackPtr, $this->arrayCompareFunctions, true, true ); + if ( false === $function_ptr ) { + return false; + } + + $function_name = $this->tokens[ $function_ptr ]['content']; + if ( true === $this->arrayCompareFunctions[ $function_name ] ) { + return true; + } + + if ( $this->get_function_call_parameter_count( $function_ptr ) >= $this->arrayCompareFunctions[ $function_name ] ) { + return true; + } + + return false; + } + /** * Check what type of 'use' statement a token is part of. * diff --git a/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php b/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php index 14b3f26b39..881480e33b 100644 --- a/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php +++ b/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php @@ -155,6 +155,11 @@ function ( $symbol ) { return; } + // If this is a comparison using the array comparison functions, sanitization isn't needed. + if ( $this->is_in_array_comparison( $stackPtr ) ) { + return; + } + $this->mergeFunctionLists(); // Now look for sanitizing functions. diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc index 84b4c16fed..495f9342fc 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc @@ -276,3 +276,16 @@ function test_additional_array_walking_functions() { $sane = map_deep( wp_unslash( $_GET['test'] ), 'sanitize_text_field' ); // Ok. $sane = map_deep( wp_unslash( $_GET['test'] ), 'foo' ); // Bad. } + +function test_recognize_array_comparison_functions_as_such() { + if ( ! isset( $_POST['form_fields'] ) ) { + return; + } + + if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'install', 'update', 'activate' ), true ) ) {} // OK. + if ( isset( $_REQUEST['plugin_state'] ) && in_array( $_REQUEST['plugin_state'], $states, true ) ) {} // OK. + if ( in_array( 'my_form_hidden_field_value', $_POST['form_fields'], true ) ) {} // OK. + if ( array_search( $_POST['form_fields'], 'my_form_hidden_field_value' ) ) {} // OK. + if ( array_keys( $_POST['form_fields'], 'my_form_hidden_field_value', true ) ) {} // OK. + if ( array_keys( $_POST['form_fields'] ) ) {} // Bad x2. +} diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php index 74ff09a7d3..ab2aa92d74 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php @@ -67,6 +67,7 @@ public function getErrorList() { 257 => 1, 266 => 1, 277 => 1, + 290 => 2, ); } From 5f2d6b544042797426c6ef5b24a844b3071e4025 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 31 Mar 2019 07:14:47 +0200 Subject: [PATCH 141/241] Sniff::has_nonce_check(): ignore nonce checks in nested closed scopes A function, closure, anonymous class and other OO constructs are all "closed" scopes. If any of these are nested, they open a nested closed scope and anything within that scope should be disregarded for the purpose of verifying whether or not a nonce check has been executed. This small change implements that. This fixes some potential false negatives. Includes unit tests. Related to 764 --- WordPress/Sniff.php | 10 ++++++++++ .../Security/NonceVerificationUnitTest.inc | 20 +++++++++++++++++++ .../Security/NonceVerificationUnitTest.php | 2 ++ 3 files changed, 32 insertions(+) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 10ac07bc01..8a64bc8689 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1468,6 +1468,16 @@ protected function has_nonce_check( $stackPtr ) { // Loop through the tokens looking for nonce verification functions. for ( $i = $start; $i < $end; $i++ ) { + // Skip over nested closed scope constructs. + if ( \T_FUNCTION === $tokens[ $i ]['code'] + || \T_CLOSURE === $tokens[ $i ]['code'] + || isset( Tokens::$ooScopeTokens[ $tokens[ $i ]['code'] ] ) + ) { + if ( isset( $tokens[ $i ]['scope_closer'] ) ) { + $i = $tokens[ $i ]['scope_closer']; + } + continue; + } // If this isn't a function name, skip it. if ( \T_STRING !== $tokens[ $i ]['code'] ) { diff --git a/WordPress/Tests/Security/NonceVerificationUnitTest.inc b/WordPress/Tests/Security/NonceVerificationUnitTest.inc index d7959cfa95..7c604beb3f 100644 --- a/WordPress/Tests/Security/NonceVerificationUnitTest.inc +++ b/WordPress/Tests/Security/NonceVerificationUnitTest.inc @@ -189,3 +189,23 @@ function fix_false_negatives_namespaced_function_same_name() { WP_Faker\SecurityBypass\wp_verify_nonce( 'something' ); do_something( $_POST['abc'] ); // Bad. } + +function skip_over_nested_constructs_1() { + $b = function () { + check_ajax_referer( 'something' ); // Nonce check is not in the same function scope. + }; + + do_something( $_POST['abc'] ); // Bad. +} + +function skip_over_nested_constructs_2() { + if ( $_POST['abc'] === 'test' ) { // Bad. + return; + } + + $b = new class() { + public function named() { + check_ajax_referer( 'something' ); // Nonce check is not in the same function scope. + } + }; +} diff --git a/WordPress/Tests/Security/NonceVerificationUnitTest.php b/WordPress/Tests/Security/NonceVerificationUnitTest.php index 0929ffda1c..838e897a9b 100644 --- a/WordPress/Tests/Security/NonceVerificationUnitTest.php +++ b/WordPress/Tests/Security/NonceVerificationUnitTest.php @@ -49,6 +49,8 @@ public function getErrorList() { 177 => 1, 185 => 1, 190 => 1, + 198 => 1, + 202 => 1, ); } From 1a79eae7dccbb15b203c332671b20d14548aa1c8 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 30 Mar 2019 04:27:53 +0100 Subject: [PATCH 142/241] ValidatedSanitizedInput: add unit tests for null coalesce (equals) operators --- .../ValidatedSanitizedInputUnitTest.inc | 35 ++++++++++++++++++- .../ValidatedSanitizedInputUnitTest.php | 11 ++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc index 495f9342fc..93ceaec2bb 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc @@ -161,7 +161,7 @@ some string {$_POST[some_var]} {$_GET['evil']} EOD ); // Bad x2. -if ( ( $_POST['foo'] ?? 'post' ) === 'post' ) {} // OK. +if ( ( $_POST['foo'] ?? 'post' ) === 'post' ) {} // Bad x2 - unslash, sanitize - more complex compares are not handled. if ( ( $_POST['foo'] <=> 'post' ) === 0 ) {} // OK. // Test whitespace independent isset/empty detection. @@ -289,3 +289,36 @@ function test_recognize_array_comparison_functions_as_such() { if ( array_keys( $_POST['form_fields'], 'my_form_hidden_field_value', true ) ) {} // OK. if ( array_keys( $_POST['form_fields'] ) ) {} // Bad x2. } + +/* + * Test recognition of validation via null coalesce, while still checking the var for sanitization. + */ +function test_null_coalesce_1() { + $var = sanitize_text_field( wp_unslash( $_POST['foo'] ?? '' ) ); // OK. + $var = sanitize_text_field( wp_unslash( $_POST['fool'] ?? $_POST['secondary'] ?? '' ) ); // OK. + $var = sanitize_text_field( wp_unslash( $_POST['bar']['sub'] ?? '' ) ); // OK. + $var = sanitize_text_field( $_POST['foobar'] ?? '' ); // Bad x1 - unslash. +} + +// The below two sets should give the same errors. +function test_null_coalesce_2() { + $var = $_POST['foo'] ?? ''; // Bad x2 - sanitize + unslash. + $var = $_POST['bar']['sub'] ?? ''; // Bad x2 - sanitize + unslash. + $var = ( $_POST['foobar']['sub'] ?? '' ); // Bad x2 - sanitize + unslash. + + $var = isset( $_POST['_foo'] ) ? $_POST['_foo'] : ''; // Bad x2 - sanitize + unslash. + $var = isset( $_POST['_bar']['_sub'] ) ? $_POST['_bar']['_sub'] : ''; // Bad x2 - sanitize + unslash. + $var = ( isset( $_POST['_foobar']['_sub'] ) ? $_POST['_foobar']['_sub'] : '' ); // Bad x2 - sanitize + unslash. +} + +function test_null_coalesce_validation() { + $_POST['key'] = $_POST['key'] ?? 'default'; // OK, assignment & Bad x2 - unslash, sanitize. + $key = sanitize_text_field( wp_unslash( $_POST['key'] ) ); // OK, validated via null coalesce. + $another_key = sanitize_text_field( wp_unslash( $_POST['another_key'] ) ); // Bad, not validated, different key. +} + +function test_null_coalesce_equals_validation() { + $_POST['key'] ??= 'default'; // OK, assignment. + $key = sanitize_text_field( wp_unslash( $_POST['key'] ) ); // OK, validated via null coalesce equals. + $another_key = sanitize_text_field( wp_unslash( $_POST['another_key'] ) ); // Bad, not validated, different key. +} diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php index ab2aa92d74..ca0821bd59 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php @@ -54,6 +54,7 @@ public function getErrorList() { 138 => 1, 150 => 2, 160 => 2, + 164 => 2, 189 => 1, 202 => 1, 206 => 1, @@ -68,6 +69,16 @@ public function getErrorList() { 266 => 1, 277 => 1, 290 => 2, + 300 => 1, + 305 => 2, + 306 => 2, + 307 => 2, + 309 => 2, + 310 => 2, + 311 => 2, + 315 => 2, + 317 => 1, + 323 => 1, ); } From 6c8d0523d289fb7841d5a599200edfecbbc0d202 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 30 Mar 2019 04:58:38 +0100 Subject: [PATCH 143/241] Sniff::is_comparison(): allow to disregard null coalesce The null coalesce operator `??` is a special comparison operator, in the sense that it doesn't compare a variable to whatever is on the other side of the comparison operator. For this reason, it should be possible to disregard it. --- WordPress/Sniff.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 9f00241cc4..51562dae5e 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -2229,12 +2229,24 @@ protected function is_validated( $stackPtr, $array_keys = array(), $in_condition * Also recognizes `switch ( $var )`. * * @since 0.5.0 + * @since 2.1.0 Added the $include_coalesce parameter. * - * @param int $stackPtr The index of this token in the stack. + * @param int $stackPtr The index of this token in the stack. + * @param bool $include_coalesce Optional. Whether or not to regard the null + * coalesce operator - ?? - as a comparison operator. + * Defaults to true. + * Null coalesce is a special comparison operator in this + * sense as it doesn't compare a variable to whatever is + * on the other side of the comparison operator. * * @return bool Whether this is a comparison. */ - protected function is_comparison( $stackPtr ) { + protected function is_comparison( $stackPtr, $include_coalesce = true ) { + + $comparisonTokens = Tokens::$comparisonTokens; + if ( false === $include_coalesce ) { + unset( $comparisonTokens[ \T_COALESCE ] ); + } // We first check if this is a switch statement (switch ( $var )). if ( isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) { @@ -2258,7 +2270,7 @@ protected function is_comparison( $stackPtr ) { true ); - if ( isset( Tokens::$comparisonTokens[ $this->tokens[ $previous_token ]['code'] ] ) ) { + if ( isset( $comparisonTokens[ $this->tokens[ $previous_token ]['code'] ] ) ) { return true; } @@ -2281,7 +2293,7 @@ protected function is_comparison( $stackPtr ) { ); } - if ( false !== $next_token && isset( Tokens::$comparisonTokens[ $this->tokens[ $next_token ]['code'] ] ) ) { + if ( false !== $next_token && isset( $comparisonTokens[ $this->tokens[ $next_token ]['code'] ] ) ) { return true; } From 449ea6472d328ae8ba44d21134803447aa121b1b Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 30 Mar 2019 04:29:05 +0100 Subject: [PATCH 144/241] Sniff::is_validated(): recognize null coalesce (equal) operator as a way to validate a variable This adds recognition of the coalesce operator `??` (PHP 7.0) and the coalesce equals operator `??=`, as will be added in PHP 7.4, to the `Sniff::is_validated()` method. This prevents false positives where variables would be seen as "not validated", when the variable has in fact been validated via a coalesce equals assignment in a previous statement. Related to 764, 840 --- WordPress/Sniff.php | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 51562dae5e..f7d0f2ff75 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -2097,10 +2097,12 @@ protected function is_validated( $stackPtr, $array_keys = array(), $in_condition $bare_array_keys = array_map( array( $this, 'strip_quotes' ), $array_keys ); $targets = array( - \T_ISSET => 'construct', - \T_EMPTY => 'construct', - \T_UNSET => 'construct', - \T_STRING => 'function_call', + \T_ISSET => 'construct', + \T_EMPTY => 'construct', + \T_UNSET => 'construct', + \T_STRING => 'function_call', + \T_COALESCE => 'coalesce', + \T_COALESCE_EQUAL => 'coalesce', ); // phpcs:ignore Generic.CodeAnalysis.JumbledIncrementer.Found -- On purpose, see below. @@ -2215,6 +2217,40 @@ protected function is_validated( $stackPtr, $array_keys = array(), $in_condition } return true; + + case 'coalesce': + $prev = $i; + do { + $prev = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $prev - 1 ), null, true, null, true ); + // Skip over array keys, like $_GET['key']['subkey']. + if ( \T_CLOSE_SQUARE_BRACKET === $this->tokens[ $prev ]['code'] ) { + $prev = $this->tokens[ $prev ]['bracket_opener']; + continue; + } + + break; + } while ( $prev >= ( $scope_start + 1 ) ); + + // We should now have reached the variable. + if ( \T_VARIABLE !== $this->tokens[ $prev ]['code'] ) { + continue 2; + } + + if ( $this->tokens[ $prev ]['content'] !== $this->tokens[ $stackPtr ]['content'] ) { + continue 2; + } + + if ( ! empty( $bare_array_keys ) ) { + $found_keys = $this->get_array_access_keys( $prev ); + $found_keys = array_map( array( $this, 'strip_quotes' ), $found_keys ); + $diff = array_diff_assoc( $bare_array_keys, $found_keys ); + if ( ! empty( $diff ) ) { + continue 2; + } + } + + // Right variable, correct key. + return true; } } From 625f221df1c2294c905796afeba2a1584f77da57 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 30 Mar 2019 10:30:06 +0100 Subject: [PATCH 145/241] ValidatedSanitizedInput: throw unslash/sanitization errors for null coalesced variable --- WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php b/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php index 881480e33b..1a0be175c3 100644 --- a/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php +++ b/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php @@ -151,7 +151,7 @@ function ( $symbol ) { } // If this is a comparison ('a' == $_POST['foo']), sanitization isn't needed. - if ( $this->is_comparison( $stackPtr ) ) { + if ( $this->is_comparison( $stackPtr, false ) ) { return; } From 7c6f0a85abccaf38e89f1f95c985e98e61dd45c4 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 30 Mar 2019 10:32:14 +0100 Subject: [PATCH 146/241] ValidatedSanitizedInput: allow for validation via null coalesce / null coalesce equals PHP 7.0 introduced the null coalesce operator, while PHP 7.4 will introduce the null coalesce equal operator. These operators should be accounted for in the `ValidatedSanitizedInput` sniff as valid ways to validate a variable, but should still allow for the sniff to *also* check for sanitization. Refs: * https://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.coalesce * https://wiki.php.net/rfc/isset_ternary * https://wiki.php.net/rfc/null_coalesce_equal_operator Related to 764 Fixes 837 Closes 840 which is superseded by this PR --- .../Security/ValidatedSanitizedInputSniff.php | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php b/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php index 1a0be175c3..4b65ac65be 100644 --- a/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php +++ b/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php @@ -10,6 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\Security; use WordPressCS\WordPress\Sniff; +use PHP_CodeSniffer\Util\Tokens; /** * Flag any non-validated/sanitized input ( _GET / _POST / etc. ). @@ -131,8 +132,37 @@ function ( $symbol ) { $error_data = array( $this->tokens[ $stackPtr ]['content'] . '[' . implode( '][', $array_keys ) . ']' ); - // Check for validation first. - if ( ! $this->is_validated( $stackPtr, $array_keys, $this->check_validation_in_scope_only ) ) { + /* + * Check for validation first. + */ + $validated = false; + + for ( $i = ( $stackPtr + 1 ); $i < $this->phpcsFile->numTokens; $i++ ) { + if ( isset( Tokens::$emptyTokens[ $this->tokens[ $i ]['code'] ] ) ) { + continue; + } + + if ( \T_OPEN_SQUARE_BRACKET === $this->tokens[ $i ]['code'] + && isset( $this->tokens[ $i ]['bracket_closer'] ) + ) { + // Skip over array keys. + $i = $this->tokens[ $i ]['bracket_closer']; + continue; + } + + if ( \T_COALESCE === $this->tokens[ $i ]['code'] ) { + $validated = true; + } + + // Anything else means this is not a validation coalesce. + break; + } + + if ( false === $validated ) { + $validated = $this->is_validated( $stackPtr, $array_keys, $this->check_validation_in_scope_only ); + } + + if ( false === $validated ) { $this->phpcsFile->addError( 'Detected usage of a possibly undefined superglobal array index: %s. Use isset() or empty() to check the index exists before using it', $stackPtr, From 7b187492e9556e9567d5baf52746b3ef63b2de15 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 31 Mar 2019 07:00:36 +0200 Subject: [PATCH 147/241] Sniff::has_nonce_check(): allow for comparing a variable before nonce check This builds onto the similar changes made for the `ValidatedSanitizedInput` sniff in ... This fixes false positives as reported in 1114 and 1506. Note: it is not currently checked that the nonce check is done within the same conditional scope as the comparison. Just that it is done within the same _function_ scope. Includes unit tests. Fixes 1114 Fixes 1506 --- WordPress/Sniff.php | 2 + .../Security/NonceVerificationUnitTest.inc | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 9f00241cc4..8e6c6ffef3 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1440,6 +1440,8 @@ protected function has_nonce_check( $stackPtr ) { $allow_nonce_after = false; if ( $this->is_in_isset_or_empty( $stackPtr ) || $this->is_in_type_test( $stackPtr ) + || $this->is_comparison( $stackPtr ) + || $this->is_in_array_comparison( $stackPtr ) ) { $allow_nonce_after = true; } diff --git a/WordPress/Tests/Security/NonceVerificationUnitTest.inc b/WordPress/Tests/Security/NonceVerificationUnitTest.inc index 7c604beb3f..cd5a7d4f92 100644 --- a/WordPress/Tests/Security/NonceVerificationUnitTest.inc +++ b/WordPress/Tests/Security/NonceVerificationUnitTest.inc @@ -209,3 +209,40 @@ function skip_over_nested_constructs_2() { } }; } + +// Issue #1506 +function allow_for_compare_before_noncecheck() { + if ( + 'newsletter_sign_up' === $_POST['action'] && // OK. + wp_verify_nonce( $_POST['newsletter_nonce'] ) + ) {} +} + +// Issue #1114 +function allow_for_nonce_check_within_switch() { + if ( ! isset( $_REQUEST['action'] ) ) { + return; + } + + switch ( $_REQUEST['action'] ) { // OK. + case 'foo': + check_admin_referer( 'foo' ); + break; + case 'bar': + check_admin_referer( 'bar' ); + break; + } +} + +function allow_for_array_compare_before_noncecheck() { + if ( array_search( array( 'subscribe', 'unsubscribe', $_POST['action'], true ) // OK. + && wp_verify_nonce( $_POST['newsletter_nonce'] ) + ) {} +} + +function allow_for_array_comparison_in_condition() { + if ( in_array( $_GET['action'], $valid_actions, true ) ) { // OK. + check_admin_referer( 'foo' ); + foo(); + } +} From 2ac765f2b0ae653efef9f5dda74cd2324f3abe78 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 2 Apr 2019 10:04:51 +0200 Subject: [PATCH 148/241] ValidatedSanitizedInput: allow for more unslashing functions As correctly pointed out in https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/ 869#issuecomment-478329921 and confirmed via a trace-back of the functions used by `wp_unslash()`, WP contains two additional unslashing functions which are perfectly valid to use for unslashing received data. Refs: * https://developer.wordpress.org/reference/functions/wp_unslash/ * https://developer.wordpress.org/reference/functions/stripslashes_deep/ * https://developer.wordpress.org/reference/functions/stripslashes_from_strings_only/ This commit adds allowance for using these. It also updates the error message to reflect this. Includes unit tests. --- WordPress/Sniff.php | 38 +++++++++++++------ .../ValidatedSanitizedInputUnitTest.inc | 9 +++++ 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index c4b066e911..27441c89a3 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -315,6 +315,19 @@ abstract class Sniff implements PHPCS_Sniff { 'sizeof' => true, ); + /** + * Functions which unslash the data passed to them. + * + * @since 2.1.0 + * + * @var array + */ + protected $unslashingFunctions = array( + 'stripslashes_deep' => true, + 'stripslashes_from_strings_only' => true, + 'wp_unslash' => true, + ); + /** * List of PHP native functions to test the type of a variable. * @@ -1801,8 +1814,8 @@ protected function is_safe_casted( $stackPtr ) { * @since 0.5.0 * * @param int $stackPtr The index of the token in the stack. - * @param bool $require_unslash Whether to give an error if wp_unslash() isn't - * used on the variable before sanitization. + * @param bool $require_unslash Whether to give an error if no unslashing function + * is used on the variable before sanitization. * * @return bool Whether the token being sanitized. */ @@ -1833,10 +1846,10 @@ protected function is_sanitized( $stackPtr, $require_unslash = false ) { return true; } - $valid_functions = $this->sanitizingFunctions; - $valid_functions += $this->unslashingSanitizingFunctions; - $valid_functions += $this->arrayWalkingFunctions; - $valid_functions['wp_unslash'] = true; + $valid_functions = $this->sanitizingFunctions; + $valid_functions += $this->unslashingSanitizingFunctions; + $valid_functions += $this->unslashingFunctions; + $valid_functions += $this->arrayWalkingFunctions; $functionPtr = $this->is_in_function_call( $stackPtr, $valid_functions ); @@ -1851,12 +1864,15 @@ protected function is_sanitized( $stackPtr, $require_unslash = false ) { $functionName = $this->tokens[ $functionPtr ]['content']; - // Check if wp_unslash() is being used. - if ( 'wp_unslash' === $functionName ) { + // Check if an unslashing function is being used. + if ( isset( $this->unslashingFunctions[ $functionName ] ) ) { $is_unslashed = true; - unset( $valid_functions['wp_unslash'] ); + // Remove the unslashing functions. + $valid_functions = array_diff_key( $valid_functions, $this->unslashingFunctions ); + + // Check is any of the remaining (sanitizing) functions is used. $higherFunctionPtr = $this->is_in_function_call( $functionPtr, $valid_functions ); // If there is no other valid function being used, this value is unsanitized. @@ -1909,7 +1925,7 @@ protected function is_sanitized( $stackPtr, $require_unslash = false ) { } /** - * Add an error for missing use of wp_unslash(). + * Add an error for missing use of unslashing. * * @since 0.5.0 * @@ -1918,7 +1934,7 @@ protected function is_sanitized( $stackPtr, $require_unslash = false ) { public function add_unslash_error( $stackPtr ) { $this->phpcsFile->addError( - 'Missing wp_unslash() before sanitization.', + '%s data not unslashed before sanitization. Use wp_unslash() or similar', $stackPtr, 'MissingUnslash', array( $this->tokens[ $stackPtr ]['content'] ) diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc index 93ceaec2bb..46dad6254c 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc @@ -322,3 +322,12 @@ function test_null_coalesce_equals_validation() { $key = sanitize_text_field( wp_unslash( $_POST['key'] ) ); // OK, validated via null coalesce equals. $another_key = sanitize_text_field( wp_unslash( $_POST['another_key'] ) ); // Bad, not validated, different key. } + +function test_using_different_unslashing_functions() { + if ( ! isset( $_GET['test'] ) ) { + return; + } + + $sane = sanitize_text_field(stripslashes_deep($_GET['test'])); // Ok. + $sane = sanitize_text_field( stripslashes_from_strings_only( $_GET['test'] ) ); // OK. +} From bb646b6a30cff20535709f93f9640c2a39c8f739 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 1 Apr 2019 07:19:11 +0200 Subject: [PATCH 149/241] Sniff::has_nonce_check(): allow for unslashing a variable before nonce check This also gets rid of a bug were sanitization was not recognized as such if the call to `wp_unslash()` was nested inside it. Includes unit tests. Fixes 572 --- WordPress/Sniff.php | 1 + .../Security/NonceVerificationUnitTest.inc | 18 ++++++++++++++++++ .../Security/NonceVerificationUnitTest.php | 1 + 3 files changed, 20 insertions(+) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 27441c89a3..f868537201 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1455,6 +1455,7 @@ protected function has_nonce_check( $stackPtr ) { || $this->is_in_type_test( $stackPtr ) || $this->is_comparison( $stackPtr ) || $this->is_in_array_comparison( $stackPtr ) + || $this->is_in_function_call( $stackPtr, $this->unslashingFunctions ) !== false ) { $allow_nonce_after = true; } diff --git a/WordPress/Tests/Security/NonceVerificationUnitTest.inc b/WordPress/Tests/Security/NonceVerificationUnitTest.inc index cd5a7d4f92..b6e3e9aeef 100644 --- a/WordPress/Tests/Security/NonceVerificationUnitTest.inc +++ b/WordPress/Tests/Security/NonceVerificationUnitTest.inc @@ -246,3 +246,21 @@ function allow_for_array_comparison_in_condition() { foo(); } } + +# Issue #572. +function allow_for_unslash_before_noncecheck_but_demand_noncecheck() { + $var = wp_unslash( $_POST['foo'] ); // Bad. + echo $var; +} + +function allow_for_unslash_before_noncecheck() { + $var = stripslashes_from_strings_only( $_POST['foo'] ); // OK. + wp_verify_nonce( $var ); + echo $var; +} + +function allow_for_unslash_in_sanitization() { + $var = sanitize_text_field( wp_unslash( $_POST['foo'] ) ); // OK. + wp_verify_nonce( $var ); + echo $var; +} diff --git a/WordPress/Tests/Security/NonceVerificationUnitTest.php b/WordPress/Tests/Security/NonceVerificationUnitTest.php index 838e897a9b..5cd8813314 100644 --- a/WordPress/Tests/Security/NonceVerificationUnitTest.php +++ b/WordPress/Tests/Security/NonceVerificationUnitTest.php @@ -51,6 +51,7 @@ public function getErrorList() { 190 => 1, 198 => 1, 202 => 1, + 252 => 1, ); } From a8d8c6ce09f6def51e5de6d7944c37f0037d2bb7 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 31 Mar 2019 09:20:07 +0200 Subject: [PATCH 150/241] NonceVerification: bug fix - sanitization is no alternative for nonce check Any usage of superglobals in calls to sanitization functions were up to now ignored. As the output of sanitization is normally assigned to a names variable, this meant that it was possible to bypass the nonce verification sniff that way. I don't believe that was the intended behaviour. Instead IMO, a sanitization call should be allowed prior to the nonce verification, but should not negate the nonce verification check. This fixes that. Includes unit tests. --- WordPress/Sniff.php | 1 + WordPress/Sniffs/Security/NonceVerificationSniff.php | 4 ---- .../Tests/Security/NonceVerificationUnitTest.inc | 11 +++++++++++ .../Tests/Security/NonceVerificationUnitTest.php | 1 + 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index f868537201..07d88fbe81 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1456,6 +1456,7 @@ protected function has_nonce_check( $stackPtr ) { || $this->is_comparison( $stackPtr ) || $this->is_in_array_comparison( $stackPtr ) || $this->is_in_function_call( $stackPtr, $this->unslashingFunctions ) !== false + || $this->is_only_sanitized( $stackPtr ) ) { $allow_nonce_after = true; } diff --git a/WordPress/Sniffs/Security/NonceVerificationSniff.php b/WordPress/Sniffs/Security/NonceVerificationSniff.php index b29dcb1fa0..e9b2cf6603 100644 --- a/WordPress/Sniffs/Security/NonceVerificationSniff.php +++ b/WordPress/Sniffs/Security/NonceVerificationSniff.php @@ -121,10 +121,6 @@ public function process_token( $stackPtr ) { $this->mergeFunctionLists(); - if ( $this->is_only_sanitized( $stackPtr ) ) { - return; - } - if ( $this->has_nonce_check( $stackPtr ) ) { return; } diff --git a/WordPress/Tests/Security/NonceVerificationUnitTest.inc b/WordPress/Tests/Security/NonceVerificationUnitTest.inc index b6e3e9aeef..d02e6a7cb0 100644 --- a/WordPress/Tests/Security/NonceVerificationUnitTest.inc +++ b/WordPress/Tests/Security/NonceVerificationUnitTest.inc @@ -264,3 +264,14 @@ function allow_for_unslash_in_sanitization() { wp_verify_nonce( $var ); echo $var; } + +function dont_allow_bypass_nonce_via_sanitization() { + $var = sanitize_text_field( $_POST['foo'] ); // Bad. + echo $var; +} + +function dont_allow_bypass_nonce_via_sanitization() { + $var = sanitize_text_field( $_POST['foo'] ); // OK. + wp_verify_nonce( $var ); + echo $var; +} diff --git a/WordPress/Tests/Security/NonceVerificationUnitTest.php b/WordPress/Tests/Security/NonceVerificationUnitTest.php index 5cd8813314..964ab9501a 100644 --- a/WordPress/Tests/Security/NonceVerificationUnitTest.php +++ b/WordPress/Tests/Security/NonceVerificationUnitTest.php @@ -52,6 +52,7 @@ public function getErrorList() { 198 => 1, 202 => 1, 252 => 1, + 269 => 1, ); } From cce11ae5f02832367b2a0852ef864fc0223e6ecc Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 27 Mar 2019 01:17:08 +0100 Subject: [PATCH 151/241] Core: forbid assignments in conditions As per the proposal in https://make.wordpress.org/core/2019/03/26/coding-standards-updates-for-php-5-6/ Open actions: * [x] Adjust Core PHP handbook to mention this rule in the `Clever code` section --- WordPress-Core/ruleset.xml | 7 +++++++ WordPress-Extra/ruleset.xml | 6 ------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index 16edf427a6..e14d49b15f 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -392,6 +392,13 @@ + + + diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index 6ff9b6cf42..f62542455e 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -24,12 +24,6 @@
- - - From d6f9dc0bc74202f5f7bc901edaf15abcba82218e Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 27 Mar 2019 01:44:11 +0100 Subject: [PATCH 152/241] Core: warn against the use of loose comparisons As per the proposal in 1624, this moves the sniffs which `warn` against the use of loose comparisons to the Core ruleset. Open actions: * [x] Adjust Core PHP handbook to mention this rule in the `Clever code` section (or wherever else it should go). --- WordPress-Core/ruleset.xml | 5 +++++ WordPress-Extra/ruleset.xml | 9 --------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index e14d49b15f..9a3485b353 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -392,6 +392,11 @@ + + + + - - - - - - From 4d814b73729f78adef1e306c990b6e9f2e8f789b Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 3 Apr 2019 07:03:07 +0200 Subject: [PATCH 153/241] Changelog for WPCS 2.1.0 * Release date set at this Monday April 8th. * Includes all currently merged changes. * Includes a minor update to the Readme file for the DealerDirect Composer plugin version number. Related to 1628 (which is included in this release) --- CHANGELOG.md | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 2 +- 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96b8b726e9..fdfb7c265f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,81 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a _No documentation available about unreleased changes as of yet._ +## [2.1.0] - 2019-04-08 + +### Added +- New `WordPress.PHP.IniSet` sniff to the `WordPress-Extra` ruleset. + This sniff will detect calls to `ini_set()` and `ini_alter()` and warn against their use as changing configuration values at runtime leads to an unpredictable runtime environment, which can result in conflicts between core/plugins/themes. + - The sniff will not throw notices about a very limited set of "safe" ini directives. + - For a number of ini directives for which there are alternative, non-conflicting ways to achieve the same available, the sniff will throw an `error` and advise using the alternative. +- `doubleval()`, `count()` and `sizeof()` to the list of functions which unslash and sanitize `Sniff::$unslashingSanitizingFunctions`. + This affects the `WordPress.Security.ValidatedSanitizedInput` and the `WordPress.Security.NonceVerification` sniffs. +- The new WP 5.1 `WP_UnitTestCase_Base` class to the `Sniff::$test_class_whitelist` property. +- New `Sniff::get_array_access_keys()` utility method to retrieve all array keys for a variable using multi-level array access. +- New `Sniff::is_class_object_call()`, `Sniff::is_token_namespaced()` utility methods. + These should help make the checking of whether or not a function call is a global function, method call or a namespaced function call more consistent. + This also implements allowing for the [namespace keyword being used as an operator](https://www.php.net/manual/en/language.namespaces.nsconstants.php#example-258). +- New `Sniff::is_in_function_call()` utility method to facilitate checking whether a token is (part of) a parameter passed to a specific (set of) function(s). +- New `Sniff::is_in_type_test()` utility method to determine if a variable is being type tested, along with a `Sniff::$typeTestFunctions` property containing the names of the functions this applies to. +- New `Sniff::is_in_array_comparison()` utility method to determine if a variable is (part of) a parameter in an array-value comparison, along with a `Sniff::$arrayCompareFunctions` property containing the names of the relevant functions. +- New `Sniff::$arrayWalkingFunctions` property containing the names of array functions which apply a callback to the array, but don't change the array by reference. +- New `Sniff::$unslashingFunctions` property containing the names of functions which unslash data passed to them and return the unslashed result. + +### Changed +- Moved the `WordPress.PHP.StrictComparisons`, `WordPress.PHP.StrictInArray` and the `WordPress.CodeAnalysis.AssignmentInCondition` sniff from the `WordPress-Extra` to the `WordPress-Core` ruleset. +- The `Squiz.Commenting.InlineComment.SpacingAfter` error is no longer included in the `WordPress-Docs` ruleset. +- The default value for `minimum_supported_wp_version`, as used by a [number of sniffs detecting usage of deprecated WP features](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#minimum-wp-version-to-check-for-usage-of-deprecated-functions-classes-and-function-parameters), has been updated to `4.8`. +- The `WordPress.WP.DeprecatedFunctions` sniff will now detect functions deprecated in WP 5.1. +- The `WordPress.Security.NonceVerification` sniff now allows for variable type testing, comparisons, unslashing and sanitization before the nonce check. A nonce check within the same scope, however, is still required. +- The `WordPress.Security.ValidatedSanitizedInput` sniff now allows for using a superglobal in an array-value comparison without sanitization, same as when the superglobal is used in a scalar value comparison. +- `WordPress.NamingConventions.PrefixAllGlobals`: some of the error messages have been made more explicit. +- The error messages for the `WordPress.Security.ValidatedSanitizedInput` sniff will now contain information on the index keys accessed. +- The error message for the `WordPress.Security.ValidatedSanitizedInput.InputNotValidated` has been reworded to make it more obvious what the actual issue being reported is. +- The error message for the `WordPress.Security.ValidatedSanitizedInput.MissingUnslash` has been reworded. +- The `Sniff::is_comparison()` method now has a new `$include_coalesce` parameter to allow for toggling whether the null coalesce operator should be seen as a comparison operator. Defaults to `true`. +- All sniffs are now also being tested against PHP 7.4 (unstable) for consistent sniff results. +- The recommended version of the suggested DealerDirect PHPCS Composer plugin is now `^0.5.0`. +- Various minor code tweaks and clean up. + +### Removed +- `ini_set` and `ini_alter` from the list of functions detected by the `WordPress.PHP.DiscouragedFunctions` sniff. + These are now covered via the new `WordPress.PHP.IniSet` sniff. +- `in_array()` and `array_key_exists()` from the list of `Sniff::$sanitizingFunctions`. These are now handled differently. + +### Fixed +- The `WordPress.NamingConventions.PrefixAllGlobals` sniff would underreport when global functions would be autoloaded via a Composer autoload `files` configuration. +- The `WordPress.Security.EscapeOutput` sniff will now recognize `map_deep()` for escaping the values in an array via a callback to an output escaping function. This should prevent false positives. +- The `WordPress.Security.NonceVerification` sniff will no longer inadvertently allow for a variable to be sanitized without a nonce check within the same scope. +- The `WordPress.Security.ValidatedSanitizedInput` sniff will no longer throw errors when a variable is only being type tested. +- The `WordPress.Security.ValidatedSanitizedInput` sniff will now correctly recognize the null coalesce (PHP 7.0) and null coalesce equal (PHP 7.4) operators and will now throw errors for missing unslashing and sanitization where relevant. +- The `WordPress.WP.AlternativeFunctions` sniff will no longer recommend using the WP_FileSystem when PHP native input streams, like `php://input`, or the PHP input stream constants are being read or written to. +- The `WordPress.WP.AlternativeFunctions` sniff will no longer report on usage of the `curl_version()` function. +- The `WordPress.WP.CronInterval` sniff now has improved function recognition which should lower the chance of false positives. +- The `WordPress.WP.EnqueuedResources` sniff will no longer throw false positives for inline jQuery code trying to access a stylesheet link tag. +- Various bugfixes for the `Sniff::has_nonce_check()` method: + - The method will no longer incorrectly identify methods/namespaced functions mirroring the name of WP native nonce verification functions as if they were the global functions. + This will prevent some false negatives. + - The method will now skip over nested closed scopes, such as closures and anonymous classes. This should prevent some false negatives for nonce verification being done while not in the correct scope. + + These fixes affect the `WordPress.Security.NonceVerification` sniff. +- The `Sniff::is_in_isset_or_empty()` method now also checks for usage of `array_key_exist()` and `key_exists()` and will regard these as correct ways to validate a variable. + This should prevent false positives for the `WordPress.Security.ValidatedSanitizedInput` and the `WordPress.Security.NonceVerification` sniffs. +- Various bugfixes for the `Sniff::is_sanitized()` method: + - The method presumed the WordPress coding style regarding code layout, which could lead to false positives. + - The method will no longer incorrectly identify methods/namespaced functions mirroring the name of WP/PHP native unslashing/sanitization functions as if they were the global functions. + This will prevent some false negatives. + - The method will now recognize `map_deep()` for sanitizing an array via a callback to a sanitization function. This should prevent false positives. + - The method will now recognize `stripslashes_deep()` and `stripslashes_from_strings_only()` as valid unslashing functions. This should prevent false positives. + All these fixes affect both the `WordPress.Security.ValidatedSanitizedInput` and the `WordPress.Security.NonceVerification` sniff. +- Various bugfixes for the `Sniff::is_validated()` method: + - The method did not verify correctly whether a variable being validated was the same variable as later used which could lead to false negatives. + - The method did not verify correctly whether a variable being validated had the same array index keys as the variable as later used which could lead to both false negatives as well as false positives. + - The method now also checks for usage of `array_key_exist()` and `key_exists()` and will regard these as correct ways to validate a variable. This should prevent some false positives. + - The methods will now recognize the null coalesce and the null coalesce equal operators as ways to validate a variable. This prevents some false positives. + The results from the `WordPress.Security.ValidatedSanitizedInput` sniff should be more accurate because of these fixes. +- A potential "Undefined index" notice from the `Sniff::is_assignment()` method. + + ## [2.0.0] - 2019-01-16 ### Important information about this release: @@ -994,6 +1069,7 @@ See the comparison for full list. Initial tagged release. [Unreleased]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/master...HEAD +[2.1.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/2.0.0...2.1.0 [2.0.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/2.0.0-RC1...2.0.0 [2.0.0-RC1]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.2.1...2.0.0-RC1 [1.2.1]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.2.0...1.2.1 diff --git a/README.md b/README.md index b2662a15e1..17c4a52dc4 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ When installing the WordPress Coding Standards as a dependency in a larger proje There are two actively maintained Composer plugins which can handle the registration of standards with PHP_CodeSniffer for you: * [composer-phpcodesniffer-standards-plugin](https://github.com/higidi/composer-phpcodesniffer-standards-plugin) -* [phpcodesniffer-composer-installer](https://github.com/DealerDirect/phpcodesniffer-composer-installer):"^0.4.3" +* [phpcodesniffer-composer-installer](https://github.com/DealerDirect/phpcodesniffer-composer-installer):"^0.5.0" It is strongly suggested to `require` one of these plugins in your project to handle the registration of external standards with PHPCS for you. From f4b82aea6c3ac845fb1f437e569a2ed9fb096d23 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 3 Apr 2019 21:48:49 +0200 Subject: [PATCH 154/241] Changelog: clarified the addition of the `count()` and `sizeof()` functions --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdfb7c265f..6a5e83627a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,8 @@ _No documentation available about unreleased changes as of yet._ This sniff will detect calls to `ini_set()` and `ini_alter()` and warn against their use as changing configuration values at runtime leads to an unpredictable runtime environment, which can result in conflicts between core/plugins/themes. - The sniff will not throw notices about a very limited set of "safe" ini directives. - For a number of ini directives for which there are alternative, non-conflicting ways to achieve the same available, the sniff will throw an `error` and advise using the alternative. -- `doubleval()`, `count()` and `sizeof()` to the list of functions which unslash and sanitize `Sniff::$unslashingSanitizingFunctions`. +- `doubleval()`, `count()` and `sizeof()` to `Sniff::$unslashingSanitizingFunctions` property. + While `count()` and its alias `sizeof()`, don't actually unslash or sanitize, the output of these functions is safe to use without unslashing or sanitizing. This affects the `WordPress.Security.ValidatedSanitizedInput` and the `WordPress.Security.NonceVerification` sniffs. - The new WP 5.1 `WP_UnitTestCase_Base` class to the `Sniff::$test_class_whitelist` property. - New `Sniff::get_array_access_keys()` utility method to retrieve all array keys for a variable using multi-level array access. From 7e6f1dd7a1a7a6d4aaba7e0adc35d050de3496a3 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Sat, 20 Apr 2019 22:28:58 +0200 Subject: [PATCH 155/241] Add missing WP global variable `$current_blog` I encountered a missing global variable called `$current_blog`. It is used for Multisite installations and referes to the current site, just as `$current_site` (which is included in the list) refers to the current network. --- WordPress/Sniff.php | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 07d88fbe81..1ea5d563b2 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -638,6 +638,7 @@ abstract class Sniff implements PHPCS_Sniff { 'compress_css' => true, 'compress_scripts' => true, 'concatenate_scripts' => true, + 'current_blog' => true, 'current_screen' => true, 'current_site' => true, 'current_user' => true, From 1dec52a1c876576dac775816a8e7780044ad52d1 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 23 Apr 2019 14:24:20 +0200 Subject: [PATCH 156/241] NonceVerification: improve handling of nested functions The `Sniff::has_nonce_verification()` method would determine the scope within which to look for a nonce verification function based on the first function condition of the `$stackPtr` being examined. This breaks when closures/functions are nested within other functions, as the code within those nested constructs will be ignored, while instead, that should be the code which should be examined. By changing the start point of the scope within which the method looks for nonce verification functions to the deepest nested function, this use-case is handled correctly. Note that PHPCS 3.5.0 is expected to contain a utility function which can largely replace the code which was now added. Once PHPCS 3.5.0 has been released and WPCS ups it's minimum version requirement, this change should be made. Fixes 1694 --- WordPress/Sniff.php | 16 ++++++----- .../Security/NonceVerificationUnitTest.inc | 28 ++++++++++++++++++- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 1ea5d563b2..a69ffba8b1 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1441,13 +1441,15 @@ protected function has_nonce_check( $stackPtr ) { $tokens = $this->phpcsFile->getTokens(); // If we're in a function, only look inside of it. - $f = $this->phpcsFile->getCondition( $stackPtr, \T_FUNCTION ); - if ( false !== $f ) { - $start = $tokens[ $f ]['scope_opener']; - } else { - $f = $this->phpcsFile->getCondition( $stackPtr, \T_CLOSURE ); - if ( false !== $f ) { - $start = $tokens[ $f ]['scope_opener']; + // Once PHPCS 3.5.0 comes out this should be changed to the new Conditions::GetLastCondition() method. + if ( isset( $tokens[ $stackPtr ]['conditions'] ) === true ) { + $conditions = $tokens[ $stackPtr ]['conditions']; + $conditions = array_reverse( $conditions, true ); + foreach ( $conditions as $tokenPtr => $condition ) { + if ( \T_FUNCTION === $condition || \T_CLOSURE === $condition ) { + $start = $tokens[ $tokenPtr ]['scope_opener']; + break; + } } } diff --git a/WordPress/Tests/Security/NonceVerificationUnitTest.inc b/WordPress/Tests/Security/NonceVerificationUnitTest.inc index d02e6a7cb0..41cf566594 100644 --- a/WordPress/Tests/Security/NonceVerificationUnitTest.inc +++ b/WordPress/Tests/Security/NonceVerificationUnitTest.inc @@ -247,7 +247,7 @@ function allow_for_array_comparison_in_condition() { } } -# Issue #572. +// Issue #572. function allow_for_unslash_before_noncecheck_but_demand_noncecheck() { $var = wp_unslash( $_POST['foo'] ); // Bad. echo $var; @@ -275,3 +275,29 @@ function dont_allow_bypass_nonce_via_sanitization() { wp_verify_nonce( $var ); echo $var; } + +// Issue #1694 +function function_containing_nested_class() { + if ( !class_exists( 'Nested_Class' ) ) { + class Nested_Class extends Something { + public function method_in_nested_class() { + if ( isset( $_POST['my_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['my_nonce'] ) ), 'the_nonce' ) ) { + if ( isset( $_POST['hello'] ) ) { + echo 'world'; + } + } + } + } + } +} + +function function_containing_nested_closure() { + $closure = function() { + if ( isset( $_POST['my_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['my_nonce'] ) ), 'the_nonce' ) ) { + if ( isset( $_POST['hello'] ) ) { + echo 'world'; + } + } + }; +} + From 2f4a53d007d9101b4f585500f4a960e3e2f8e4a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Demarle?= Date: Sun, 5 May 2019 17:27:27 +0200 Subject: [PATCH 157/241] Accept tag_ID as variable name --- WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index 0b9422796a..cb0c04d0be 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -51,6 +51,7 @@ class ValidVariableNameSniff extends PHPCS_AbstractVariableSniff { 'PHP_SELF' => true, 'post_ID' => true, 'user_ID' => true, + 'tag_ID' => true, ); /** From 1698284940c73448f8e317a0af0a88468ccc5976 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 6 May 2019 01:14:14 +0200 Subject: [PATCH 158/241] CapitalPDangit: ignore misspellings in constant declarations Just like in array declarations, when `wordpress` is spelled incorrectly in constant declarations, this will be a false positive in 90% of the cases, so just ignore it. Fixes 1698 --- WordPress/Sniffs/WP/CapitalPDangitSniff.php | 18 ++++++++++++++++++ WordPress/Tests/WP/CapitalPDangitUnitTest.inc | 8 ++++++++ .../Tests/WP/CapitalPDangitUnitTest.inc.fixed | 8 ++++++++ 3 files changed, 34 insertions(+) diff --git a/WordPress/Sniffs/WP/CapitalPDangitSniff.php b/WordPress/Sniffs/WP/CapitalPDangitSniff.php index 908e5d6cc8..3c270154a1 100644 --- a/WordPress/Sniffs/WP/CapitalPDangitSniff.php +++ b/WordPress/Sniffs/WP/CapitalPDangitSniff.php @@ -188,6 +188,24 @@ public function process_token( $stackPtr ) { } } + // Ignore constant declarations via define(). + if ( $this->is_in_function_call( $stackPtr, array( 'define' => true ), true, true ) ) { + return; + } + + // Ignore constant declarations using the const keyword. + $stop_points = array( + \T_CONST, + \T_SEMICOLON, + \T_OPEN_TAG, + \T_CLOSE_TAG, + \T_OPEN_CURLY_BRACKET, + ); + $maybe_const = $this->phpcsFile->findPrevious( $stop_points, ( $stackPtr - 1 ) ); + if ( false !== $maybe_const && \T_CONST === $this->tokens[ $maybe_const ]['code'] ) { + return; + } + $content = $this->tokens[ $stackPtr ]['content']; if ( preg_match_all( self::WP_REGEX, $content, $matches, ( \PREG_PATTERN_ORDER | \PREG_OFFSET_CAPTURE ) ) > 0 ) { diff --git a/WordPress/Tests/WP/CapitalPDangitUnitTest.inc b/WordPress/Tests/WP/CapitalPDangitUnitTest.inc index 20783f50e9..33622aa88c 100644 --- a/WordPress/Tests/WP/CapitalPDangitUnitTest.inc +++ b/WordPress/Tests/WP/CapitalPDangitUnitTest.inc @@ -180,3 +180,11 @@ wordpress.pot $text = <<<'EOD' This is an explanation about word-press. EOD; + +// Issue 1698 - ignore constant declarations. +define( 'WORDPRESS_SOMETHING', 'wordpress' ); // OK. +class TestMe { + public const MY_CONST = 123, + ANOTHER => array( 'a' => 'b' ), + WORDPRESS_SOMETHING = 'wordpress'; // OK (complex declaration to make sure start of statement is detected correctly). +} diff --git a/WordPress/Tests/WP/CapitalPDangitUnitTest.inc.fixed b/WordPress/Tests/WP/CapitalPDangitUnitTest.inc.fixed index 7dcc166678..7dc636aa88 100644 --- a/WordPress/Tests/WP/CapitalPDangitUnitTest.inc.fixed +++ b/WordPress/Tests/WP/CapitalPDangitUnitTest.inc.fixed @@ -180,3 +180,11 @@ wordpress.pot $text = <<<'EOD' This is an explanation about WordPress. EOD; + +// Issue 1698 - ignore constant declarations. +define( 'WORDPRESS_SOMETHING', 'wordpress' ); // OK. +class TestMe { + public const MY_CONST = 123, + ANOTHER => array( 'a' => 'b' ), + WORDPRESS_SOMETHING = 'wordpress'; // OK (complex declaration to make sure start of statement is detected correctly). +} From 423ed658d7fa027c7740b698cdaa90a2407c442a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Demarle?= Date: Mon, 6 May 2019 21:42:40 +0200 Subject: [PATCH 159/241] Add tag_ID to the list of global variables And restore the alphabetical order in the list of valid variable names. --- WordPress/Sniff.php | 1 + WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index a69ffba8b1..7e798320fe 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -741,6 +741,7 @@ abstract class Sniff implements PHPCS_Sniff { 'table_prefix' => true, 'tabs' => true, 'tag' => true, + 'tag_ID' => true, 'targets' => true, 'tax' => true, 'taxnow' => true, diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index cb0c04d0be..dad06cac71 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -50,8 +50,8 @@ class ValidVariableNameSniff extends PHPCS_AbstractVariableSniff { 'is_winIE' => true, 'PHP_SELF' => true, 'post_ID' => true, - 'user_ID' => true, 'tag_ID' => true, + 'user_ID' => true, ); /** From 85c1a10829e6d9288c7bb6cd28a219748a3bb9f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=BDoljom?= Date: Tue, 7 May 2019 15:18:20 +0200 Subject: [PATCH 160/241] Remove paginate_comments_links from escaped functions list --- WordPress/Sniff.php | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 7e798320fe..1e45252e9e 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -202,7 +202,6 @@ abstract class Sniff implements PHPCS_Sniff { 'get_the_ID' => true, 'get_the_post_thumbnail' => true, 'get_the_term_list' => true, - 'paginate_comments_links' => true, 'post_type_archive_title' => true, 'readonly' => true, 'selected' => true, From 79b68552a94e618525856585f73d837de26aaf32 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 17 May 2019 06:58:15 +0200 Subject: [PATCH 161/241] Sniff::is_test_class(): recognize `TestCase` What with WP dropping support for PHP 5.2, I expect that more and more projects will start to use `use` statements in their code. When the PHPUnit native `PHPUnit\Framework\TestCase` is imported via a `use` statement and then `extend`ed, the WPCS sniffs would not recognize the extending class as a test class. Adding `TestCase` to the default test class whitelist fixes this. While this means that any class extending the quite genericly named `TestCase` will now be recognized as a test class, even when the `TestCase` in question is not the PHPUnit native one, I think it's safe to assume that even when it's not the PHPUnit native one, it _will_ be a test base class and for WPCS purposes the extending class can be marked as a test class. Includes unit test via the `GlobalVariablesOverride` sniff. Includes adjusting an existing unit test for the `FileName` sniff to still test what it was testing before. --- WordPress/Sniff.php | 2 ++ .../TestFiles/test-sample-namespaced-extends.4.inc | 2 +- .../Tests/WP/GlobalVariablesOverrideUnitTest.5.inc | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.5.inc diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 1e45252e9e..23a2a3aaa1 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -861,6 +861,8 @@ abstract class Sniff implements PHPCS_Sniff { 'WP_XMLRPC_UnitTestCase' => true, 'PHPUnit_Framework_TestCase' => true, 'PHPUnit\Framework\TestCase' => true, + // PHPUnit native TestCase class when imported via use statement. + 'TestCase' => true, ); /** diff --git a/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends.4.inc b/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends.4.inc index 0f494371b1..7d17da83b9 100644 --- a/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends.4.inc +++ b/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends.4.inc @@ -2,5 +2,5 @@ phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] Some\Name\TestSample Date: Sat, 18 May 2019 17:13:29 +0200 Subject: [PATCH 162/241] Update default minimum_supported_version to WP 4.9 The minimum version should be three versions behind the latest WP release, so what with 5.2 being out, it should now be 4.9. Includes (not) updating the list of deprecated functions. Input for this based on @JDGrimes's WP deprecated code scanner. --- WordPress/Sniff.php | 2 +- WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc | 4 ++-- WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php | 9 +++++---- WordPress/Tests/WP/DeprecatedParametersUnitTest.inc | 5 ++--- WordPress/Tests/WP/DeprecatedParametersUnitTest.php | 8 +++----- phpcs.xml.dist.sample | 2 +- 6 files changed, 14 insertions(+), 16 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 23a2a3aaa1..1d5edc4e28 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -82,7 +82,7 @@ abstract class Sniff implements PHPCS_Sniff { * * @var string WordPress version. */ - public $minimum_supported_version = '4.8'; + public $minimum_supported_version = '4.9'; /** * Custom list of classes which test classes can extend. diff --git a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc index eb0822692e..6a41db6cc6 100644 --- a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc +++ b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc @@ -327,12 +327,12 @@ _usort_terms_by_name(); get_paged_template(); wp_get_network(); wp_kses_js_entities(); +/* ============ WP 4.8 ============ */ +wp_dashboard_plugins_output(); /* * Warning. */ -/* ============ WP 4.8 ============ */ -wp_dashboard_plugins_output(); /* ============ WP 4.9 ============ */ get_shortcut_link(); is_user_option_local(); diff --git a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php index c14a79c9bd..ba45e47476 100644 --- a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php @@ -28,7 +28,7 @@ class DeprecatedFunctionsUnitTest extends AbstractSniffUnitTest { */ public function getErrorList() { - $errors = array_fill( 8, 322, 1 ); + $errors = array_fill( 8, 324, 1 ); // Unset the lines related to version comments. unset( @@ -61,7 +61,8 @@ public function getErrorList() { $errors[304], $errors[311], $errors[319], - $errors[323] + $errors[323], + $errors[330] ); return $errors; @@ -74,10 +75,10 @@ public function getErrorList() { */ public function getWarningList() { - $warnings = array_fill( 335, 9, 1 ); + $warnings = array_fill( 337, 7, 1 ); // Unset the lines related to version comments. - unset( $warnings[336], $warnings[341] ); + unset( $warnings[341] ); return $warnings; } diff --git a/WordPress/Tests/WP/DeprecatedParametersUnitTest.inc b/WordPress/Tests/WP/DeprecatedParametersUnitTest.inc index 8022d59bc5..3ada338c90 100644 --- a/WordPress/Tests/WP/DeprecatedParametersUnitTest.inc +++ b/WordPress/Tests/WP/DeprecatedParametersUnitTest.inc @@ -34,6 +34,7 @@ comments_link( 'deprecated', 'deprecated' ); comments_number( '', '', '', 'deprecated' ); convert_chars( '', 'deprecated' ); discover_pingback_server_uri( '', 'deprecated' ); +get_category_parents( '', '', '', '', array( 'deprecated') ); get_delete_post_link( '', 'deprecated' ); get_last_updated( 'deprecated' ); get_the_author( 'deprecated' ); @@ -61,6 +62,4 @@ wp_title_rss( 'deprecated' ); wp_upload_bits( '', 'deprecated' ); xfn_check( '', '', 'deprecated' ); -// All will give an WARNING as they have been deprecated after WP 4.8. - -get_category_parents( '', '', '', '', array( 'deprecated') ); +// All will give an WARNING as they have been deprecated after WP 4.9. diff --git a/WordPress/Tests/WP/DeprecatedParametersUnitTest.php b/WordPress/Tests/WP/DeprecatedParametersUnitTest.php index 77d4d87e88..af86abf2e5 100644 --- a/WordPress/Tests/WP/DeprecatedParametersUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedParametersUnitTest.php @@ -27,7 +27,7 @@ class DeprecatedParametersUnitTest extends AbstractSniffUnitTest { * @return array => */ public function getErrorList() { - $errors = array_fill( 28, 35, 1 ); + $errors = array_fill( 28, 36, 1 ); $errors[22] = 1; $errors[23] = 1; @@ -35,7 +35,7 @@ public function getErrorList() { // Override number of errors. $errors[33] = 2; - $errors[47] = 2; + $errors[48] = 2; return $errors; } @@ -46,9 +46,7 @@ public function getErrorList() { * @return array => */ public function getWarningList() { - return array( - 66 => 1, - ); + return array(); } } diff --git a/phpcs.xml.dist.sample b/phpcs.xml.dist.sample index ffe70c7f1a..e6e2ab99f6 100644 --- a/phpcs.xml.dist.sample +++ b/phpcs.xml.dist.sample @@ -70,7 +70,7 @@ the wiki: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties --> - + From 97d6fbf1e95215140cf54e229bbfb341b9bd72c4 Mon Sep 17 00:00:00 2001 From: Juliette <663378+jrfnl@users.noreply.github.com> Date: Tue, 21 May 2019 04:27:46 +0200 Subject: [PATCH 163/241] Changelog for WPCS 2.1.1 (#1707) Changelog for WPCS 2.1.1 * Release date set at this **Tuesday May 21st**. * Includes all currently merged changes. --- CHANGELOG.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a5e83627a..a777dc0905 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,27 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a _No documentation available about unreleased changes as of yet._ + +## [2.1.1] - 2019-05-21 + +### Changed +- The `WordPress.WP.CapitalPDangit` will now ignore misspelled instances of `WordPress` within constant declarations. + This covers both constants declared using `defined()` as well as constants declared using the `const` keyword. +- The default value for `minimum_supported_wp_version`, as used by a [number of sniffs detecting usage of deprecated WP features](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#minimum-wp-version-to-check-for-usage-of-deprecated-functions-classes-and-function-parameters), has been updated to `4.9`. + +### Removed +- `paginate_comments_links()` from the list of auto-escaped functions `Sniff::$autoEscapedFunctions`. + This affects the `WordPress.Security.EscapeOutput` sniff. + +### Fixed +- The `$current_blog` and `$tag_ID` variables have been added to the list of WordPress global variables. + This fixes some false positives from the `WordPress.NamingConventions.PrefixAllGlobals` and the `WordPress.WP.GlobalVariablesOverride` sniffs. +- The generic `TestCase` class name has been added to the `$test_class_whitelist`. + This fixes some false positives from the `WordPress.NamingConventions.FileName`, `WordPress.NamingConventions.PrefixAllGlobals` and the `WordPress.WP.GlobalVariablesOverride` sniffs. +- The `WordPress.NamingConventions.ValidVariableName` sniff will now correctly recognize `$tag_ID` as a WordPress native, mixed-case variable. +- The `WordPress.Security.NonceVerification` sniff will now correctly recognize nonce verification within a nested closure or anonymous class. + + ## [2.1.0] - 2019-04-08 ### Added @@ -1070,6 +1091,7 @@ See the comparison for full list. Initial tagged release. [Unreleased]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/master...HEAD +[2.1.1]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/2.1.0...2.1.1 [2.1.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/2.0.0...2.1.0 [2.0.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/2.0.0-RC1...2.0.0 [2.0.0-RC1]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.2.1...2.0.0-RC1 From 0c7aff07ad0a2064588c9e6255bb86dcfb2a5089 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 22 May 2019 10:59:21 +0200 Subject: [PATCH 164/241] Travis: run the code style related and ruleset checks in separate stages Travis now offers stages. Using stages we can: - Run the code style related checks before running any unit tests and stop the build early if any are detected. - Remove the duplicate unit test runs - i.e. previously we had an extra (third) build against PHP 7.2 (now changed to 7.3) which would run the code style related checks, but would also re-run the unit tests. This extra build will now no longer run the unit tests. While this does mean that the unit tests will run with a slight delay (the `Sniff` and `Rulesets` stages have to finish before they start), it also means that we: * Get code style errors reported earlier as it's been moved to be the first stage and the build will just stop if any are found. * We won't be wasting Travis's resources on builds which will have to be re-run anyway. Ref: https://docs.travis-ci.com/user/build-stages/ Note that `Allowed failures` is no longer listed as a separate block in the Travis result overview, but is _is_ respected. For more discussion about this: * https://github.com/travis-ci/travis-ci/issues/7789 * https://travis-ci.community/t/always-show-allow-failures-allowed-failures-when-build-stages-are-used/217 * https://travis-ci.community/t/work-out-kinks-in-interactions-between-stages-allow-fail-and-fast-finish/1090 * https://github.com/travis-ci/travis-ci/issues/9677 --- .travis.yml | 114 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 70 insertions(+), 44 deletions(-) diff --git a/.travis.yml b/.travis.yml index bb60dd86aa..93399c75b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,16 +27,67 @@ env: # Lowest supported release in the 3.x series with which WPCS is compatible. - PHPCS_BRANCH="3.3.1" -matrix: +stages: + - sniff + - rulesets + - test + +jobs: fast_finish: true include: - # Run PHPCS against WPCS. I just picked to run it against 7.2. - - php: 7.2 - env: PHPCS_BRANCH="dev-master" SNIFF=1 + - stage: sniff + php: 7.3 + env: PHPCS_BRANCH="dev-master" addons: apt: packages: - libxml2-utils + script: + # WordPress Coding Standards. + # @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + # @link http://pear.php.net/package/PHP_CodeSniffer/ + - $(pwd)/vendor/bin/phpcs --runtime-set ignore_warnings_on_exit 1 + + # Validate the xml files. + # @link http://xmlsoft.org/xmllint.html + # For the build to properly error when validating against a scheme, these each have to be in their own condition. + - xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./*/ruleset.xml + - xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./phpcs.xml.dist.sample + + # Check the code-style consistency of the xml files. + - diff -B --tabsize=4 ./WordPress/ruleset.xml <(xmllint --format "./WordPress/ruleset.xml") + - diff -B --tabsize=4 ./WordPress-Core/ruleset.xml <(xmllint --format "./WordPress-Core/ruleset.xml") + - diff -B --tabsize=4 ./WordPress-Docs/ruleset.xml <(xmllint --format "./WordPress-Docs/ruleset.xml") + - diff -B --tabsize=4 ./WordPress-Extra/ruleset.xml <(xmllint --format "./WordPress-Extra/ruleset.xml") + - diff -B --tabsize=4 ./phpcs.xml.dist.sample <(xmllint --format "./phpcs.xml.dist.sample") + + # Make sure the rulesets don't thrown unexpected errors or warnings. + # This check needs to be run against a high PHP version to prevent triggering the syntax error check. + # It also needs to be run against all PHPCS versions WPCS is tested against. + - stage: rulesets + php: 7.3 + env: PHPCS_BRANCH="dev-master" + script: + - $(pwd)/vendor/bin/phpcs -ps ./bin/class-ruleset-test.php --standard=WordPress-Core + - $(pwd)/vendor/bin/phpcs -ps ./bin/class-ruleset-test.php --standard=WordPress-Docs + - $(pwd)/vendor/bin/phpcs -ps ./bin/class-ruleset-test.php --standard=WordPress-Extra + - $(pwd)/vendor/bin/phpcs -ps ./bin/class-ruleset-test.php --standard=WordPress + + # Test for fixer conflicts by running the auto-fixers of the complete WPCS over the test case files. + # This is not an exhaustive test, but should give an early indication for typical fixer conflicts. + # For the first run, the exit code will be 1 (= all fixable errors fixed). + # `travis_retry` should then kick in to run the fixer again which should now return 0 (= no fixable errors found). + # All error codes for the PHPCBF: https://github.com/squizlabs/PHP_CodeSniffer/issues/1270#issuecomment-272768413 + - travis_retry $(pwd)/vendor/bin/phpcbf -pq ./WordPress/Tests/ --standard=WordPress --extensions=inc --exclude=Generic.PHP.Syntax --report=summary + + - stage: rulesets + php: 7.3 + env: PHPCS_BRANCH="3.3.1" + script: + - $(pwd)/vendor/bin/phpcs -ps ./bin/class-ruleset-test.php --standard=WordPress-Core + - $(pwd)/vendor/bin/phpcs -ps ./bin/class-ruleset-test.php --standard=WordPress-Docs + - $(pwd)/vendor/bin/phpcs -ps ./bin/class-ruleset-test.php --standard=WordPress-Extra + - $(pwd)/vendor/bin/phpcs -ps ./bin/class-ruleset-test.php --standard=WordPress allow_failures: # Allow failures for unstable builds. @@ -51,7 +102,7 @@ before_install: - export PHPUNIT_DIR=/tmp/phpunit - composer require squizlabs/php_codesniffer:${PHPCS_BRANCH} --update-no-dev --no-suggest --no-scripts - | - if [[ "$SNIFF" == "1" ]]; then + if [[ "$TRAVIS_BUILD_STAGE_NAME" == "Sniff" ]]; then composer install --dev --no-suggest # The `dev` required DealerDirect Composer plugin takes care of the installed_paths. else @@ -63,42 +114,17 @@ before_install: - if [[ ${TRAVIS_PHP_VERSION:0:3} > "7.1" ]]; then wget -P $PHPUNIT_DIR https://phar.phpunit.de/phpunit-7.phar && chmod +x $PHPUNIT_DIR/phpunit-7.phar; fi script: - # Lint the PHP files against parse errors. - - if [[ "$LINT" == "1" ]]; then if find . -path ./vendor -prune -o -path ./bin -prune -o -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi; fi - # Run the unit tests. - - | - if [[ ${TRAVIS_PHP_VERSION:0:3} > "7.1" ]]; then - php $PHPUNIT_DIR/phpunit-7.phar --filter WordPress --bootstrap="$(pwd)/vendor/squizlabs/php_codesniffer/tests/bootstrap.php" $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php - else - phpunit --filter WordPress --bootstrap="$(pwd)/vendor/squizlabs/php_codesniffer/tests/bootstrap.php" $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php - fi - # Test for fixer conflicts by running the auto-fixers of the complete WPCS over the test case files. - # This is not an exhaustive test, but should give an early indication for typical fixer conflicts. - # For the first run, the exit code will be 1 (= all fixable errors fixed). - # `travis_retry` should then kick in to run the fixer again which should now return 0 (= no fixable errors found). - # All error codes for the PHPCBF: https://github.com/squizlabs/PHP_CodeSniffer/issues/1270#issuecomment-272768413 - - if [[ "$SNIFF" == "1" ]]; then travis_retry $(pwd)/vendor/bin/phpcbf -p ./WordPress/Tests/ --standard=WordPress --extensions=inc --exclude=Generic.PHP.Syntax --report=summary; fi - # Make sure the rulesets don't thrown unexpected errors or warnings. - # This check needs to be run against a high PHP version to prevent triggering the syntax error check. - # It also needs to be run against all PHPCS versions WPCS is tested against. - - if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress-Core; fi - - if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress-Docs; fi - - if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress-Extra; fi - - if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress; fi - # WordPress Coding Standards. - # @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards - # @link http://pear.php.net/package/PHP_CodeSniffer/ - - if [[ "$SNIFF" == "1" ]]; then $(pwd)/vendor/bin/phpcs --runtime-set ignore_warnings_on_exit 1; fi - # Validate the xml files. - # @link http://xmlsoft.org/xmllint.html - - if [[ "$SNIFF" == "1" ]]; then xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./*/ruleset.xml; fi - - if [[ "$SNIFF" == "1" ]]; then xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./phpcs.xml.dist.sample; fi - # Check the code-style consistency of the xml files. - - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress/ruleset.xml <(xmllint --format "./WordPress/ruleset.xml"); fi - - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-Core/ruleset.xml <(xmllint --format "./WordPress-Core/ruleset.xml"); fi - - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-Docs/ruleset.xml <(xmllint --format "./WordPress-Docs/ruleset.xml"); fi - - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-Extra/ruleset.xml <(xmllint --format "./WordPress-Extra/ruleset.xml"); fi - - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./phpcs.xml.dist.sample <(xmllint --format "./phpcs.xml.dist.sample"); fi - # Validate the composer.json file. - # @link https://getcomposer.org/doc/03-cli.md#validate - - if [[ "$LINT" == "1" ]]; then composer validate --no-check-all --strict; fi + # Lint the PHP files against parse errors. + - if [[ "$LINT" == "1" ]]; then if find . -path ./vendor -prune -o -path ./bin -prune -o -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi; fi + + # Validate the composer.json file. + # @link https://getcomposer.org/doc/03-cli.md#validate + - if [[ "$LINT" == "1" ]]; then composer validate --no-check-all --strict; fi + + # Run the unit tests. + - | + if [[ ${TRAVIS_PHP_VERSION:0:3} > "7.1" ]]; then + php $PHPUNIT_DIR/phpunit-7.phar --filter WordPress --bootstrap="$(pwd)/vendor/squizlabs/php_codesniffer/tests/bootstrap.php" $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php + else + phpunit --filter WordPress --bootstrap="$(pwd)/vendor/squizlabs/php_codesniffer/tests/bootstrap.php" $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php + fi From fc44f79556168cd6204a2c7ef72750b318cee2d1 Mon Sep 17 00:00:00 2001 From: Stephen Edgar Date: Wed, 22 May 2019 11:06:12 +0100 Subject: [PATCH 165/241] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 93399c75b5..f4fb839d60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -61,7 +61,7 @@ jobs: - diff -B --tabsize=4 ./WordPress-Extra/ruleset.xml <(xmllint --format "./WordPress-Extra/ruleset.xml") - diff -B --tabsize=4 ./phpcs.xml.dist.sample <(xmllint --format "./phpcs.xml.dist.sample") - # Make sure the rulesets don't thrown unexpected errors or warnings. + # Make sure the rulesets don't throw unexpected errors or warnings. # This check needs to be run against a high PHP version to prevent triggering the syntax error check. # It also needs to be run against all PHPCS versions WPCS is tested against. - stage: rulesets From c6cb5c8f83b3eafbe5e84f103a867ec283d12936 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 22 May 2019 17:01:02 +0200 Subject: [PATCH 166/241] ValidHookName: bug fix / skip over array keys String array keys for variable array access would also be examined as part of the hook name, while those should be skipped over as they are not part of the _hook_name. This fixes that. Includes unit test. This commit also lowers the nesting level of the loop by continuing early whenever possible. --- .../NamingConventions/ValidHookNameSniff.php | 82 ++++++++++++------- .../ValidHookNameUnitTest.1.inc | 5 ++ .../ValidHookNameUnitTest.php | 1 + 3 files changed, 58 insertions(+), 30 deletions(-) diff --git a/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php index e7dc9b9e86..0103108a35 100644 --- a/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php @@ -10,6 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\NamingConventions; use WordPressCS\WordPress\AbstractFunctionParameterSniff; +use PHP_CodeSniffer\Util\Tokens; /** * Use lowercase letters in action and filter names. Separate words via underscores. @@ -108,39 +109,60 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p $content[ $i ] = $this->tokens[ $i ]['content']; $expected[ $i ] = $this->tokens[ $i ]['content']; - if ( \in_array( $this->tokens[ $i ]['code'], array( \T_CONSTANT_ENCAPSED_STRING, \T_DOUBLE_QUOTED_STRING ), true ) ) { - $string = $this->strip_quotes( $this->tokens[ $i ]['content'] ); - - /* - * Here be dragons - a double quoted string can contain extrapolated variables - * which don't have to comply with these rules. - */ - if ( \T_DOUBLE_QUOTED_STRING === $this->tokens[ $i ]['code'] ) { - $transform = $this->transform_complex_string( $string, $regex ); - $case_transform = $this->transform_complex_string( $string, $regex, 'case' ); - $punct_transform = $this->transform_complex_string( $string, $regex, 'punctuation' ); - } else { - $transform = $this->transform( $string, $regex ); - $case_transform = $this->transform( $string, $regex, 'case' ); - $punct_transform = $this->transform( $string, $regex, 'punctuation' ); - } + // Skip past potential variable array access: $var['Key']. + if ( \T_VARIABLE === $this->tokens[ $i ]['code'] ) { + do { + $open_bracket = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), null, true ); + if ( false === $open_bracket + || \T_OPEN_SQUARE_BRACKET !== $this->tokens[ $open_bracket ]['code'] + || ! isset( $this->tokens[ $open_bracket ]['bracket_closer'] ) + ) { + continue 2; + } - if ( $string === $transform ) { - continue; - } + $i = $this->tokens[ $open_bracket ]['bracket_closer']; - if ( \T_DOUBLE_QUOTED_STRING === $this->tokens[ $i ]['code'] ) { - $expected[ $i ] = '"' . $transform . '"'; - } else { - $expected[ $i ] = '\'' . $transform . '\''; - } + } while ( isset( $this->tokens[ $i ] ) && $i <= $parameters[1]['end'] ); - if ( $string !== $case_transform ) { - $case_errors++; - } - if ( $string !== $punct_transform ) { - $underscores++; - } + continue; + } + + // Skip past non-string tokens. + if ( isset( Tokens::$stringTokens[ $this->tokens[ $i ]['code'] ] ) === false ) { + continue; + } + + $string = $this->strip_quotes( $this->tokens[ $i ]['content'] ); + + /* + * Here be dragons - a double quoted string can contain extrapolated variables + * which don't have to comply with these rules. + */ + if ( \T_DOUBLE_QUOTED_STRING === $this->tokens[ $i ]['code'] ) { + $transform = $this->transform_complex_string( $string, $regex ); + $case_transform = $this->transform_complex_string( $string, $regex, 'case' ); + $punct_transform = $this->transform_complex_string( $string, $regex, 'punctuation' ); + } else { + $transform = $this->transform( $string, $regex ); + $case_transform = $this->transform( $string, $regex, 'case' ); + $punct_transform = $this->transform( $string, $regex, 'punctuation' ); + } + + if ( $string === $transform ) { + continue; + } + + if ( \T_DOUBLE_QUOTED_STRING === $this->tokens[ $i ]['code'] ) { + $expected[ $i ] = '"' . $transform . '"'; + } else { + $expected[ $i ] = '\'' . $transform . '\''; + } + + if ( $string !== $case_transform ) { + $case_errors++; + } + if ( $string !== $punct_transform ) { + $underscores++; } } diff --git a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.1.inc b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.1.inc index bda73caaf5..7fd072418e 100644 --- a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.1.inc +++ b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.1.inc @@ -83,3 +83,8 @@ do_action( "admin_Head_{${$object->getName()}}_Action_{${$object->getName()}}_Ac // Make sure that deprecated hook names are ignored for this sniff. do_action_deprecated( "admin_Head_$Post admin_Head_$Post" ); // Ok. apply_filters_deprecated( "admin_Head_$Post->ID admin_Head_$Post->ID" ); // Ok. + +// Ignore array keys. +do_action( 'prefix_block_' . $block['blockName'] ); // Ok. +do_action( 'prefix_block_' . $block [ 'blockName' ] . '_More_hookname' ); // Error - use lowercase (second part of the hook name). +do_action( "prefix_block_{$block['blockName']}" ); // Ok. diff --git a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php index b128f1da7b..565c4ccf6e 100644 --- a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php +++ b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php @@ -68,6 +68,7 @@ public function getErrorList( $testFile = 'ValidHookNameUnitTest.1.inc' ) { 79 => 1, 80 => 1, 81 => 1, + 89 => 1, ); case 'ValidHookNameUnitTest.2.inc': From ea20e20c009d03374b99e3046be32e0e00657bb1 Mon Sep 17 00:00:00 2001 From: losnappas Date: Sat, 1 Jun 2019 11:57:38 +0000 Subject: [PATCH 167/241] Sniff::$sanitizingFunctions: Add wp_sanitize_redirect (#1716) Ref: https://developer.wordpress.org/reference/functions/wp_sanitize_redirect/ Fixes 1715 --- WordPress/Sniff.php | 1 + WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc | 2 ++ 2 files changed, 3 insertions(+) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 1d5edc4e28..8c3a86cb40 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -287,6 +287,7 @@ abstract class Sniff implements PHPCS_Sniff { 'wp_parse_id_list' => true, 'wp_redirect' => true, 'wp_safe_redirect' => true, + 'wp_sanitize_redirect' => true, 'wp_strip_all_tags' => true, ); diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc index 46dad6254c..b70afe7f0a 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc @@ -331,3 +331,5 @@ function test_using_different_unslashing_functions() { $sane = sanitize_text_field(stripslashes_deep($_GET['test'])); // Ok. $sane = sanitize_text_field( stripslashes_from_strings_only( $_GET['test'] ) ); // OK. } + +echo wp_sanitize_redirect( wp_unslash( $_GET['test'] ) ); // OK. From 1418e16fda96d61aa43d2d9448d75cb56198c0ba Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Tue, 4 Jun 2019 22:02:25 +0200 Subject: [PATCH 168/241] Add RECOVERY_MODE_COOKIE to whitelisted core constants --- WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index de46e0bdae..4655f953dd 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -164,6 +164,7 @@ class PrefixAllGlobalsSniff extends AbstractFunctionParameterSniff { 'ADMIN_COOKIE_PATH' => true, 'PLUGINS_COOKIE_PATH' => true, 'COOKIE_DOMAIN' => true, + 'RECOVERY_MODE_COOKIE' => true, 'FORCE_SSL_ADMIN' => true, 'FORCE_SSL_LOGIN' => true, 'AUTOSAVE_INTERVAL' => true, From dd25d8ad6568f8f04575235cbdc87d71c4ac1e66 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Wed, 26 Jun 2019 14:13:13 +0100 Subject: [PATCH 169/241] Composer: Update repo URL references The repo has moved organization within GitHub. --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index f306ca7bdc..8fd557c301 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "authors": [ { "name": "Contributors", - "homepage": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/graphs/contributors" + "homepage": "https://github.com/WordPress/WordPress-Coding-Standards/graphs/contributors" } ], "require": { @@ -42,8 +42,8 @@ ] }, "support": { - "issues": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues", - "wiki": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki", - "source": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards" + "issues": "https://github.com/WordPress/WordPress-Coding-Standards/issues", + "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki", + "source": "https://github.com/WordPress/WordPress-Coding-Standards" } } From c3bdb1df5fe12caa6371e4305a834886a7d60105 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 27 Jun 2019 12:51:21 +0200 Subject: [PATCH 170/241] Travis: add "quicktest" stage for non-PR/merge builds The "quicktest" stage will only run a CS check, ruleset check, linting and the unit tests against low/high PHP/PHPCS combinations. This should catch most issues. The more comprehensive complete build against a larger combination of PHP/PHPCS combination will now only be run on PRs and merges to `develop`/`master`. --- .travis.yml | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index f4fb839d60..294a81aee6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,14 +27,23 @@ env: # Lowest supported release in the 3.x series with which WPCS is compatible. - PHPCS_BRANCH="3.3.1" +# Define the stages used. +# For non-PRs, only the sniff, ruleset and quicktest stages are run. +# For pull requests and merges, the full script is run (skipping quicktest). +# Note: for pull requests, "develop" should be the base branch name. +# See: https://docs.travis-ci.com/user/conditions-v1 stages: - - sniff - - rulesets - - test + - name: sniff + - name: rulesets + - name: quicktest + if: type = push AND branch NOT IN (master, develop) + - name: test + if: branch IN (master, develop) jobs: fast_finish: true include: + #### SNIFF STAGE #### - stage: sniff php: 7.3 env: PHPCS_BRANCH="dev-master" @@ -61,6 +70,7 @@ jobs: - diff -B --tabsize=4 ./WordPress-Extra/ruleset.xml <(xmllint --format "./WordPress-Extra/ruleset.xml") - diff -B --tabsize=4 ./phpcs.xml.dist.sample <(xmllint --format "./phpcs.xml.dist.sample") + #### RULESET STAGE #### # Make sure the rulesets don't throw unexpected errors or warnings. # This check needs to be run against a high PHP version to prevent triggering the syntax error check. # It also needs to be run against all PHPCS versions WPCS is tested against. @@ -89,6 +99,19 @@ jobs: - $(pwd)/vendor/bin/phpcs -ps ./bin/class-ruleset-test.php --standard=WordPress-Extra - $(pwd)/vendor/bin/phpcs -ps ./bin/class-ruleset-test.php --standard=WordPress + #### QUICK TEST STAGE #### + # This is a much quicker test which only runs the unit tests and linting against the low/high + # supported PHP/PHPCS combinations. + - stage: quicktest + php: 7.3 + env: PHPCS_BRANCH="dev-master" LINT=1 + - php: 7.3 + env: PHPCS_BRANCH="3.3.1" + - php: 5.4 + env: PHPCS_BRANCH="dev-master" LINT=1 + - php: 5.4 + env: PHPCS_BRANCH="3.3.1" + allow_failures: # Allow failures for unstable builds. - php: "7.4snapshot" From d0b9d93221abaf86bae76fc96fbd517d0209a631 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 28 May 2019 02:59:38 +0200 Subject: [PATCH 171/241] RestrictedPHPFunctions: add error for use of date() As this sniff is already included in the WP Core ruleset and the enhancement request is about PHP native functions, this seemed liked a logical sniff to add this to. I've elected to make this an `error` instead of a `warning` as the code within WP Core has been cleaned up for this issue now and it would be good to prevent new instances of `date()` creeping in. Fixes 1713 --- WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php | 8 ++++++++ WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.inc | 3 +++ WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php | 1 + 3 files changed, 12 insertions(+) diff --git a/WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php b/WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php index 6bde3337d4..27faaa51a6 100644 --- a/WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php @@ -17,6 +17,7 @@ * @package WPCS\WordPressCodingStandards * * @since 0.14.0 + * @since 2.2.0 New group `date` added. */ class RestrictedPHPFunctionsSniff extends AbstractFunctionRestrictionsSniff { @@ -42,6 +43,13 @@ public function getGroups() { 'create_function', ), ), + 'date' => array( + 'type' => 'error', + 'message' => '%s() is affected by runtime timezone changes which can cause date/time to be incorrectly displayed. Use gmdate() instead.', + 'functions' => array( + 'date', + ), + ), ); } diff --git a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.inc b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.inc index 84dbd1d7b3..2a4e8754b5 100644 --- a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.inc +++ b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.inc @@ -3,3 +3,6 @@ add_action( 'widgets_init', create_function( '', // Error. 'return register_widget( "time_more_on_time_widget" );' ) ); + +$post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), date( __( 'F j, Y' ), $now ), date( __( 'g:i a' ), $now ) ); // Error. +$post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), gmdate( __( 'F j, Y' ), $now ), gmdate( __( 'g:i a' ), $now ) ); // OK. diff --git a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php index e39e473eb5..30ad0b2b00 100644 --- a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php @@ -28,6 +28,7 @@ class RestrictedPHPFunctionsUnitTest extends AbstractSniffUnitTest { public function getErrorList() { return array( 3 => 1, + 7 => 2, ); } From ce7e4a7b24650eda0d7e5a6b7f7d01c3c6cef4e1 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Thu, 27 Jun 2019 22:28:26 +0100 Subject: [PATCH 172/241] Add `$plugin` to the list of global variables that shouldn't be overridden. --- WordPress/Sniff.php | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 8c3a86cb40..6fc8842051 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -708,6 +708,7 @@ abstract class Sniff implements PHPCS_Sniff { 'PHP_SELF' => true, 'phpmailer' => true, 'plugin_page' => true, + 'plugin' => true, 'plugins' => true, 'post' => true, 'post_default_category' => true, From d50ee5864a295bb2f3780431dcb90fa62b72eb6a Mon Sep 17 00:00:00 2001 From: Flip Date: Thu, 20 Jun 2019 17:42:13 +0200 Subject: [PATCH 173/241] New error handling Deprecated Classes, Functions, Parameters and Parameter Values --- .../Docs/WP/DeprecatedClassesStandard.xml | 19 +++++++++++++++++++ .../Docs/WP/DeprecatedFunctionsStandard.xml | 19 +++++++++++++++++++ .../WP/DeprecatedParameterValuesStandard.xml | 19 +++++++++++++++++++ .../Docs/WP/DeprecatedParametersStandard.xml | 19 +++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 WordPress/Docs/WP/DeprecatedClassesStandard.xml create mode 100644 WordPress/Docs/WP/DeprecatedFunctionsStandard.xml create mode 100644 WordPress/Docs/WP/DeprecatedParameterValuesStandard.xml create mode 100644 WordPress/Docs/WP/DeprecatedParametersStandard.xml diff --git a/WordPress/Docs/WP/DeprecatedClassesStandard.xml b/WordPress/Docs/WP/DeprecatedClassesStandard.xml new file mode 100644 index 0000000000..42d57e56f1 --- /dev/null +++ b/WordPress/Docs/WP/DeprecatedClassesStandard.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + diff --git a/WordPress/Docs/WP/DeprecatedFunctionsStandard.xml b/WordPress/Docs/WP/DeprecatedFunctionsStandard.xml new file mode 100644 index 0000000000..7a0eaf9390 --- /dev/null +++ b/WordPress/Docs/WP/DeprecatedFunctionsStandard.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + diff --git a/WordPress/Docs/WP/DeprecatedParameterValuesStandard.xml b/WordPress/Docs/WP/DeprecatedParameterValuesStandard.xml new file mode 100644 index 0000000000..b084f2466c --- /dev/null +++ b/WordPress/Docs/WP/DeprecatedParameterValuesStandard.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + diff --git a/WordPress/Docs/WP/DeprecatedParametersStandard.xml b/WordPress/Docs/WP/DeprecatedParametersStandard.xml new file mode 100644 index 0000000000..f754081c72 --- /dev/null +++ b/WordPress/Docs/WP/DeprecatedParametersStandard.xml @@ -0,0 +1,19 @@ + + + + + + + + + + $string ); // Deprecated WP 2.1 + ]]> + + + From fab1ed525e057c19d723bf7c93feaf0a48512abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=BDoljom?= Date: Mon, 1 Jul 2019 05:33:31 +0200 Subject: [PATCH 174/241] Documentation: Update all links to the repository (#1748) The GitHub repository has moved from the dedicated `WordPress-Coding-Standards` organisation to the `WordPress` organisation. This: * Updates all links which pointed to the old repo on GH to the new one. * Updates the badges in the Readme to pick up things up correctly again for the new repo. * Updated all links to Travis from `.org` to `.com` as the build CI has moved as well. --- .github/CONTRIBUTING.md | 4 +- .travis.yml | 2 +- CHANGELOG.md | 142 +++++++++--------- README.md | 38 ++--- WordPress-Core/ruleset.xml | 20 +-- WordPress-Extra/ruleset.xml | 40 ++--- ...stractArrayAssignmentRestrictionsSniff.php | 2 +- WordPress/AbstractClassRestrictionsSniff.php | 2 +- WordPress/AbstractFunctionParameterSniff.php | 2 +- .../AbstractFunctionRestrictionsSniff.php | 2 +- WordPress/PHPCSHelper.php | 2 +- WordPress/Sniff.php | 2 +- .../Arrays/ArrayDeclarationSpacingSniff.php | 2 +- .../Sniffs/Arrays/ArrayIndentationSniff.php | 2 +- .../ArrayKeySpacingRestrictionsSniff.php | 2 +- .../Arrays/CommaAfterArrayItemSniff.php | 2 +- .../MultipleStatementAlignmentSniff.php | 2 +- .../Classes/ClassInstantiationSniff.php | 2 +- .../AssignmentInConditionSniff.php | 2 +- .../CodeAnalysis/EmptyStatementSniff.php | 2 +- .../Sniffs/DB/DirectDatabaseQuerySniff.php | 2 +- .../DB/PreparedSQLPlaceholdersSniff.php | 2 +- WordPress/Sniffs/DB/PreparedSQLSniff.php | 2 +- .../Sniffs/DB/RestrictedClassesSniff.php | 2 +- .../Sniffs/DB/RestrictedFunctionsSniff.php | 2 +- WordPress/Sniffs/DB/SlowDBQuerySniff.php | 2 +- WordPress/Sniffs/Files/FileNameSniff.php | 2 +- .../PrefixAllGlobalsSniff.php | 2 +- .../ValidFunctionNameSniff.php | 2 +- .../NamingConventions/ValidHookNameSniff.php | 2 +- .../ValidVariableNameSniff.php | 2 +- .../Sniffs/PHP/DevelopmentFunctionsSniff.php | 2 +- .../PHP/DiscouragedPHPFunctionsSniff.php | 2 +- WordPress/Sniffs/PHP/DontExtractSniff.php | 2 +- WordPress/Sniffs/PHP/IniSetSniff.php | 2 +- .../Sniffs/PHP/NoSilencedErrorsSniff.php | 2 +- WordPress/Sniffs/PHP/POSIXFunctionsSniff.php | 2 +- .../Sniffs/PHP/PregQuoteDelimiterSniff.php | 2 +- .../PHP/RestrictedPHPFunctionsSniff.php | 2 +- .../Sniffs/PHP/StrictComparisonsSniff.php | 2 +- WordPress/Sniffs/PHP/StrictInArraySniff.php | 2 +- WordPress/Sniffs/PHP/TypeCastsSniff.php | 2 +- WordPress/Sniffs/PHP/YodaConditionsSniff.php | 2 +- .../Sniffs/Security/EscapeOutputSniff.php | 2 +- .../Security/NonceVerificationSniff.php | 2 +- .../Sniffs/Security/PluginMenuSlugSniff.php | 2 +- .../Sniffs/Security/SafeRedirectSniff.php | 2 +- .../Security/ValidatedSanitizedInputSniff.php | 4 +- .../Sniffs/Utils/I18nTextDomainFixerSniff.php | 2 +- .../Sniffs/WP/AlternativeFunctionsSniff.php | 2 +- WordPress/Sniffs/WP/CapitalPDangitSniff.php | 2 +- WordPress/Sniffs/WP/CronIntervalSniff.php | 2 +- .../Sniffs/WP/DeprecatedClassesSniff.php | 2 +- .../Sniffs/WP/DeprecatedFunctionsSniff.php | 2 +- .../WP/DeprecatedParameterValuesSniff.php | 2 +- .../Sniffs/WP/DeprecatedParametersSniff.php | 2 +- .../Sniffs/WP/DiscouragedConstantsSniff.php | 2 +- .../Sniffs/WP/DiscouragedFunctionsSniff.php | 2 +- .../WP/EnqueuedResourceParametersSniff.php | 2 +- .../Sniffs/WP/EnqueuedResourcesSniff.php | 2 +- .../WP/GlobalVariablesOverrideSniff.php | 2 +- WordPress/Sniffs/WP/I18nSniff.php | 2 +- WordPress/Sniffs/WP/PostsPerPageSniff.php | 2 +- WordPress/Sniffs/WP/TimezoneChangeSniff.php | 2 +- .../WhiteSpace/CastStructureSpacingSniff.php | 2 +- .../ControlStructureSpacingSniff.php | 2 +- .../WhiteSpace/DisallowInlineTabsSniff.php | 2 +- .../WhiteSpace/OperatorSpacingSniff.php | 2 +- .../WhiteSpace/PrecisionAlignmentSniff.php | 2 +- .../ArrayDeclarationSpacingUnitTest.php | 2 +- .../Tests/Arrays/ArrayIndentationUnitTest.php | 2 +- .../ArrayKeySpacingRestrictionsUnitTest.php | 2 +- .../Arrays/CommaAfterArrayItemUnitTest.php | 2 +- .../MultipleStatementAlignmentUnitTest.php | 2 +- .../Classes/ClassInstantiationUnitTest.php | 2 +- .../AssignmentInConditionUnitTest.php | 2 +- .../CodeAnalysis/EmptyStatementUnitTest.php | 2 +- .../Tests/DB/DirectDatabaseQueryUnitTest.php | 2 +- .../DB/PreparedSQLPlaceholdersUnitTest.php | 2 +- WordPress/Tests/DB/PreparedSQLUnitTest.php | 2 +- .../Tests/DB/RestrictedClassesUnitTest.php | 2 +- .../Tests/DB/RestrictedFunctionsUnitTest.php | 2 +- WordPress/Tests/DB/SlowDBQueryUnitTest.php | 2 +- WordPress/Tests/Files/FileNameUnitTest.php | 2 +- .../PrefixAllGlobalsUnitTest.php | 2 +- .../ValidFunctionNameUnitTest.php | 2 +- .../ValidHookNameUnitTest.php | 2 +- .../ValidVariableNameUnitTest.php | 2 +- .../PHP/DevelopmentFunctionsUnitTest.php | 2 +- .../PHP/DiscouragedPHPFunctionsUnitTest.php | 2 +- WordPress/Tests/PHP/DontExtractUnitTest.php | 2 +- WordPress/Tests/PHP/IniSetUnitTest.php | 2 +- .../Tests/PHP/NoSilencedErrorsUnitTest.php | 2 +- .../Tests/PHP/POSIXFunctionsUnitTest.php | 2 +- .../Tests/PHP/PregQuoteDelimiterUnitTest.php | 2 +- .../PHP/RestrictedPHPFunctionsUnitTest.php | 2 +- .../Tests/PHP/StrictComparisonsUnitTest.php | 2 +- WordPress/Tests/PHP/StrictInArrayUnitTest.php | 2 +- WordPress/Tests/PHP/TypeCastsUnitTest.php | 2 +- .../Tests/PHP/YodaConditionsUnitTest.php | 2 +- .../Tests/Security/EscapeOutputUnitTest.php | 2 +- .../Security/NonceVerificationUnitTest.php | 2 +- .../Tests/Security/PluginMenuSlugUnitTest.php | 2 +- .../Tests/Security/SafeRedirectUnitTest.php | 2 +- .../ValidatedSanitizedInputUnitTest.php | 2 +- .../Utils/I18nTextDomainFixerUnitTest.php | 2 +- .../Tests/WP/AlternativeFunctionsUnitTest.php | 2 +- WordPress/Tests/WP/CapitalPDangitUnitTest.php | 2 +- WordPress/Tests/WP/CronIntervalUnitTest.php | 2 +- .../Tests/WP/DeprecatedClassesUnitTest.php | 2 +- .../Tests/WP/DeprecatedFunctionsUnitTest.php | 2 +- .../WP/DeprecatedParameterValuesUnitTest.php | 2 +- .../Tests/WP/DeprecatedParametersUnitTest.php | 2 +- .../Tests/WP/DiscouragedConstantsUnitTest.php | 2 +- .../Tests/WP/DiscouragedFunctionsUnitTest.php | 2 +- .../WP/EnqueuedResourceParametersUnitTest.php | 2 +- .../Tests/WP/EnqueuedResourcesUnitTest.php | 2 +- .../WP/GlobalVariablesOverrideUnitTest.1.inc | 6 +- .../WP/GlobalVariablesOverrideUnitTest.php | 2 +- WordPress/Tests/WP/I18nUnitTest.php | 2 +- WordPress/Tests/WP/PostsPerPageUnitTest.php | 2 +- WordPress/Tests/WP/TimezoneChangeUnitTest.php | 2 +- .../CastStructureSpacingUnitTest.php | 2 +- .../ControlStructureSpacingUnitTest.1.inc | 2 +- ...ontrolStructureSpacingUnitTest.1.inc.fixed | 2 +- .../ControlStructureSpacingUnitTest.php | 2 +- .../WhiteSpace/DisallowInlineTabsUnitTest.php | 2 +- .../WhiteSpace/OperatorSpacingUnitTest.php | 2 +- .../WhiteSpace/PrecisionAlignmentUnitTest.php | 2 +- phpcs.xml.dist.sample | 2 +- 130 files changed, 250 insertions(+), 250 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 2a6e2d2496..34b96be5c7 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -30,7 +30,7 @@ Once a commit is made to `develop`, a PR should be opened from `develop` into `m When writing sniffs, always remember that any `public` sniff property can be overruled via a custom ruleset by the end-user. Only make a property `public` if that is the intended behaviour. -When you introduce new `public` sniff properties, or your sniff extends a class from which you inherit a `public` property, please don't forget to update the [public properties wiki page](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties) with the relevant details once your PR has been merged into the `develop` branch. +When you introduce new `public` sniff properties, or your sniff extends a class from which you inherit a `public` property, please don't forget to update the [public properties wiki page](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties) with the relevant details once your PR has been merged into the `develop` branch. ## Whitelist comments @@ -51,7 +51,7 @@ When you introduce new `public` sniff properties, or your sniff extends a class The WordPress Coding Standards use the `PHP_CodeSniffer` native unit test suite for unit testing the sniffs. -Presuming you have installed `PHP_CodeSniffer` and the WordPress-Coding-Standards as [noted in the README](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards#how-to-use-this), all you need now is `PHPUnit`. +Presuming you have installed `PHP_CodeSniffer` and the WordPress-Coding-Standards as [noted in the README](https://github.com/WordPress/WordPress-Coding-Standards#how-to-use-this), all you need now is `PHPUnit`. > N.B.: If you installed WPCS using Composer, make sure you used `--prefer-source` or run `composer install --prefer-source` now to make sure the unit tests are available. > Other than that, you're all set already as Composer will have installed PHPUnit for you. diff --git a/.travis.yml b/.travis.yml index 294a81aee6..2eb7d0e9e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -53,7 +53,7 @@ jobs: - libxml2-utils script: # WordPress Coding Standards. - # @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + # @link https://github.com/WordPress/WordPress-Coding-Standards # @link http://pear.php.net/package/PHP_CodeSniffer/ - $(pwd)/vendor/bin/phpcs --runtime-set ignore_warnings_on_exit 1 diff --git a/CHANGELOG.md b/CHANGELOG.md index a777dc0905..53270b436b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ _No documentation available about unreleased changes as of yet._ ### Changed - The `WordPress.WP.CapitalPDangit` will now ignore misspelled instances of `WordPress` within constant declarations. This covers both constants declared using `defined()` as well as constants declared using the `const` keyword. -- The default value for `minimum_supported_wp_version`, as used by a [number of sniffs detecting usage of deprecated WP features](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#minimum-wp-version-to-check-for-usage-of-deprecated-functions-classes-and-function-parameters), has been updated to `4.9`. +- The default value for `minimum_supported_wp_version`, as used by a [number of sniffs detecting usage of deprecated WP features](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#minimum-wp-version-to-check-for-usage-of-deprecated-functions-classes-and-function-parameters), has been updated to `4.9`. ### Removed - `paginate_comments_links()` from the list of auto-escaped functions `Sniff::$autoEscapedFunctions`. @@ -53,7 +53,7 @@ _No documentation available about unreleased changes as of yet._ ### Changed - Moved the `WordPress.PHP.StrictComparisons`, `WordPress.PHP.StrictInArray` and the `WordPress.CodeAnalysis.AssignmentInCondition` sniff from the `WordPress-Extra` to the `WordPress-Core` ruleset. - The `Squiz.Commenting.InlineComment.SpacingAfter` error is no longer included in the `WordPress-Docs` ruleset. -- The default value for `minimum_supported_wp_version`, as used by a [number of sniffs detecting usage of deprecated WP features](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#minimum-wp-version-to-check-for-usage-of-deprecated-functions-classes-and-function-parameters), has been updated to `4.8`. +- The default value for `minimum_supported_wp_version`, as used by a [number of sniffs detecting usage of deprecated WP features](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#minimum-wp-version-to-check-for-usage-of-deprecated-functions-classes-and-function-parameters), has been updated to `4.8`. - The `WordPress.WP.DeprecatedFunctions` sniff will now detect functions deprecated in WP 5.1. - The `WordPress.Security.NonceVerification` sniff now allows for variable type testing, comparisons, unslashing and sanitization before the nonce check. A nonce check within the same scope, however, is still required. - The `WordPress.Security.ValidatedSanitizedInput` sniff now allows for using a superglobal in an array-value comparison without sanitization, same as when the superglobal is used in a scalar value comparison. @@ -116,7 +116,7 @@ Also, all previously deprecated sniffs, properties and methods have been removed Please read the complete changelog carefully before you upgrade. -If you are a maintainer of an external standard based on WordPressCS and any of your custom sniffs are based on or extend WPCS sniffs, please read the [Developers Upgrade Guide to WordPressCS 2.0.0](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Upgrade-Guide-to-WordPressCS-2.0.0-for-Developers-of-external-standards). +If you are a maintainer of an external standard based on WordPressCS and any of your custom sniffs are based on or extend WPCS sniffs, please read the [Developers Upgrade Guide to WordPressCS 2.0.0](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Upgrade-Guide-to-WordPressCS-2.0.0-for-Developers-of-external-standards). ### Changes since 2.0.0-RC1 @@ -126,7 +126,7 @@ If you are a maintainer of an external standard based on WordPressCS and any of ### Changes since 1.2.1 For a full list of changes from the 1.2.1 version, please review the following changelog: -* https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/releases/tag/2.0.0-RC1 +* https://github.com/WordPress/WordPress-Coding-Standards/releases/tag/2.0.0-RC1 ## [2.0.0-RC1] - 2018-12-31 @@ -141,7 +141,7 @@ Also, all previously deprecated sniffs, properties and methods have been removed Please read the complete changelog carefully before you upgrade. -If you are a maintainer of an external standard based on WordPressCS and any of your custom sniffs are based on or extend WPCS sniffs, please read the [Developers Upgrade Guide to WordPressCS 2.0.0](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Upgrade-Guide-to-WordPressCS-2.0.0-for-Developers-of-external-standards). +If you are a maintainer of an external standard based on WordPressCS and any of your custom sniffs are based on or extend WPCS sniffs, please read the [Developers Upgrade Guide to WordPressCS 2.0.0](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Upgrade-Guide-to-WordPressCS-2.0.0-for-Developers-of-external-standards). ### Added - `Generic.PHP.DiscourageGoto`, `Generic.PHP.LowerCaseType`, `Generic.WhiteSpace.ArbitraryParenthesesSpacing` and `PSR12.Keywords.ShortFormTypeKeywords` to the `WordPress-Core` ruleset. @@ -181,8 +181,8 @@ If you are a maintainer of an external standard based on WordPressCS and any of - `WordPress.NamingConventions.ValidVariableName`: Added unit tests confirming support for multi-variable/property declarations. - The `get_name_suggestion()` method has been moved from the `WordPress.NamingConventions.ValidFunctionName` sniff to the base `Sniff` class, renamed to `get_snake_case_name_suggestion()` and made static. - The rulesets are now validated against the `PHP_CodeSniffer` XSD schema. -- Updated the [custom ruleset example](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/phpcs.xml.dist.sample) to use the recommended ruleset syntax for `PHP_CodeSniffer` 3.3.1+, including using the new [array property format](https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.3.0) which is now supported. -- Dev: The command to run the unit tests has changed. Please see the updated instructions in the [CONTRIBUTING.md](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/.github/CONTRIBUTING.md) file. +- Updated the [custom ruleset example](https://github.com/WordPress/WordPress-Coding-Standards/blob/develop/phpcs.xml.dist.sample) to use the recommended ruleset syntax for `PHP_CodeSniffer` 3.3.1+, including using the new [array property format](https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.3.0) which is now supported. +- Dev: The command to run the unit tests has changed. Please see the updated instructions in the [CONTRIBUTING.md](https://github.com/WordPress/WordPress-Coding-Standards/blob/develop/.github/CONTRIBUTING.md) file. The `bin/pre-commit` example git hook has been updated to match. Additionally a `run-tests` script has been added to the `composer.json` file for your convenience. To facilitate this, PHPUnit has been added to `require-dev`, even though it is strictly speaking a dependency of PHPCS, not of WPCS. - Dev: The DealerDirect PHPCS Composer plugin has been added to `require-dev`. @@ -190,7 +190,7 @@ If you are a maintainer of an external standard based on WordPressCS and any of - User facing documentation, including the wiki, as well as inline documentation has been updated for all the changes contained in WordPressCS 2.0 and other recommended best practices for `PHP_CodeSniffer` 3.3.1+. ### Deprecated -- The use of the [WordPressCS native whitelist comments](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Whitelisting-code-which-flags-errors), which were introduced in WPCS 0.4.0, have been deprecated and support will be removed in WPCS 3.0.0. +- The use of the [WordPressCS native whitelist comments](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Whitelisting-code-which-flags-errors), which were introduced in WPCS 0.4.0, have been deprecated and support will be removed in WPCS 3.0.0. The WordPressCS native whitelist comments will continue to work for now, but a deprecation warning will be thrown when they are encountered. You are encouraged to upgrade our whitelist comment to use the [PHPCS native selective ignore annotations](https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.2.0) as introduced in `PHP_CodeSniffer` 3.2.0, as soon as possible. @@ -203,7 +203,7 @@ If you are a maintainer of an external standard based on WordPressCS and any of For checking a theme/plugin for hosting on the WordPress.com VIP platform, please use the [Automattic VIP coding standards](https://github.com/Automattic/VIP-Coding-Standards) instead. - Support for array properties set in a custom ruleset without the `type="array"` attribute. Support for this was deprecated in WPCS 1.0.0. - If in doubt about how properties should be set in your custom ruleset, please refer to the [Customizable sniff properties](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties) wiki page which contains XML code examples for setting each and every WPCS native sniff property. + If in doubt about how properties should be set in your custom ruleset, please refer to the [Customizable sniff properties](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties) wiki page which contains XML code examples for setting each and every WPCS native sniff property. As the minimum `PHP_CodeSniffer` version is now 3.3.1, you can now also use the [new format for setting array properties](https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.3.0), so this would be a great moment to review and update your custom ruleset. Note: the ability to set select properties from the command-line as comma-delimited strings is _not_ affected by this change. - The following sniffs have been removed outright without deprecation. @@ -278,7 +278,7 @@ If you are a maintainer of an external standard based on WordPressCS and any of Note: This will be the last release supporting PHP_CodeSniffer 2.x. ### Changed -- The default value for `minimum_supported_wp_version`, as used by a [number of sniffs detecting usage of deprecated WP features](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#minimum-wp-version-to-check-for-usage-of-deprecated-functions-classes-and-function-parameters), has been updated to `4.7`. +- The default value for `minimum_supported_wp_version`, as used by a [number of sniffs detecting usage of deprecated WP features](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#minimum-wp-version-to-check-for-usage-of-deprecated-functions-classes-and-function-parameters), has been updated to `4.7`. - The `WordPress.NamingConventions.PrefixAllGlobals` sniff will now report the error for hook names and constant names declared with `define()` on the line containing the parameter for the hook/constant name. Previously, it would report the error on the line containing the function call. - Various minor housekeeping fixes to inline documentation, rulesets, code. @@ -319,7 +319,7 @@ Note: This will be the last release supporting PHP_CodeSniffer 2.x. - Minor hardening and efficiency improvements to the `WordPress.NamingConventions.PrefixAllGlobals` sniff. - The inline documentation of the `WordPress-Core` ruleset has been updated to be in line again with [the handbook](https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/). - The inline links to documentation about the VIP requirements have been updated. -- Updated the [custom ruleset example](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/phpcs.xml.dist.sample) to recommend using `PHPCompatibilityWP` rather than `PHPCompatibility`. +- Updated the [custom ruleset example](https://github.com/WordPress/WordPress-Coding-Standards/blob/develop/phpcs.xml.dist.sample) to recommend using `PHPCompatibilityWP` rather than `PHPCompatibility`. - All sniffs are now also being tested against PHP 7.3 for consistent sniff results. Note: PHP 7.3 is only supported in combination with PHPCS 3.3.1 or higher as `PHP_CodeSniffer` itself has an incompatibility in earlier versions. - Minor grammar fixes in text strings and documentation. @@ -351,7 +351,7 @@ Note: This will be the last release supporting PHP_CodeSniffer 2.x. The user-defined whitelist will always be respected. By default, this property is set to `true` for the `WordPress-Core` ruleset and to `false` for the `WordPress-Extra` ruleset (which is stricter regarding these kind of best practices). - Metrics to the `WordPress.NamingConventions.PrefixAllGlobals` sniff to aid people in determining the most commonly used prefix in a legacy project. - For an example of how to use this feature, please see the detailed explanation in the [pull request](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/1437). + For an example of how to use this feature, please see the detailed explanation in the [pull request](https://github.com/WordPress/WordPress-Coding-Standards/pull/1437). ### Changed - The `PEAR.Functions.FunctionCallSignature` sniff, which is part of the `WordPress-Core` ruleset, used to allow multiple function call parameters per line in multi-line function calls. This will no longer be allowed. @@ -412,7 +412,7 @@ If you are a maintainer of an external standard based on WPCS and any of your cu - New utility method `Sniff::is_use_of_global_constant()`. - A rationale to the package suggestion made via `composer.json`. - CI: Validation of the `composer.json` file on each build. -- A wiki page with instructions on how to [set up WPCS to run with Eclipse on XAMPP](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/How-to-use-WPCS-with-Eclipse-and-XAMPP). +- A wiki page with instructions on how to [set up WPCS to run with Eclipse on XAMPP](https://github.com/WordPress/WordPress-Coding-Standards/wiki/How-to-use-WPCS-with-Eclipse-and-XAMPP). - Readme: A link to an external resource with more examples for setting up PHPCS for CI. - Readme: A badge-based quick overview of the project. @@ -433,7 +433,7 @@ If you are a maintainer of an external standard based on WPCS and any of your cu - The `WordPress.VIP.PostsPerPage` sniff has been split into two distinct sniffs: - `WordPress.WP.PostsPerPage` which will check for the use of a high pagination limit and will throw a `warning` when this is encountered. For the `VIP` ruleset, the error level remains `error`. - `WordPress.VIP.PostsPerPage` wich will check for disabling of pagination. -- The default value for `minimum_supported_wp_version`, as used by a [number of sniffs detecting usage of deprecated WP features](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#minimum-wp-version-to-check-for-usage-of-deprecated-functions-classes-and-function-parameters), has been updated to `4.6`. +- The default value for `minimum_supported_wp_version`, as used by a [number of sniffs detecting usage of deprecated WP features](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#minimum-wp-version-to-check-for-usage-of-deprecated-functions-classes-and-function-parameters), has been updated to `4.6`. - The `WordPress.WP.AlternativeFunctions` sniff will now only throw a warning if/when the recommended alternative function is available in the minimum supported WP version of a project. In addition to this, certain alternatives are only valid alternatives in certain circumstances, like when the WP version only supports the first parameter of the PHP function it is trying to replace. This will now be taken into account for: @@ -456,8 +456,8 @@ If you are a maintainer of an external standard based on WPCS and any of your cu - CI: Each change will now also be checked for PHP cross-version compatibility. - CI: The rulesets will now also be tested on each change to ensure no unexpected messages are thrown. - CI: Minor changes to the script to make the build testing faster. -- Updated the [custom ruleset example](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/phpcs.xml.dist.sample) for the changes contained in this release and to reflect current best practices regarding the PHPCompatibility standard. -- The instructions on how to set up WPCS for various IDEs have been moved from the `README` to the [wiki](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki). +- Updated the [custom ruleset example](https://github.com/WordPress/WordPress-Coding-Standards/blob/develop/phpcs.xml.dist.sample) for the changes contained in this release and to reflect current best practices regarding the PHPCompatibility standard. +- The instructions on how to set up WPCS for various IDEs have been moved from the `README` to the [wiki](https://github.com/WordPress/WordPress-Coding-Standards/wiki). - Updated output examples in `README.md` and `CONTRIBUTING.md` and other minor changes to these files. - Updated references to the PHPCompatibility standard to reflect its new location and recommend using PHPCompatibilityWP. @@ -490,11 +490,11 @@ If you are a maintainer of an external standard based on WPCS and any of your cu - `Variables` - `XSS` - The `posts_per_page` property in the `WordPress.VIP.PostsPerPage` sniff has been deprecated as the related functionality has been moved to the `WordPress.WP.PostsPerPage` sniff. - See [WP PostsPerPage: post limit](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#wp-postsperpage-post-limit) for more information about this property. + See [WP PostsPerPage: post limit](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#wp-postsperpage-post-limit) for more information about this property. - The `exclude` property which is available to most sniffs which extend the `AbstractArrayAssignmentRestrictions`, `AbstractFunctionRestrictions` and `AbstractVariableRestrictions` classes or any of their children, used to be a `string` property and expected a comma-delimited list of groups to exclude. The type of the property has now been changed to `array`. Custom rulesets which pass this property need to be adjusted to reflect this change. Support for passing the property as a comma-delimited string has been deprecated and will be removed in WPCS 2.0.0. - See [Excluding a group of checks](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#excluding-a-group-of-checks) for more information about the sniffs affected by this change. + See [Excluding a group of checks](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#excluding-a-group-of-checks) for more information about the sniffs affected by this change. - The `AbstractVariableRestrictionsSniff` class has been deprecated as all sniffs depending on this class have been deprecated. Unless a new sniff is created in the near future which uses this class, the abstract class will be removed in WPCS 2.0.0. - The `Sniff::has_html_open_tag()` utility method has been deprecated as it is now only used by deprecated sniffs. The method will be removed in WPCS 2.0.0. @@ -509,7 +509,7 @@ If you are a maintainer of an external standard based on WPCS and any of your cu PHPCS 3.2.0 introduced new annotations which can be used inline to selectively disable/ignore certain sniffs. **Note**: The initial implementation of the new annotations was buggy. If you intend to start using these new style annotations, you are strongly advised to use PHPCS 3.3.0 or higher. For more information about these annotations, please refer to the [PHPCS Wiki](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-parts-of-a-file). - - The [WPCS native whitelist comments](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Whitelisting-code-which-flags-errors) can now be combined with the new style PHPCS whitelist annotations in the `-- for reasons` part of the annotation. + - The [WPCS native whitelist comments](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Whitelisting-code-which-flags-errors) can now be combined with the new style PHPCS whitelist annotations in the `-- for reasons` part of the annotation. - `WordPress.Arrays.ArrayDeclarationSpacing`: the fixer will now handle the new style annotations correctly. - `WordPress.Arrays.CommaAfterArrayItem`: prevent a fixer loop when new style annotations are encountered. - `WordPress.Files.FileName`: respect the new style annotations if these would selectively disable this sniff. @@ -579,10 +579,10 @@ If you are a maintainer of an external standard based on WPCS and any of your cu ### Added - `WordPress.Arrays.MultipleStatementAlignment` sniff to the `WordPress-Core` ruleset which will align the array assignment operator for multi-item, multi-line associative arrays. - This new sniff offers four custom properties to customize its behaviour: [`ignoreNewlines`](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#array-alignment-allow-for-new-lines), [`exact`](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#array-alignment-allow-non-exact-alignment), [`maxColumn`](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#array-alignment-maximum-column) and [`alignMultilineItems`](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#array-alignment-dealing-with-multi-line-items). + This new sniff offers four custom properties to customize its behaviour: [`ignoreNewlines`](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#array-alignment-allow-for-new-lines), [`exact`](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#array-alignment-allow-non-exact-alignment), [`maxColumn`](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#array-alignment-maximum-column) and [`alignMultilineItems`](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#array-alignment-dealing-with-multi-line-items). - `WordPress.DB.PreparedSQLPlaceholders` sniff to the `WordPress-Core` ruleset which will analyse the placeholders passed to `$wpdb->prepare()` for their validity, check whether queries using `IN ()` and `LIKE` statements are created correctly and will check whether a correct number of replacements are passed. This sniff should help detect queries which are impacted by the security fixes to `$wpdb->prepare()` which shipped with WP 4.8.2 and 4.8.3. - The sniff also adds a new ["PreparedSQLPlaceholders replacement count" whitelist comment](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Whitelisting-code-which-flags-errors#preparedsql-placeholders-vs-replacements) for pertinent replacement count vs placeholder mismatches. Please consider carefully whether something could be a bug when you are tempted to use the whitelist comment and if so, [report it](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/new). + The sniff also adds a new ["PreparedSQLPlaceholders replacement count" whitelist comment](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Whitelisting-code-which-flags-errors#preparedsql-placeholders-vs-replacements) for pertinent replacement count vs placeholder mismatches. Please consider carefully whether something could be a bug when you are tempted to use the whitelist comment and if so, [report it](https://github.com/WordPress/WordPress-Coding-Standards/issues/new). - `WordPress.PHP.DiscourageGoto` sniff to the `WordPress-Core` ruleset. - `WordPress.PHP.RestrictedFunctions` sniff to the `WordPress-Core` ruleset which initially forbids the use of `create_function()`. This was previous only discouraged under certain circumstances. @@ -591,7 +591,7 @@ If you are a maintainer of an external standard based on WPCS and any of your cu - `WordPress.WhiteSpace.SemicolonSpacing` sniff to the `WordPress-Core` ruleset which will throw a (fixable) error when whitespace is found before a semi-colon, except for when the semi-colon denotes an empty `for()` condition. - `WordPress.CodeAnalysis.AssignmentInCondition` sniff to the `WordPress-Extra` ruleset. - `WordPress.WP.DiscouragedConstants` sniff to the `WordPress-Extra` and `WordPress-VIP` rulesets to detect usage of deprecated WordPress constants, such as `STYLESHEETPATH` and `HEADER_IMAGE`. -- Ability to pass the `minimum_supported_version` to use for the `DeprecatedFunctions`, `DeprecatedClasses` and `DeprecatedParameters` sniff in one go. You can pass a `minimum_supported_wp_version` runtime variable for this [from the command line or pass it using a `config` directive in a custom ruleset](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#setting-minimum-supported-wp-version-for-all-sniffs-in-one-go-wpcs-0140). +- Ability to pass the `minimum_supported_version` to use for the `DeprecatedFunctions`, `DeprecatedClasses` and `DeprecatedParameters` sniff in one go. You can pass a `minimum_supported_wp_version` runtime variable for this [from the command line or pass it using a `config` directive in a custom ruleset](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#setting-minimum-supported-wp-version-for-all-sniffs-in-one-go-wpcs-0140). - `Generic.Formatting.MultipleStatementAlignment` - customized to have a `maxPadding` of `40` -, `Generic.Functions.FunctionCallArgumentSpacing` and `Squiz.WhiteSpace.ObjectOperatorSpacing` to the `WordPress-Core` ruleset. - `Squiz.Scope.MethodScope`, `Squiz.Scope.MemberVarScope`, `Squiz.WhiteSpace.ScopeKeywordSpacing`, `PSR2.Methods.MethodDeclaration`, `Generic.Files.OneClassPerFile`, `Generic.Files.OneInterfacePerFile`, `Generic.Files.OneTraitPerFile`, `PEAR.Files.IncludingFile`, `Squiz.WhiteSpace.LanguageConstructSpacing`, `PSR2.Namespaces.NamespaceDeclaration` to the `WordPress-Extra` ruleset. - The `is_class_constant()`, `is_class_property` and `valid_direct_scope()` utility methods to the `WordPress\Sniff` class. @@ -600,13 +600,13 @@ If you are a maintainer of an external standard based on WPCS and any of your cu - When passing an array property via a custom ruleset to PHP_CodeSniffer, spaces around the key/value are taken as intentional and parsed as part of the array key/value. In practice, this leads to confusion and WPCS does not expect any values which could be preceded/followed by a space, so for the WordPress Coding Standard native array properties, like `customAutoEscapedFunction`, `text_domain`, `prefixes`, WPCS will now trim whitespace from the keys/values received before use. - The WPCS native whitelist comments used to only work when they were put on the _end of the line_ of the code they applied to. As of now, they will also be recognized when they are be put at the _end of the statement_ they apply to. - The `WordPress.Arrays.ArrayDeclarationSpacing` sniff used to enforce all associative arrays to be multi-line. The handbook has been updated to only require this for multi-item associative arrays and the sniff has been updated accordingly. - [The original behaviour can still be enforced](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#arrays-forcing-single-item-associative-arrays-to-be-multi-line) by setting the new `allow_single_item_single_line_associative_arrays` property to `false` in a custom ruleset. + [The original behaviour can still be enforced](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#arrays-forcing-single-item-associative-arrays-to-be-multi-line) by setting the new `allow_single_item_single_line_associative_arrays` property to `false` in a custom ruleset. - The `WordPress.NamingConventions.PrefixAllGlobals` sniff will now allow for a limited list of WP core hooks which are intended to be called by plugins and themes. - The `WordPress.PHP.DiscouragedFunctions` sniff used to include `create_function`. This check has been moved to the new `WordPress.PHP.RestrictedFunctions` sniff. - The `WordPress.PHP.StrictInArray` sniff now has a separate error code `FoundNonStrictFalse` for when the `$strict` parameter has been set to `false`. This allows for excluding the warnings for that particular situation, which will normally be intentional, via a custom ruleset. -- The `WordPress.VIP.CronInterval` sniff now allows for customizing the minimum allowed cron interval by [setting a property in a custom ruleset](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#vip-croninterval-minimum-interval). +- The `WordPress.VIP.CronInterval` sniff now allows for customizing the minimum allowed cron interval by [setting a property in a custom ruleset](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#vip-croninterval-minimum-interval). - The `WordPress.VIP.RestrictedFunctions` sniff used to prohibit the use of certain WP native functions, recommending the use of `wpcom_vip_get_term_link()`, `wpcom_vip_get_term_by()` and `wpcom_vip_get_category_by_slug()` instead, as the WP native functions were not being cached. As the results of the relevant WP native functions are cached as of WP 4.8, the advice has now been reversed i.e. use the WP native functions instead of `wpcom...` functions. -- The `WordPress.VIP.PostsPerPage` sniff now allows for customizing the `post_per_page` limit for which the sniff will trigger by [setting a property in a custom ruleset](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#vip-postsperpage-post-limit). +- The `WordPress.VIP.PostsPerPage` sniff now allows for customizing the `post_per_page` limit for which the sniff will trigger by [setting a property in a custom ruleset](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#vip-postsperpage-post-limit). - The `WordPress.WP.I18n` sniff will now allow and actively encourage omitting the text domain in I18n function calls if the text domain passed via the `text_domain` property is `default`, i.e. the domain used by Core. When `default` is one of several text domains passed via the `text_domain` property, the error thrown when the domain is missing has been downgraded to a `warning`. - The `WordPress.XSS.EscapeOutput` sniff now has a separate error code `OutputNotEscapedShortEcho` and the error message texts have been updated. @@ -619,7 +619,7 @@ If you are a maintainer of an external standard based on WPCS and any of your cu - Various minor documentation fixes. - Improved the Atom setup instructions in the Readme. - Updated the unit testing information in Contributing. -- Updated the [custom ruleset example](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/phpcs.xml.dist.sample) for the changes contained in this release and to make it more explicit what is recommended versus example code. +- Updated the [custom ruleset example](https://github.com/WordPress/WordPress-Coding-Standards/blob/develop/phpcs.xml.dist.sample) for the changes contained in this release and to make it more explicit what is recommended versus example code. - The minimum recommended version for the suggested `DealerDirect/phpcodesniffer-composer-installer` Composer plugin has gone up to `0.4.3`. This patch version fixes support for PHP 5.3. ### Fixed @@ -645,7 +645,7 @@ If you are a maintainer of an external standard based on WPCS and any of your cu ### Added - Support for PHP_CodeSniffer 3.0.2+. The minimum required PHPCS version (2.9.0) stays the same. -- Support for the PHPCS 3 `--ignore-annotations` command line option. If you pass this option, both PHPCS native `@ignore ...` annotations as well as the WPCS specific [whitelist flags](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Whitelisting-code-which-flags-errors) will be ignored. +- Support for the PHPCS 3 `--ignore-annotations` command line option. If you pass this option, both PHPCS native `@ignore ...` annotations as well as the WPCS specific [whitelist flags](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Whitelisting-code-which-flags-errors) will be ignored. ### Changed - The minimum required PHP version is now 5.3 when used in combination with PHPCS 2.x and PHP 5.4 when used in combination with PHPCS 3.x. @@ -678,9 +678,9 @@ If you are a maintainer of an external standard based on WPCS and any of your cu - `WordPress.Classes.ClassInstantion` sniff to the `WordPress-Extra` ruleset to detect - and auto-fix - missing parentheses on object instantiation and superfluous whitespace in PHP and JS files. The sniff will also detect `new` being assigned by reference. - `WordPress.CodeAnalysis.EmptyStatement` sniff to the `WordPress-Extra` ruleset to detect - and auto-fix - superfluous semi-colons and empty PHP open-close tag combinations. - `WordPress.NamingConventions.PrefixAllGlobals` sniff to the `WordPress-Extra` ruleset to verify that all functions, classes, interfaces, traits, variables, constants and hook names which are declared/defined in the global namespace are prefixed with one of the prefixes provided via a custom property or via the command line. - To activate this sniff, [one or more allowed prefixes should be provided to the sniff](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#naming-conventions-prefix-everything-in-the-global-namespace). This can be done using a custom ruleset or via the command line. + To activate this sniff, [one or more allowed prefixes should be provided to the sniff](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#naming-conventions-prefix-everything-in-the-global-namespace). This can be done using a custom ruleset or via the command line. PHP superglobals and WP global variables are exempt from variable name prefixing. Deprecated hook names will also be disregarded when non-prefixed. Back-fills for known native PHP functionality is also accounted for. - For verified exceptions, [unprefixed code can be whitelisted](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Whitelisting-code-which-flags-errors#non-prefixed-functionclassvariableconstant-in-the-global-namespace). + For verified exceptions, [unprefixed code can be whitelisted](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Whitelisting-code-which-flags-errors#non-prefixed-functionclassvariableconstant-in-the-global-namespace). Code in unit test files is automatically exempt from this sniff. - `WordPress.WP.DeprecatedClasses` sniff to the `WordPress-Extra` ruleset to detect usage of deprecated WordPress classes. - `WordPress.WP.DeprecatedParameters` sniff to the `WordPress-Extra` ruleset to detect deprecated parameters being passed to WordPress functions with a value other than the expected default. @@ -696,7 +696,7 @@ If you are a maintainer of an external standard based on WPCS and any of your cu - Improved support for detecting issues in code using heredoc and/or nowdoc syntax. - Improved sniff efficiency, precision and performance for a number of sniffs. - Updated a few sniffs to take advantage of new features and fixes which are included in PHP_CodeSniffer 2.9.0. -- `WordPress.Files.Filename`: The "file name mirrors the class name prefixed with 'class'" check for PHP files containing a class will no longer be applied to typical unit test classes, i.e. for classes which extend `WP_UnitTestCase`, `PHPUnit_Framework_TestCase` and `PHPUnit\Framework\TestCase`. Additional test case base classes can be passed to the sniff using the new [`custom_test_class_whitelist` property](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#custom-unit-test-classes). +- `WordPress.Files.Filename`: The "file name mirrors the class name prefixed with 'class'" check for PHP files containing a class will no longer be applied to typical unit test classes, i.e. for classes which extend `WP_UnitTestCase`, `PHPUnit_Framework_TestCase` and `PHPUnit\Framework\TestCase`. Additional test case base classes can be passed to the sniff using the new [`custom_test_class_whitelist` property](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#custom-unit-test-classes). - The `WordPress.Files.FileName` sniff allows now for more theme-specific template hierarchy based file name exceptions. - The whitelist flag for the `WordPress.VIP.SlowQuery` sniff was `tax_query` which was unintuitive. This has now been changed to `slow query` to be in line with other whitelist flags. - The `WordPress.WhiteSpace.OperatorSpacing` sniff will now ignore operator spacing within `declare()` statements. @@ -705,7 +705,7 @@ If you are a maintainer of an external standard based on WPCS and any of your cu - The `WordPress.XSS.EscapeOutput` sniff will now also detect unescaped output when the short open echo tags ` [![Latest Stable Version](https://poser.pugx.org/wp-coding-standards/wpcs/v/stable)](https://packagist.org/packages/wp-coding-standards/wpcs) -[![Travis Build Status](https://travis-ci.org/WordPress-Coding-Standards/WordPress-Coding-Standards.svg?branch=master)](https://travis-ci.org/WordPress-Coding-Standards/WordPress-Coding-Standards) -[![Release Date of the Latest Version](https://img.shields.io/github/release-date/WordPress-Coding-Standards/WordPress-Coding-Standards.svg?maxAge=1800)](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/releases) +[![Travis Build Status](https://travis-ci.com/WordPress/WordPress-Coding-Standards.svg?branch=master)](https://travis-ci.com/WordPress/WordPress-Coding-Standards) +[![Release Date of the Latest Version](https://img.shields.io/github/release-date/WordPress/WordPress-Coding-Standards.svg?maxAge=1800)](https://github.com/WordPress/WordPress-Coding-Standards/releases) :construction: [![Latest Unstable Version](https://img.shields.io/badge/unstable-dev--develop-e68718.svg?maxAge=2419200)](https://packagist.org/packages/wp-coding-standards/wpcs#dev-develop) -[![Travis Build Status](https://travis-ci.org/WordPress-Coding-Standards/WordPress-Coding-Standards.svg?branch=develop)](https://travis-ci.org/WordPress-Coding-Standards/WordPress-Coding-Standards) -[![Last Commit to Unstable](https://img.shields.io/github/last-commit/WordPress-Coding-Standards/WordPress-Coding-Standards/develop.svg)](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/commits/develop) +[![Travis Build Status](https://travis-ci.com/WordPress/WordPress-Coding-Standards.svg?branch=develop)](https://travis-ci.com/WordPress/WordPress-Coding-Standards) +[![Last Commit to Unstable](https://img.shields.io/github/last-commit/WordPress/WordPress-Coding-Standards/develop.svg)](https://github.com/WordPress/WordPress-Coding-Standards/commits/develop) [![Minimum PHP Version](https://img.shields.io/packagist/php-v/wp-coding-standards/wpcs.svg?maxAge=3600)](https://packagist.org/packages/wp-coding-standards/wpcs) -[![Tested on PHP 5.4 to nightly](https://img.shields.io/badge/tested%20on-PHP%205.4%20|%205.5%20|%205.6%20|%207.0%20|%207.1%20|%207.2%20|%20nightly-green.svg?maxAge=2419200)](https://travis-ci.org/WordPress-Coding-Standards/WordPress-Coding-Standards) +[![Tested on PHP 5.4 to 7.4 snapshot](https://img.shields.io/badge/tested%20on-PHP%205.4%20|%205.5%20|%205.6%20|%207.0%20|%207.1%20|%207.2%20|%207.3%20|%207.4snapshot-green.svg?maxAge=2419200)](https://travis-ci.com/WordPress/WordPress-Coding-Standards) -[![License: MIT](https://poser.pugx.org/wp-coding-standards/wpcs/license)](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/LICENSE) +[![License: MIT](https://poser.pugx.org/wp-coding-standards/wpcs/license)](https://github.com/WordPress/WordPress-Coding-Standards/blob/develop/LICENSE) [![Total Downloads](https://poser.pugx.org/wp-coding-standards/wpcs/downloads)](https://packagist.org/packages/wp-coding-standards/wpcs/stats) -[![Number of Contributors](https://img.shields.io/github/contributors/WordPress-Coding-Standards/WordPress-Coding-Standards.svg?maxAge=3600)](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/graphs/contributors) +[![Number of Contributors](https://img.shields.io/github/contributors/WordPress/WordPress-Coding-Standards.svg?maxAge=3600)](https://github.com/WordPress/WordPress-Coding-Standards/graphs/contributors) @@ -48,12 +48,12 @@ This project is a collection of [PHP_CodeSniffer](https://github.com/squizlabs/P ## Project history - On 22nd April 2009, the original project from [Urban Giraffe](https://urbangiraffe.com/articles/wordpress-codesniffer-standard/) was packaged and published. - - In May 2011 the project was forked and [added](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/commit/04fd547c691ca2baae3fa8e195a46b0c9dd671c5) to GitHub by [Chris Adams](https://chrisadams.me.uk/). + - In May 2011 the project was forked and [added](https://github.com/WordPress/WordPress-Coding-Standards/commit/04fd547c691ca2baae3fa8e195a46b0c9dd671c5) to GitHub by [Chris Adams](https://chrisadams.me.uk/). - In April 2012 [XWP](https://xwp.co/) started to dedicate resources to develop and lead the creation of the sniffs and rulesets for `WordPress-Core`, `WordPress-VIP` (WordPress.com VIP), and `WordPress-Extra`. - - In May 2015, an initial documentation ruleset was [added](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/commit/b1a4bf8232a22563ef66f8a529357275a49f47dc#diff-a17c358c3262a26e9228268eb0a7b8c8) as `WordPress-Docs`. + - In May 2015, an initial documentation ruleset was [added](https://github.com/WordPress/WordPress-Coding-Standards/commit/b1a4bf8232a22563ef66f8a529357275a49f47dc#diff-a17c358c3262a26e9228268eb0a7b8c8) as `WordPress-Docs`. - In 2015, [J.D. Grimes](https://github.com/JDGrimes) began significant contributions, along with maintenance from [Gary Jones](https://github.com/GaryJones). - In 2016, [Juliette Reinders Folmer](https://github.com/jrfnl) began contributing heavily, adding more commits in a year than anyone else in the five years since the project was added to GitHub. - - In July 2018, version [`1.0.0`](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/releases/tag/1.0.0) of the project was released. + - In July 2018, version [`1.0.0`](https://github.com/WordPress/WordPress-Coding-Standards/releases/tag/1.0.0) of the project was released. ## Installation @@ -94,7 +94,7 @@ It is strongly suggested to `require` one of these plugins in your project to ha 2. Clone the WordPress standards repository: - git clone -b master https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git wpcs + git clone -b master https://github.com/WordPress/WordPress-Coding-Standards.git wpcs 3. Add its path to the PHP_CodeSniffer configuration: @@ -110,7 +110,7 @@ To summarize: ```bash cd ~/projects git clone https://github.com/squizlabs/PHP_CodeSniffer.git phpcs -git clone -b master https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git wpcs +git clone -b master https://github.com/WordPress/WordPress-Coding-Standards.git wpcs cd phpcs ./bin/phpcs --config-set installed_paths ../wpcs ``` @@ -144,7 +144,7 @@ If you need to further customize the selection of sniffs for your project - you The WordPress Coding Standard contains a number of sniffs which are configurable. This means that you can turn parts of the sniff on or off, or change the behaviour by setting a property for the sniff in your custom `.phpcs.xml.dist` file. -You can find a complete list of all the properties you can change in the [wiki](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties). +You can find a complete list of all the properties you can change in the [wiki](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties). ### Recommended additional rulesets @@ -217,15 +217,15 @@ Will result in following output: ### Using PHPCS and WPCS from within your IDE * **PhpStorm** : Please see "[PHP Code Sniffer with WordPress Coding Standards Integration](https://confluence.jetbrains.com/display/PhpStorm/WordPress+Development+using+PhpStorm#WordPressDevelopmentusingPhpStorm-PHPCodeSnifferwithWordPressCodingStandardsIntegrationinPhpStorm)" in the PhpStorm documentation. -* **Sublime Text** : Please see "[Setting up WPCS to work in Sublime Text](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Setting-up-WPCS-to-work-in-Sublime-Text)" in the wiki. -* **Atom**: Please see "[Setting up WPCS to work in Atom](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Setting-up-WPCS-to-work-in-Atom)" in the wiki. +* **Sublime Text** : Please see "[Setting up WPCS to work in Sublime Text](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Setting-up-WPCS-to-work-in-Sublime-Text)" in the wiki. +* **Atom**: Please see "[Setting up WPCS to work in Atom](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Setting-up-WPCS-to-work-in-Atom)" in the wiki. * **Visual Studio**: Please see "[Setting up PHP CodeSniffer in Visual Studio Code](https://tommcfarlin.com/php-codesniffer-in-visual-studio-code/)", a tutorial by Tom McFarlin. -* **Eclipse with XAMPP**: Please see "[Setting up WPCS when using Eclipse with XAMPP](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/How-to-use-WPCS-with-Eclipse-and-XAMPP)" in the wiki. +* **Eclipse with XAMPP**: Please see "[Setting up WPCS when using Eclipse with XAMPP](https://github.com/WordPress/WordPress-Coding-Standards/wiki/How-to-use-WPCS-with-Eclipse-and-XAMPP)" in the wiki. ## Running your code through WPCS automatically using CI tools -### [Travis CI](https://travis-ci.org/) +### [Travis CI](https://travis-ci.com/) To integrate PHPCS with WPCS with Travis CI, you'll need to install both `before_install` and add the run command to the `script`. If your project uses Composer, the typical instructions might be different. @@ -249,7 +249,7 @@ before_install: # Install PHP_CodeSniffer. - if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git $PHPCS_DIR; fi # Install WordPress Coding Standards. - - if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git $SNIFFS_DIR; fi + - if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/WordPress/WordPress-Coding-Standards.git $SNIFFS_DIR; fi # Set install path for WordPress Coding Standards. - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/bin/phpcs --config-set installed_paths $SNIFFS_DIR; fi # After CodeSniffer install you should refresh your path. @@ -269,7 +269,7 @@ More examples and advice about integrating PHPCS in your Travis build tests can ## Fixing errors or whitelisting them -You can find information on how to deal with some of the more frequent issues in the [wiki](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki). +You can find information on how to deal with some of the more frequent issues in the [wiki](https://github.com/WordPress/WordPress-Coding-Standards/wiki). ### Tools shipped with WPCS diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index 9a3485b353..24ceda47b6 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -17,7 +17,7 @@ + https://github.com/WordPress/WordPress-Coding-Standards/issues/527 --> + https://github.com/WordPress/WordPress-Coding-Standards/issues/1330 --> + https://github.com/WordPress/WordPress-Coding-Standards/issues/632 --> @@ -276,11 +276,11 @@ ############################################################################# --> + https://github.com/WordPress/WordPress-Coding-Standards/issues/639 --> + https://github.com/WordPress/WordPress-Coding-Standards/issues/640 --> @@ -325,10 +325,10 @@ Hyphens should separate words. --> + https://github.com/WordPress/WordPress-Coding-Standards/issues/642 --> + https://github.com/WordPress/WordPress-Coding-Standards/issues/642 --> @@ -345,7 +345,7 @@ Handbook: PHP - Interpolation for Naming Dynamic Hooks. Ref: https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#interpolation-for-naming-dynamic-hooks - https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/751 + https://github.com/WordPress/WordPress-Coding-Standards/issues/751 ############################################################################# --> @@ -365,7 +365,7 @@ --> + https://github.com/WordPress/WordPress-Coding-Standards/issues/643 --> + https://github.com/WordPress/WordPress-Coding-Standards/issues/607 --> diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index ffdb2310bf..c43d6c6803 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -6,7 +6,7 @@ + https://github.com/WordPress/WordPress-Coding-Standards/pull/382 --> @@ -25,18 +25,18 @@ + https://github.com/WordPress/WordPress-Coding-Standards/issues/607 --> + https://github.com/WordPress/WordPress-Coding-Standards/pull/809 --> + https://github.com/WordPress/WordPress-Coding-Standards/issues/1143 --> warning @@ -49,11 +49,11 @@ + https://github.com/WordPress/WordPress-Coding-Standards/issues/1153 --> - + @@ -63,7 +63,7 @@ + https://github.com/WordPress/WordPress-Coding-Standards/issues/1101 --> @@ -78,11 +78,11 @@ + https://github.com/WordPress/WordPress-Coding-Standards/pull/1264 --> + https://github.com/WordPress/WordPress-Coding-Standards/issues/73 --> @@ -96,27 +96,27 @@ + https://github.com/WordPress/WordPress-Coding-Standards/issues/35 --> + https://github.com/WordPress/WordPress-Coding-Standards/issues/26 --> + https://github.com/WordPress/WordPress-Coding-Standards/issues/1447 --> + https://github.com/WordPress/WordPress-Coding-Standards/issues/1146 --> + https://github.com/WordPress/WordPress-Coding-Standards/pull/646 --> + https://github.com/WordPress/WordPress-Coding-Standards/issues/522 --> @@ -131,7 +131,7 @@ - + + https://github.com/WordPress/WordPress-Coding-Standards/issues/1371 --> + https://github.com/WordPress/WordPress-Coding-Standards/pull/1450 --> @@ -160,7 +160,7 @@ + https://github.com/WordPress/WordPress-Coding-Standards/pull/1463 --> diff --git a/WordPress/AbstractArrayAssignmentRestrictionsSniff.php b/WordPress/AbstractArrayAssignmentRestrictionsSniff.php index 6095db0d72..7c662cd0f5 100644 --- a/WordPress/AbstractArrayAssignmentRestrictionsSniff.php +++ b/WordPress/AbstractArrayAssignmentRestrictionsSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/AbstractClassRestrictionsSniff.php b/WordPress/AbstractClassRestrictionsSniff.php index ad46cb83a4..9374622e1f 100644 --- a/WordPress/AbstractClassRestrictionsSniff.php +++ b/WordPress/AbstractClassRestrictionsSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/AbstractFunctionParameterSniff.php b/WordPress/AbstractFunctionParameterSniff.php index 5c059a6df2..482ba0080a 100644 --- a/WordPress/AbstractFunctionParameterSniff.php +++ b/WordPress/AbstractFunctionParameterSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/AbstractFunctionRestrictionsSniff.php b/WordPress/AbstractFunctionRestrictionsSniff.php index 4553e3f472..e208c90ac1 100644 --- a/WordPress/AbstractFunctionRestrictionsSniff.php +++ b/WordPress/AbstractFunctionRestrictionsSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/PHPCSHelper.php b/WordPress/PHPCSHelper.php index 1e79685f46..1599a97a1b 100644 --- a/WordPress/PHPCSHelper.php +++ b/WordPress/PHPCSHelper.php @@ -3,7 +3,7 @@ * PHPCS cross-version compatibility helper class. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 8c3a86cb40..c271e9c562 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -3,7 +3,7 @@ * Represents a PHP_CodeSniffer sniff for sniffing WordPress coding standards. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php index f5c6257f3c..3b3c5aaa47 100644 --- a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php b/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php index 2285a7cc79..08c85213e1 100644 --- a/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php b/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php index b209409368..7e990d0dfc 100644 --- a/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php b/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php index 296a406105..16baac99ad 100644 --- a/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php +++ b/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/Arrays/MultipleStatementAlignmentSniff.php b/WordPress/Sniffs/Arrays/MultipleStatementAlignmentSniff.php index ccecf224a7..c5bd8380fe 100644 --- a/WordPress/Sniffs/Arrays/MultipleStatementAlignmentSniff.php +++ b/WordPress/Sniffs/Arrays/MultipleStatementAlignmentSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/Classes/ClassInstantiationSniff.php b/WordPress/Sniffs/Classes/ClassInstantiationSniff.php index 37b942f6f0..3572fbeed2 100644 --- a/WordPress/Sniffs/Classes/ClassInstantiationSniff.php +++ b/WordPress/Sniffs/Classes/ClassInstantiationSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/CodeAnalysis/AssignmentInConditionSniff.php b/WordPress/Sniffs/CodeAnalysis/AssignmentInConditionSniff.php index fa3d9db7f5..bf5879b8df 100644 --- a/WordPress/Sniffs/CodeAnalysis/AssignmentInConditionSniff.php +++ b/WordPress/Sniffs/CodeAnalysis/AssignmentInConditionSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php b/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php index 2b92e1c7a1..b9e99f7fb4 100644 --- a/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php +++ b/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php b/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php index 35b4e6447b..c6fe9c7a87 100644 --- a/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php +++ b/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php b/WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php index 405eb094d0..8f184c6be7 100644 --- a/WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php +++ b/WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/DB/PreparedSQLSniff.php b/WordPress/Sniffs/DB/PreparedSQLSniff.php index 5ddf1d92fc..a3ed993542 100644 --- a/WordPress/Sniffs/DB/PreparedSQLSniff.php +++ b/WordPress/Sniffs/DB/PreparedSQLSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/DB/RestrictedClassesSniff.php b/WordPress/Sniffs/DB/RestrictedClassesSniff.php index 564a629ace..5ae13ee57b 100644 --- a/WordPress/Sniffs/DB/RestrictedClassesSniff.php +++ b/WordPress/Sniffs/DB/RestrictedClassesSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/DB/RestrictedFunctionsSniff.php b/WordPress/Sniffs/DB/RestrictedFunctionsSniff.php index 1981f3a8e0..dbab49fec9 100644 --- a/WordPress/Sniffs/DB/RestrictedFunctionsSniff.php +++ b/WordPress/Sniffs/DB/RestrictedFunctionsSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/DB/SlowDBQuerySniff.php b/WordPress/Sniffs/DB/SlowDBQuerySniff.php index d0e547d4a7..4feebdcb60 100644 --- a/WordPress/Sniffs/DB/SlowDBQuerySniff.php +++ b/WordPress/Sniffs/DB/SlowDBQuerySniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/Files/FileNameSniff.php b/WordPress/Sniffs/Files/FileNameSniff.php index 43eb1061b9..598bc39bda 100644 --- a/WordPress/Sniffs/Files/FileNameSniff.php +++ b/WordPress/Sniffs/Files/FileNameSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index 4655f953dd..a00f0cf2ad 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php index 645bed3d9d..c88835cb6f 100644 --- a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php index 0103108a35..88ab8394e4 100644 --- a/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index dad06cac71..34314ff186 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/PHP/DevelopmentFunctionsSniff.php b/WordPress/Sniffs/PHP/DevelopmentFunctionsSniff.php index 79fe642bca..59e914dcf7 100644 --- a/WordPress/Sniffs/PHP/DevelopmentFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/DevelopmentFunctionsSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php b/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php index e2691c2e60..39f87c098d 100644 --- a/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/PHP/DontExtractSniff.php b/WordPress/Sniffs/PHP/DontExtractSniff.php index 0b9b984b3a..af2233bbe1 100644 --- a/WordPress/Sniffs/PHP/DontExtractSniff.php +++ b/WordPress/Sniffs/PHP/DontExtractSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/PHP/IniSetSniff.php b/WordPress/Sniffs/PHP/IniSetSniff.php index afd58f1bf8..79841b5396 100644 --- a/WordPress/Sniffs/PHP/IniSetSniff.php +++ b/WordPress/Sniffs/PHP/IniSetSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php b/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php index cc7b5fcb0c..6e0dba4679 100644 --- a/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php +++ b/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php b/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php index aade23c63c..9fb1cdcbeb 100644 --- a/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/PHP/PregQuoteDelimiterSniff.php b/WordPress/Sniffs/PHP/PregQuoteDelimiterSniff.php index f5e1a5a8ce..af88c404ac 100644 --- a/WordPress/Sniffs/PHP/PregQuoteDelimiterSniff.php +++ b/WordPress/Sniffs/PHP/PregQuoteDelimiterSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php b/WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php index 27faaa51a6..b7f3bb14a1 100644 --- a/WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/PHP/StrictComparisonsSniff.php b/WordPress/Sniffs/PHP/StrictComparisonsSniff.php index 97f3c4e406..85fe055490 100644 --- a/WordPress/Sniffs/PHP/StrictComparisonsSniff.php +++ b/WordPress/Sniffs/PHP/StrictComparisonsSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/PHP/StrictInArraySniff.php b/WordPress/Sniffs/PHP/StrictInArraySniff.php index f50ce14b9f..d7c12056aa 100644 --- a/WordPress/Sniffs/PHP/StrictInArraySniff.php +++ b/WordPress/Sniffs/PHP/StrictInArraySniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/PHP/TypeCastsSniff.php b/WordPress/Sniffs/PHP/TypeCastsSniff.php index 47376ff39c..7aded55fec 100644 --- a/WordPress/Sniffs/PHP/TypeCastsSniff.php +++ b/WordPress/Sniffs/PHP/TypeCastsSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/PHP/YodaConditionsSniff.php b/WordPress/Sniffs/PHP/YodaConditionsSniff.php index 0587da884d..c85ee6027e 100644 --- a/WordPress/Sniffs/PHP/YodaConditionsSniff.php +++ b/WordPress/Sniffs/PHP/YodaConditionsSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/Security/EscapeOutputSniff.php b/WordPress/Sniffs/Security/EscapeOutputSniff.php index d1dae3af85..09a7cbd0ea 100644 --- a/WordPress/Sniffs/Security/EscapeOutputSniff.php +++ b/WordPress/Sniffs/Security/EscapeOutputSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/Security/NonceVerificationSniff.php b/WordPress/Sniffs/Security/NonceVerificationSniff.php index e9b2cf6603..15f4a60408 100644 --- a/WordPress/Sniffs/Security/NonceVerificationSniff.php +++ b/WordPress/Sniffs/Security/NonceVerificationSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/Security/PluginMenuSlugSniff.php b/WordPress/Sniffs/Security/PluginMenuSlugSniff.php index 1d6edf0957..d22402efc8 100644 --- a/WordPress/Sniffs/Security/PluginMenuSlugSniff.php +++ b/WordPress/Sniffs/Security/PluginMenuSlugSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/Security/SafeRedirectSniff.php b/WordPress/Sniffs/Security/SafeRedirectSniff.php index 4d14631356..2f6aa6a686 100644 --- a/WordPress/Sniffs/Security/SafeRedirectSniff.php +++ b/WordPress/Sniffs/Security/SafeRedirectSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php b/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php index 4b65ac65be..a545c58078 100644 --- a/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php +++ b/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ @@ -15,7 +15,7 @@ /** * Flag any non-validated/sanitized input ( _GET / _POST / etc. ). * - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/69 + * @link https://github.com/WordPress/WordPress-Coding-Standards/issues/69 * * @package WPCS\WordPressCodingStandards * diff --git a/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php b/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php index 8437b4d249..b01e066126 100644 --- a/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php +++ b/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php index 52e1356f21..43ad575cd3 100644 --- a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php +++ b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/WP/CapitalPDangitSniff.php b/WordPress/Sniffs/WP/CapitalPDangitSniff.php index 3c270154a1..edbd3ebe97 100644 --- a/WordPress/Sniffs/WP/CapitalPDangitSniff.php +++ b/WordPress/Sniffs/WP/CapitalPDangitSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/WP/CronIntervalSniff.php b/WordPress/Sniffs/WP/CronIntervalSniff.php index d7e91b8321..7cfdddd919 100644 --- a/WordPress/Sniffs/WP/CronIntervalSniff.php +++ b/WordPress/Sniffs/WP/CronIntervalSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/WP/DeprecatedClassesSniff.php b/WordPress/Sniffs/WP/DeprecatedClassesSniff.php index cd69ba988b..7a13aa5727 100644 --- a/WordPress/Sniffs/WP/DeprecatedClassesSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedClassesSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php b/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php index 8525dc33bb..641edbfbfd 100644 --- a/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php b/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php index 01a2f7f860..2d567cbca1 100644 --- a/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/WP/DeprecatedParametersSniff.php b/WordPress/Sniffs/WP/DeprecatedParametersSniff.php index b6918cdb39..a6ba90aa4c 100644 --- a/WordPress/Sniffs/WP/DeprecatedParametersSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedParametersSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php b/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php index 6539b49cc5..f2f8dc64a8 100644 --- a/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php +++ b/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/WP/DiscouragedFunctionsSniff.php b/WordPress/Sniffs/WP/DiscouragedFunctionsSniff.php index ba640858f6..89d8e09c47 100644 --- a/WordPress/Sniffs/WP/DiscouragedFunctionsSniff.php +++ b/WordPress/Sniffs/WP/DiscouragedFunctionsSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php b/WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php index 0a0d0a6245..7b85aded0b 100644 --- a/WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php +++ b/WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php index e8d0333ad4..27572e95d1 100644 --- a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php +++ b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php index 57b64d07a5..8392324d90 100644 --- a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php +++ b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/WP/I18nSniff.php b/WordPress/Sniffs/WP/I18nSniff.php index 01797b5f78..6d0bc1946b 100644 --- a/WordPress/Sniffs/WP/I18nSniff.php +++ b/WordPress/Sniffs/WP/I18nSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/WP/PostsPerPageSniff.php b/WordPress/Sniffs/WP/PostsPerPageSniff.php index 8e45afe78d..968a0342b9 100644 --- a/WordPress/Sniffs/WP/PostsPerPageSniff.php +++ b/WordPress/Sniffs/WP/PostsPerPageSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/WP/TimezoneChangeSniff.php b/WordPress/Sniffs/WP/TimezoneChangeSniff.php index c57f8556cb..5712df975c 100644 --- a/WordPress/Sniffs/WP/TimezoneChangeSniff.php +++ b/WordPress/Sniffs/WP/TimezoneChangeSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php index 0aa4ff9cc2..c19f0f821a 100755 --- a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php index b0654ae4f1..29e9240057 100644 --- a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php b/WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php index 6539def540..c20a4d33e6 100644 --- a/WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php +++ b/WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php index 26c12e20b1..17e5090c72 100644 --- a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php b/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php index 5df4a72fea..010ec9438b 100644 --- a/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php +++ b/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php @@ -3,7 +3,7 @@ * WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php index 713d8b8cb5..2c521e0357 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/Arrays/ArrayIndentationUnitTest.php b/WordPress/Tests/Arrays/ArrayIndentationUnitTest.php index 3b6983ff21..4bc179dca2 100644 --- a/WordPress/Tests/Arrays/ArrayIndentationUnitTest.php +++ b/WordPress/Tests/Arrays/ArrayIndentationUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/Arrays/ArrayKeySpacingRestrictionsUnitTest.php b/WordPress/Tests/Arrays/ArrayKeySpacingRestrictionsUnitTest.php index a688f67ef1..958f5abab7 100644 --- a/WordPress/Tests/Arrays/ArrayKeySpacingRestrictionsUnitTest.php +++ b/WordPress/Tests/Arrays/ArrayKeySpacingRestrictionsUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/Arrays/CommaAfterArrayItemUnitTest.php b/WordPress/Tests/Arrays/CommaAfterArrayItemUnitTest.php index 7763f55ee5..fa5905d91a 100644 --- a/WordPress/Tests/Arrays/CommaAfterArrayItemUnitTest.php +++ b/WordPress/Tests/Arrays/CommaAfterArrayItemUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.php b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.php index bc6cc60268..62eda13d2b 100644 --- a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.php +++ b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/Classes/ClassInstantiationUnitTest.php b/WordPress/Tests/Classes/ClassInstantiationUnitTest.php index d06cb98de0..21b74950e7 100644 --- a/WordPress/Tests/Classes/ClassInstantiationUnitTest.php +++ b/WordPress/Tests/Classes/ClassInstantiationUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/CodeAnalysis/AssignmentInConditionUnitTest.php b/WordPress/Tests/CodeAnalysis/AssignmentInConditionUnitTest.php index f92dcbeb02..57785b8370 100644 --- a/WordPress/Tests/CodeAnalysis/AssignmentInConditionUnitTest.php +++ b/WordPress/Tests/CodeAnalysis/AssignmentInConditionUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php b/WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php index 22ca38d56c..7c0d72be94 100644 --- a/WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php +++ b/WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/DB/DirectDatabaseQueryUnitTest.php b/WordPress/Tests/DB/DirectDatabaseQueryUnitTest.php index bb527e39f1..cf15554f92 100644 --- a/WordPress/Tests/DB/DirectDatabaseQueryUnitTest.php +++ b/WordPress/Tests/DB/DirectDatabaseQueryUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php b/WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php index 3259bb0b5c..1cf42f021f 100644 --- a/WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php +++ b/WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/DB/PreparedSQLUnitTest.php b/WordPress/Tests/DB/PreparedSQLUnitTest.php index f525dde0e6..03f7c6d8fa 100644 --- a/WordPress/Tests/DB/PreparedSQLUnitTest.php +++ b/WordPress/Tests/DB/PreparedSQLUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/DB/RestrictedClassesUnitTest.php b/WordPress/Tests/DB/RestrictedClassesUnitTest.php index c15d35543a..b5df274d02 100644 --- a/WordPress/Tests/DB/RestrictedClassesUnitTest.php +++ b/WordPress/Tests/DB/RestrictedClassesUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php b/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php index 362500ecfc..5149dbb8fb 100644 --- a/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php +++ b/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/DB/SlowDBQueryUnitTest.php b/WordPress/Tests/DB/SlowDBQueryUnitTest.php index 24af5c213d..987e4d412d 100644 --- a/WordPress/Tests/DB/SlowDBQueryUnitTest.php +++ b/WordPress/Tests/DB/SlowDBQueryUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/Files/FileNameUnitTest.php b/WordPress/Tests/Files/FileNameUnitTest.php index af0a46c2f2..3d26c76efe 100644 --- a/WordPress/Tests/Files/FileNameUnitTest.php +++ b/WordPress/Tests/Files/FileNameUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php index 6db20b24ae..aa169b940d 100644 --- a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php +++ b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php index 10649e220d..0c1db47bc7 100644 --- a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php +++ b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php index 565c4ccf6e..dfa253c850 100644 --- a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php +++ b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php index 934826f5d4..85e1d22524 100644 --- a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php +++ b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php b/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php index aef75ef7e1..c008eb6afa 100644 --- a/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php b/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php index 0b43deffe5..1670834cd2 100644 --- a/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/PHP/DontExtractUnitTest.php b/WordPress/Tests/PHP/DontExtractUnitTest.php index c8862b6b7f..6654bdac00 100644 --- a/WordPress/Tests/PHP/DontExtractUnitTest.php +++ b/WordPress/Tests/PHP/DontExtractUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/PHP/IniSetUnitTest.php b/WordPress/Tests/PHP/IniSetUnitTest.php index 4543d44a7e..11c1f75218 100644 --- a/WordPress/Tests/PHP/IniSetUnitTest.php +++ b/WordPress/Tests/PHP/IniSetUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.php b/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.php index b9db72b0f5..5bd5ddfc84 100644 --- a/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.php +++ b/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/PHP/POSIXFunctionsUnitTest.php b/WordPress/Tests/PHP/POSIXFunctionsUnitTest.php index 13dbdecc3c..e9df9b0d5a 100644 --- a/WordPress/Tests/PHP/POSIXFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/POSIXFunctionsUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.php b/WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.php index 0615bbca22..a4b4ac6160 100644 --- a/WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.php +++ b/WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php index 30ad0b2b00..3d21aa7195 100644 --- a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/PHP/StrictComparisonsUnitTest.php b/WordPress/Tests/PHP/StrictComparisonsUnitTest.php index 79a42f6991..b7ada4d896 100644 --- a/WordPress/Tests/PHP/StrictComparisonsUnitTest.php +++ b/WordPress/Tests/PHP/StrictComparisonsUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/PHP/StrictInArrayUnitTest.php b/WordPress/Tests/PHP/StrictInArrayUnitTest.php index 66c9ed19b7..7394afeda5 100644 --- a/WordPress/Tests/PHP/StrictInArrayUnitTest.php +++ b/WordPress/Tests/PHP/StrictInArrayUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/PHP/TypeCastsUnitTest.php b/WordPress/Tests/PHP/TypeCastsUnitTest.php index 5f681f8d7f..9349f1b838 100644 --- a/WordPress/Tests/PHP/TypeCastsUnitTest.php +++ b/WordPress/Tests/PHP/TypeCastsUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/PHP/YodaConditionsUnitTest.php b/WordPress/Tests/PHP/YodaConditionsUnitTest.php index 9640da2b7d..cab9a34b36 100644 --- a/WordPress/Tests/PHP/YodaConditionsUnitTest.php +++ b/WordPress/Tests/PHP/YodaConditionsUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/Security/EscapeOutputUnitTest.php b/WordPress/Tests/Security/EscapeOutputUnitTest.php index 52b554be55..1d803fc349 100644 --- a/WordPress/Tests/Security/EscapeOutputUnitTest.php +++ b/WordPress/Tests/Security/EscapeOutputUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/Security/NonceVerificationUnitTest.php b/WordPress/Tests/Security/NonceVerificationUnitTest.php index 964ab9501a..c3fb8a67b0 100644 --- a/WordPress/Tests/Security/NonceVerificationUnitTest.php +++ b/WordPress/Tests/Security/NonceVerificationUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/Security/PluginMenuSlugUnitTest.php b/WordPress/Tests/Security/PluginMenuSlugUnitTest.php index 9141fa90a1..3b81976073 100644 --- a/WordPress/Tests/Security/PluginMenuSlugUnitTest.php +++ b/WordPress/Tests/Security/PluginMenuSlugUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/Security/SafeRedirectUnitTest.php b/WordPress/Tests/Security/SafeRedirectUnitTest.php index 14e4686f11..d16634cbe5 100644 --- a/WordPress/Tests/Security/SafeRedirectUnitTest.php +++ b/WordPress/Tests/Security/SafeRedirectUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php index ca0821bd59..493465ea3f 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php b/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php index 7f13fe3e88..88df73124d 100644 --- a/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php +++ b/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php index 55107f0f6a..98f42d5633 100644 --- a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php +++ b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/WP/CapitalPDangitUnitTest.php b/WordPress/Tests/WP/CapitalPDangitUnitTest.php index 1139ee348e..0f7454a6ae 100644 --- a/WordPress/Tests/WP/CapitalPDangitUnitTest.php +++ b/WordPress/Tests/WP/CapitalPDangitUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/WP/CronIntervalUnitTest.php b/WordPress/Tests/WP/CronIntervalUnitTest.php index 704923cc5f..afbf6a6b69 100644 --- a/WordPress/Tests/WP/CronIntervalUnitTest.php +++ b/WordPress/Tests/WP/CronIntervalUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/WP/DeprecatedClassesUnitTest.php b/WordPress/Tests/WP/DeprecatedClassesUnitTest.php index c70673deb2..b58576ccf2 100644 --- a/WordPress/Tests/WP/DeprecatedClassesUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedClassesUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php index ba45e47476..b3b217c7cf 100644 --- a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.php b/WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.php index f128e6fb34..dd3c909379 100644 --- a/WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/WP/DeprecatedParametersUnitTest.php b/WordPress/Tests/WP/DeprecatedParametersUnitTest.php index af86abf2e5..e91ad712cf 100644 --- a/WordPress/Tests/WP/DeprecatedParametersUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedParametersUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/WP/DiscouragedConstantsUnitTest.php b/WordPress/Tests/WP/DiscouragedConstantsUnitTest.php index 8437893bb0..9d48851857 100644 --- a/WordPress/Tests/WP/DiscouragedConstantsUnitTest.php +++ b/WordPress/Tests/WP/DiscouragedConstantsUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.php b/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.php index 4491430637..f081e22da8 100644 --- a/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.php +++ b/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/WP/EnqueuedResourceParametersUnitTest.php b/WordPress/Tests/WP/EnqueuedResourceParametersUnitTest.php index 8e60e6b57d..5fa96cd25c 100644 --- a/WordPress/Tests/WP/EnqueuedResourceParametersUnitTest.php +++ b/WordPress/Tests/WP/EnqueuedResourceParametersUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/WP/EnqueuedResourcesUnitTest.php b/WordPress/Tests/WP/EnqueuedResourcesUnitTest.php index 2b0da6f255..2ca0095815 100644 --- a/WordPress/Tests/WP/EnqueuedResourcesUnitTest.php +++ b/WordPress/Tests/WP/EnqueuedResourcesUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.1.inc b/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.1.inc index 3d6609e715..321054f812 100644 --- a/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.1.inc +++ b/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.1.inc @@ -39,7 +39,7 @@ function global_vars() { } // Test against cross-contamination of global detection. -// https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/486 +// https://github.com/WordPress/WordPress-Coding-Standards/issues/486 function local_var_only() { $pagenow = 'test'; // Ok, function scope. } @@ -58,7 +58,7 @@ add_filter( 'comments_open', function( $open, $post_id ) { $closure = function() { $page = 'test' }; // Ok, check against cross-contaminiation from within a closure. // Allow overriding globals in functions within unit test classes. -// https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/300#issuecomment-158778606 +// https://github.com/WordPress/WordPress-Coding-Standards/issues/300#issuecomment-158778606 trait WP_UnitTestCase { public function test_something() { @@ -177,7 +177,7 @@ function global_vars() { $closure = function ( $pagenow ) { // OK, local to the closure. $pagenow = 'something'; // OK, local to the closure. }; - + $pagenow = 'something else'; // Bad. return $closure( $pagenow ); // OK, not an assignment. diff --git a/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php b/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php index 0f77e278e0..b29c957436 100644 --- a/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php +++ b/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/WP/I18nUnitTest.php b/WordPress/Tests/WP/I18nUnitTest.php index bab594676f..6f986b8868 100644 --- a/WordPress/Tests/WP/I18nUnitTest.php +++ b/WordPress/Tests/WP/I18nUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/WP/PostsPerPageUnitTest.php b/WordPress/Tests/WP/PostsPerPageUnitTest.php index 22dd5c0715..212408ed84 100644 --- a/WordPress/Tests/WP/PostsPerPageUnitTest.php +++ b/WordPress/Tests/WP/PostsPerPageUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/WP/TimezoneChangeUnitTest.php b/WordPress/Tests/WP/TimezoneChangeUnitTest.php index 2b623f644a..81e86d1e6e 100644 --- a/WordPress/Tests/WP/TimezoneChangeUnitTest.php +++ b/WordPress/Tests/WP/TimezoneChangeUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.php index b90f1c1148..8a06a67409 100644 --- a/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.php +++ b/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc index ab0d8568b6..20d16585e0 100644 --- a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc +++ b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc @@ -5,7 +5,7 @@ while( have_posts() ) { // Okay, comments are okay here. // Okay, comments are okay here as well. } // Okay, comments are okay here. -// See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/40 . +// See https://github.com/WordPress/WordPress-Coding-Standards/issues/40 . if ( true ) { // code. diff --git a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc.fixed b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc.fixed index ef625e6362..94e7256ca9 100644 --- a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc.fixed +++ b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc.fixed @@ -5,7 +5,7 @@ while ( have_posts() ) { // Okay, comments are okay here. // Okay, comments are okay here as well. } // Okay, comments are okay here. -// See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/40 . +// See https://github.com/WordPress/WordPress-Coding-Standards/issues/40 . if ( true ) { // code. diff --git a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php index e295978e2b..d98d8417e8 100644 --- a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php +++ b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php b/WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php index 5f360ca429..edaac2c7ea 100644 --- a/WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php +++ b/WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php index 421c61fd8d..f31f3f4992 100644 --- a/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php +++ b/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php index 1da0d8fbeb..a7ed8c5601 100644 --- a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php +++ b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php @@ -3,7 +3,7 @@ * Unit test class for WordPress Coding Standard. * * @package WPCS\WordPressCodingStandards - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @link https://github.com/WordPress/WordPress-Coding-Standards * @license https://opensource.org/licenses/MIT MIT */ diff --git a/phpcs.xml.dist.sample b/phpcs.xml.dist.sample index e6e2ab99f6..a524efd077 100644 --- a/phpcs.xml.dist.sample +++ b/phpcs.xml.dist.sample @@ -68,7 +68,7 @@ For information on additional custom properties available, check out the wiki: - https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties + https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties --> From 0af5b18632cc0c981937035982d494b95078880d Mon Sep 17 00:00:00 2001 From: Andrey Savchenko Date: Tue, 2 Jul 2019 12:57:57 +0300 Subject: [PATCH 175/241] Added remaining plugin load globals --- WordPress/Sniff.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 7a8370ae6d..dde62b0af3 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -686,9 +686,11 @@ abstract class Sniff implements PHPCS_Sniff { 'mode' => true, 'monthnum' => true, 'more' => true, + 'mu_plugin' => true, 'multipage' => true, 'names' => true, 'nav_menu_selected_id' => true, + 'network_plugin' => true, 'new_whitelist_options' => true, 'numpages' => true, 'one_theme_location_no_menus' => true, From 8d861ab195ddc488fc36380fbefb6bd094451532 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 5 Jul 2019 01:29:57 +0200 Subject: [PATCH 176/241] WordPress ruleset: efficiency fix Rulesets are processed top-to-bottom, one rule at the time. For the `WordPress` ruleset, this means that PHPCS would first load the `WordPress-Core` ruleset and process all rules in that file, then read the `WordPress-Docs` ruleset and lastly, the `WordPress-Extra` ruleset. As the `WordPress-Extra` ruleset includes `WordPress-Core`, it would re-process the `WordPress-Core` ruleset a second time and then process the additional rules in the `Extra` ruleset. This means that in effect, the `WordPress-Core` ruleset is processed twice when using the `WordPress` ruleset which is inefficient. By commenting that rule out, we still document that the `WordPress` ruleset includes `WordPress-Core` without double processing the ruleset. --- WordPress/ruleset.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/WordPress/ruleset.xml b/WordPress/ruleset.xml index 80bfb8d3bf..fd24ae6318 100644 --- a/WordPress/ruleset.xml +++ b/WordPress/ruleset.xml @@ -3,7 +3,10 @@ WordPress Coding Standards + From bf3ef482d2d3012ddcf7447fd268cb41daedc86e Mon Sep 17 00:00:00 2001 From: Christopher Kanitz Date: Fri, 5 Jul 2019 12:42:00 +0200 Subject: [PATCH 177/241] Docs/WordPress.WhiteSpace.CastStructureSpacing (#1738) Adds documentation for the WordPress.WhiteSpace.CastStructureSpacing Related to #1722 --- .../CastStructureSpacingStandard.xml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 WordPress/Docs/WhiteSpace/CastStructureSpacingStandard.xml diff --git a/WordPress/Docs/WhiteSpace/CastStructureSpacingStandard.xml b/WordPress/Docs/WhiteSpace/CastStructureSpacingStandard.xml new file mode 100644 index 0000000000..f30f4dc3ba --- /dev/null +++ b/WordPress/Docs/WhiteSpace/CastStructureSpacingStandard.xml @@ -0,0 +1,19 @@ + + + + + + + (int) '420'; + ]]> + + + =(int) '420'; + ]]> + + + From d00b44ba67ae47faf7d2727faf0c9485a1e7f1d9 Mon Sep 17 00:00:00 2001 From: Christopher Kanitz Date: Fri, 5 Jul 2019 13:02:48 +0200 Subject: [PATCH 178/241] Docs/WordPress.WhiteSpace.PrecisionAlignment (#1725) Adds documentation for the WordPress.WhiteSpace.PrecisionAlignmentSniff Related to #1722 --- .../WhiteSpace/PrecisionAlignmentStandard.xml | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 WordPress/Docs/WhiteSpace/PrecisionAlignmentStandard.xml diff --git a/WordPress/Docs/WhiteSpace/PrecisionAlignmentStandard.xml b/WordPress/Docs/WhiteSpace/PrecisionAlignmentStandard.xml new file mode 100644 index 0000000000..ca819ffd7d --- /dev/null +++ b/WordPress/Docs/WhiteSpace/PrecisionAlignmentStandard.xml @@ -0,0 +1,31 @@ + + + + + + + [tab]$var = true; + ]]> + + + [space][space]$var = true; + ]]> + + + + + [tab][space][space][space][space]$var = true; + ]]> + + + [tab][space][space][space]$var = true; + ]]> + + + From d8baf910d0516325a7201e51d648ec07b2ed6582 Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Tue, 16 Jul 2019 17:17:10 +0200 Subject: [PATCH 179/241] Fixes #1733 - Error on short prefixes --- .../PrefixAllGlobalsSniff.php | 21 ++++++++++++++++ .../PrefixAllGlobalsUnitTest.1.inc | 25 +++++++++++++++++++ .../PrefixAllGlobalsUnitTest.php | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index a00f0cf2ad..305a16b908 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -33,6 +33,17 @@ class PrefixAllGlobalsSniff extends AbstractFunctionParameterSniff { */ const ERROR_MSG = '%s by a theme/plugin should start with the theme/plugin prefix. Found: "%s".'; + /** + * Minimal number of characters the prefix needs in order to be valid. + * + * @since 2.2.0 + * + * @link https://github.com/WordPress/WordPress-Coding-Standards/issues/1733 Issue 1733. + * + * @var int + */ + const MIN_PREFIX_LENGTH = 3; + /** * Target prefixes. * @@ -914,6 +925,16 @@ private function validate_prefixes() { continue; } + if ( function_exists( 'iconv_strlen' ) && iconv_strlen( $prefix, $this->phpcsFile->config->encoding ) < self::MIN_PREFIX_LENGTH ) { + $this->phpcsFile->addError( + 'The "%s" prefix is too short. Short prefixes are not unique enough and may cause name collisions with other code.', + 0, + 'ShortPrefixPassed', + array( $prefix ) + ); + continue; + } + // Validate the prefix against characters allowed for function, class, constant names etc. if ( preg_match( '`^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff\\\\]*$`', $prefix ) !== 1 ) { $this->phpcsFile->addWarning( diff --git a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc index 10b79f3a86..2ffac46aae 100644 --- a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc +++ b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc @@ -425,3 +425,28 @@ define( ); // phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] + +/* + * Bad: Issue https://github.com/WordPress/WordPress-Coding-Standards/issues/1733. + * + * Short prefixes are not allowed. The errors are triggered + * on LINE 1 for the unit-test, because it's the phpcs:set command that is + * wrong, not the implementing code. + */ +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] a +function a_do_something(){} + +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] aa +function aa_do_something(){} + +// The following line mimicks an empty prefix value. +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] , +function aa_do_something(){} + +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] 😊 +function 😊_do_something(){} + +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] 😊😊 +function 😊😊_do_something(){} + +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] diff --git a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php index aa169b940d..702b7abd5c 100644 --- a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php +++ b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php @@ -32,7 +32,7 @@ public function getErrorList( $testFile = 'PrefixAllGlobalsUnitTest.1.inc' ) { switch ( $testFile ) { case 'PrefixAllGlobalsUnitTest.1.inc': return array( - 1 => 2, // 1 x error for blacklisted prefix passed. + 1 => 8, // 2 x error for blacklisted prefix passed. 4 x error for short prefixes. 2 x no prefix. 10 => 1, 18 => 1, 21 => 1, From c8c576e9993a03ed3f21239ebe15b5a528d93edf Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Tue, 16 Jul 2019 17:28:08 +0200 Subject: [PATCH 180/241] Adds fallback for sniff when iconv is not available --- .../Sniffs/NamingConventions/PrefixAllGlobalsSniff.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index 305a16b908..82eb07ad1d 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -933,6 +933,14 @@ private function validate_prefixes() { array( $prefix ) ); continue; + } elseif ( ! function_exists( 'iconv_strlen' ) && strlen( $prefix, $this->phpcsFile->config->encoding ) < self::MIN_PREFIX_LENGTH ) { + $this->phpcsFile->addError( + 'The "%s" prefix is too short. Short prefixes are not unique enough and may cause name collisions with other code.', + 0, + 'ShortPrefixPassed', + array( $prefix ) + ); + continue; } // Validate the prefix against characters allowed for function, class, constant names etc. From 13a8bc10b54a3557f622e04fd700ca81828ac986 Mon Sep 17 00:00:00 2001 From: Christopher Kanitz Date: Thu, 18 Jul 2019 06:45:05 +0200 Subject: [PATCH 181/241] Docs/WordPress.WhiteSpace.DisallowInlineTabs (#1735) Adds documentation for the WordPress.WhiteSpace.DisallowInlineTabs sniff Related to #1722 --- .../WhiteSpace/DisallowInlineTabsStandard.xml | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 WordPress/Docs/WhiteSpace/DisallowInlineTabsStandard.xml diff --git a/WordPress/Docs/WhiteSpace/DisallowInlineTabsStandard.xml b/WordPress/Docs/WhiteSpace/DisallowInlineTabsStandard.xml new file mode 100644 index 0000000000..16f1da2fb9 --- /dev/null +++ b/WordPress/Docs/WhiteSpace/DisallowInlineTabsStandard.xml @@ -0,0 +1,25 @@ + + + + + + + [space]=> 'lor', + 'b'[space][space][space]=> 'em', +); + ]]> + + + [tab]=> 'lor', + 'b'[tab]=> 'em', +); + ]]> + + + From 42332cc9f518a10efa258e5cf7e9008571215f8d Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 20 Jul 2019 20:07:38 +0200 Subject: [PATCH 182/241] CastStructureSpacing: allow for no whitespace before a cast when used in combination with a spread operator Includes updated docs. Related 1762 Related 1524 --- WordPress/Docs/WhiteSpace/CastStructureSpacingStandard.xml | 4 ++++ WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php | 5 ++++- WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.inc | 2 ++ .../Tests/WhiteSpace/CastStructureSpacingUnitTest.inc.fixed | 2 ++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/WordPress/Docs/WhiteSpace/CastStructureSpacingStandard.xml b/WordPress/Docs/WhiteSpace/CastStructureSpacingStandard.xml index f30f4dc3ba..8539325b37 100644 --- a/WordPress/Docs/WhiteSpace/CastStructureSpacingStandard.xml +++ b/WordPress/Docs/WhiteSpace/CastStructureSpacingStandard.xml @@ -2,12 +2,16 @@ (int) '420'; + +// No space between spread operator and cast. +$a = function_call( ...(array) $mixed ); ]]> diff --git a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php index c19f0f821a..5231785a11 100755 --- a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php @@ -24,6 +24,7 @@ * @since 0.11.0 The error level for all errors thrown by this sniff has been raised from warning to error. * @since 0.12.0 This class now extends the WordPressCS native `Sniff` class. * @since 0.13.0 Class name changed: this class is now namespaced. + * @since 2.2.0 Added exception for whitespace between spread operator and cast. */ class CastStructureSpacingSniff extends Sniff { @@ -45,7 +46,9 @@ public function register() { */ public function process_token( $stackPtr ) { - if ( \T_WHITESPACE !== $this->tokens[ ( $stackPtr - 1 ) ]['code'] ) { + if ( \T_WHITESPACE !== $this->tokens[ ( $stackPtr - 1 ) ]['code'] + && \T_ELLIPSIS !== $this->tokens[ ( $stackPtr - 1 ) ]['code'] + ) { $error = 'No space before opening casting parenthesis is prohibited'; $fix = $this->phpcsFile->addFixableError( $error, $stackPtr, 'NoSpaceBeforeOpenParenthesis' ); if ( true === $fix ) { diff --git a/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.inc b/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.inc index b17bc2ce92..29c1ce52d5 100644 --- a/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.inc +++ b/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.inc @@ -20,3 +20,5 @@ $unset2 = (unset) $unset; // Ok. $float1 =(float )$float; // Bad; n.b. spacing within the cast is dealt with by an upstream sniff. $float2 = (float) $float; // Ok. + +function_call( ...(array) $mixed ); // OK. diff --git a/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.inc.fixed b/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.inc.fixed index a4ff985fe2..b596241f06 100644 --- a/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.inc.fixed +++ b/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.inc.fixed @@ -20,3 +20,5 @@ $unset2 = (unset) $unset; // Ok. $float1 = (float )$float; // Bad; n.b. spacing within the cast is dealt with by an upstream sniff. $float2 = (float) $float; // Ok. + +function_call( ...(array) $mixed ); // OK. From acbeee62c4985a62d1c142f898319978096ad5e9 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 20 Jul 2019 21:30:56 +0200 Subject: [PATCH 183/241] :sparkles: New DisallowShortTernary sniff This new sniff addresses the new "_The short ternary operator must not be used._" rule which was recently added to the handbook. The sniff has been added to the `WordPress-Core` ruleset. Refs: * https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#ternary-operator * https://make.wordpress.org/core/2019/07/12/php-coding-standards-changes/ Includes unit tests. Includes documentation. --- WordPress-Core/ruleset.xml | 2 + .../Docs/PHP/DisallowShortTernaryStandard.xml | 19 ++++++ .../Sniffs/PHP/DisallowShortTernarySniff.php | 65 +++++++++++++++++++ .../PHP/DisallowShortTernaryUnitTest.inc | 12 ++++ .../PHP/DisallowShortTernaryUnitTest.php | 46 +++++++++++++ 5 files changed, 144 insertions(+) create mode 100644 WordPress/Docs/PHP/DisallowShortTernaryStandard.xml create mode 100644 WordPress/Sniffs/PHP/DisallowShortTernarySniff.php create mode 100644 WordPress/Tests/PHP/DisallowShortTernaryUnitTest.inc create mode 100644 WordPress/Tests/PHP/DisallowShortTernaryUnitTest.php diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index 24ceda47b6..2c28c42b5b 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -367,6 +367,8 @@ An exception would be using ! empty(), as testing for false here is generally more intuitive. https://github.com/WordPress/WordPress-Coding-Standards/issues/643 --> + + + + + + + + + - From 75993cc487dad8603d09eab1cd914edf454e5131 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 12 Sep 2019 00:35:05 +0200 Subject: [PATCH 206/241] AlternativeFunctions: add extra unit test Just to be sure this was covered correctly (which it luckily was). --- WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc | 3 +++ WordPress/Tests/WP/AlternativeFunctionsUnitTest.php | 1 + 2 files changed, 4 insertions(+) diff --git a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc index a9646d98e9..7bfaf9b14d 100644 --- a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc +++ b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc @@ -68,3 +68,6 @@ readfile( 'php://filter/resource=http://www.example.com' ); // Warning. file_put_contents("php://filter/write=string.rot13/resource=example.txt","Hello World"); // Warning. curl_version(); // OK. + +// Safeguard that additional logic uses case-insensitive function name check. +Strip_Tags( $something ); // Warning. diff --git a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php index 98f42d5633..f25dec8cd3 100644 --- a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php +++ b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php @@ -63,6 +63,7 @@ public function getWarningList() { 49 => 1, 67 => 1, 68 => 1, + 73 => 1, ); } From 9a89756ee98302be652b6ab974151fc4feddca69 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 19 Sep 2019 23:47:23 +0200 Subject: [PATCH 207/241] YodaConditions: minor efficiency fix Performance: Don't unnecessarily use `array_merge()`. --- WordPress/Sniffs/PHP/YodaConditionsSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/Sniffs/PHP/YodaConditionsSniff.php b/WordPress/Sniffs/PHP/YodaConditionsSniff.php index c85ee6027e..9f3f3d10d3 100644 --- a/WordPress/Sniffs/PHP/YodaConditionsSniff.php +++ b/WordPress/Sniffs/PHP/YodaConditionsSniff.php @@ -108,7 +108,7 @@ public function process_token( $stackPtr ) { if ( \in_array( $this->tokens[ $next_non_empty ]['code'], array( \T_SELF, \T_PARENT, \T_STATIC ), true ) ) { $next_non_empty = $this->phpcsFile->findNext( - array_merge( Tokens::$emptyTokens, array( \T_DOUBLE_COLON ) ), + ( Tokens::$emptyTokens + array( \T_DOUBLE_COLON => \T_DOUBLE_COLON ) ), ( $next_non_empty + 1 ), null, true From dda05c132cc121f72fb051b49436537eb38bd0c4 Mon Sep 17 00:00:00 2001 From: jrfnl <663378+jrfnl@users.noreply.github.com> Date: Fri, 20 Sep 2019 14:00:15 +0200 Subject: [PATCH 208/241] Docs/Deprecated WP: various minor fixes to the XML docs --- .../Docs/WP/DeprecatedClassesStandard.xml | 10 +++---- .../Docs/WP/DeprecatedFunctionsStandard.xml | 8 +++--- .../WP/DeprecatedParameterValuesStandard.xml | 12 ++++----- .../Docs/WP/DeprecatedParametersStandard.xml | 27 +++++++++++++++---- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/WordPress/Docs/WP/DeprecatedClassesStandard.xml b/WordPress/Docs/WP/DeprecatedClassesStandard.xml index 42d57e56f1..4d06f6e35c 100644 --- a/WordPress/Docs/WP/DeprecatedClassesStandard.xml +++ b/WordPress/Docs/WP/DeprecatedClassesStandard.xml @@ -1,18 +1,18 @@ - + - + WP_User_Query(); ]]> - + WP_User_Search(); // Deprecated WP 3.1. ]]> diff --git a/WordPress/Docs/WP/DeprecatedFunctionsStandard.xml b/WordPress/Docs/WP/DeprecatedFunctionsStandard.xml index 7a0eaf9390..7fcc9c4e5b 100644 --- a/WordPress/Docs/WP/DeprecatedFunctionsStandard.xml +++ b/WordPress/Docs/WP/DeprecatedFunctionsStandard.xml @@ -5,14 +5,14 @@ ]]> - + get_sites(); ]]> - + wp_get_sites(); // Deprecated WP 4.6. ]]> diff --git a/WordPress/Docs/WP/DeprecatedParameterValuesStandard.xml b/WordPress/Docs/WP/DeprecatedParameterValuesStandard.xml index b084f2466c..0348fdffed 100644 --- a/WordPress/Docs/WP/DeprecatedParameterValuesStandard.xml +++ b/WordPress/Docs/WP/DeprecatedParameterValuesStandard.xml @@ -1,18 +1,18 @@ - + - + 'url' ); ]]> - + 'home' ); // Deprecated WP 2.2.0. ]]> diff --git a/WordPress/Docs/WP/DeprecatedParametersStandard.xml b/WordPress/Docs/WP/DeprecatedParametersStandard.xml index f754081c72..6399ca62fb 100644 --- a/WordPress/Docs/WP/DeprecatedParametersStandard.xml +++ b/WordPress/Docs/WP/DeprecatedParametersStandard.xml @@ -1,18 +1,35 @@ - + after the deprecated parameter, only ever pass the default value. ]]> - + - + $string ); // Deprecated WP 2.1 +// First - and only - parameter deprecated. +get_the_author( $string ); + ]]> + + + + + '', 'yes' ); + ]]> + + + 'oops', 'yes' ); ]]> From 54f1017ce3036481474e8926982bcb65fb7ad8cb Mon Sep 17 00:00:00 2001 From: jrfnl <663378+jrfnl@users.noreply.github.com> Date: Fri, 20 Sep 2019 15:56:58 +0200 Subject: [PATCH 209/241] DisallowShortTernary: improve docs The valid example line was a bit too long... oops... --- WordPress/Docs/PHP/DisallowShortTernaryStandard.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WordPress/Docs/PHP/DisallowShortTernaryStandard.xml b/WordPress/Docs/PHP/DisallowShortTernaryStandard.xml index 87bfda811a..c81b2fd82d 100644 --- a/WordPress/Docs/PHP/DisallowShortTernaryStandard.xml +++ b/WordPress/Docs/PHP/DisallowShortTernaryStandard.xml @@ -7,7 +7,8 @@ ? $data['height'] : 0; +$height = ! empty( $data['height'] ) ? + $data['height'] : 0; ]]> From 6aec3211d170d687b2eb078c11d7b91c2d314b39 Mon Sep 17 00:00:00 2001 From: oltho Date: Fri, 20 Sep 2019 16:17:21 +0200 Subject: [PATCH 210/241] Documentation Class Instantiation --- .../Classes/ClassInstantiationStandard.xml | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 WordPress/Docs/Classes/ClassInstantiationStandard.xml diff --git a/WordPress/Docs/Classes/ClassInstantiationStandard.xml b/WordPress/Docs/Classes/ClassInstantiationStandard.xml new file mode 100644 index 0000000000..b25fd34ce7 --- /dev/null +++ b/WordPress/Docs/Classes/ClassInstantiationStandard.xml @@ -0,0 +1,53 @@ + + + + + + + (); + ]]> + + + + + + + + + + + + + + (); + ]]> + + + + + + + + + + + & new Foobar(); + ]]> + + + From aecdaa763576c785779ecb214067436dbba3900b Mon Sep 17 00:00:00 2001 From: oltho Date: Sat, 28 Sep 2019 01:36:17 +0200 Subject: [PATCH 211/241] Proccessed feedback from jrfnl --- .../Docs/Classes/ClassInstantiationStandard.xml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/WordPress/Docs/Classes/ClassInstantiationStandard.xml b/WordPress/Docs/Classes/ClassInstantiationStandard.xml index b25fd34ce7..cdd749ecdd 100644 --- a/WordPress/Docs/Classes/ClassInstantiationStandard.xml +++ b/WordPress/Docs/Classes/ClassInstantiationStandard.xml @@ -1,7 +1,7 @@ @@ -18,16 +18,16 @@ $a = new Foobar; - + - + (); ]]> @@ -35,18 +35,18 @@ $a = new Foobar (); new Foobar(); ]]> & new Foobar(); +$a = & new Foobar(); ]]> From 85f30163edeb4d0d03895af5bcbac537ebc28135 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 3 Oct 2019 09:43:14 +0200 Subject: [PATCH 212/241] CapitalPDangit: minor tweak Allow for the `test` TLD. Includes unit test. --- WordPress/Sniffs/WP/CapitalPDangitSniff.php | 4 ++-- WordPress/Tests/WP/CapitalPDangitUnitTest.inc | 3 +++ WordPress/Tests/WP/CapitalPDangitUnitTest.inc.fixed | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/WordPress/Sniffs/WP/CapitalPDangitSniff.php b/WordPress/Sniffs/WP/CapitalPDangitSniff.php index edbd3ebe97..bf98233fb9 100644 --- a/WordPress/Sniffs/WP/CapitalPDangitSniff.php +++ b/WordPress/Sniffs/WP/CapitalPDangitSniff.php @@ -28,7 +28,7 @@ class CapitalPDangitSniff extends Sniff { * Regex to match a large number or spelling variations of WordPress in text strings. * * Prevents matches on: - * - URLs for wordpress.org/com/net/tv. + * - URLs for wordpress.org/com/net/test/tv. * - `@...` usernames starting with `wordpress` * - email addresses with a domain starting with `wordpress` * - email addresses with a user name ending with `wordpress` @@ -42,7 +42,7 @@ class CapitalPDangitSniff extends Sniff { * * @var string */ - const WP_REGEX = '#(?\'"()]*?\.(?:php|js|css|png|j[e]?pg|gif|pot))#i'; + const WP_REGEX = '#(?\'"()]*?\.(?:php|js|css|png|j[e]?pg|gif|pot))#i'; /** * Regex to match a large number or spelling variations of WordPress in class names. diff --git a/WordPress/Tests/WP/CapitalPDangitUnitTest.inc b/WordPress/Tests/WP/CapitalPDangitUnitTest.inc index 33622aa88c..e29ee8942f 100644 --- a/WordPress/Tests/WP/CapitalPDangitUnitTest.inc +++ b/WordPress/Tests/WP/CapitalPDangitUnitTest.inc @@ -188,3 +188,6 @@ class TestMe { ANOTHER => array( 'a' => 'b' ), WORDPRESS_SOMETHING = 'wordpress'; // OK (complex declaration to make sure start of statement is detected correctly). } + +// Allow "test" domain. +$value = function_call( 'git.wordpress.test' ); diff --git a/WordPress/Tests/WP/CapitalPDangitUnitTest.inc.fixed b/WordPress/Tests/WP/CapitalPDangitUnitTest.inc.fixed index 7dc636aa88..0a00f5ec0d 100644 --- a/WordPress/Tests/WP/CapitalPDangitUnitTest.inc.fixed +++ b/WordPress/Tests/WP/CapitalPDangitUnitTest.inc.fixed @@ -188,3 +188,6 @@ class TestMe { ANOTHER => array( 'a' => 'b' ), WORDPRESS_SOMETHING = 'wordpress'; // OK (complex declaration to make sure start of statement is detected correctly). } + +// Allow "test" domain. +$value = function_call( 'git.wordpress.test' ); From 28bc1449da4285327e9b5284f367802e182769f0 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 4 Oct 2019 04:31:06 +0200 Subject: [PATCH 213/241] Sniff: add new `is_function_deprecated()` utility function This new function: * Tries to find a function docblock, if it exists. * If found, checks if the docblock contains at least one `@deprecated` tag. Returns boolean true/false. Note: this method is `static` to allow the `ValidFunctionName` sniff which extends an upstream sniff to use the method as well. --- WordPress/Sniff.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 1abc6c920a..ed6bc3e1b7 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -3385,4 +3385,38 @@ protected function get_list_variables( $stackPtr, $list_open_close = array() ) { return $var_pointers; } + /** + * Check whether a function has been marked as deprecated via a @deprecated tag + * in the function docblock. + * + * {@internal This method is static to allow the ValidFunctionName class to use it.}} + * + * @since 2.2.0 + * + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of a T_FUNCTION + * token in the stack. + * + * @return bool + */ + public static function is_function_deprecated( File $phpcsFile, $stackPtr ) { + $tokens = $phpcsFile->getTokens(); + $find = Tokens::$methodPrefixes; + $find[] = \T_WHITESPACE; + + $comment_end = $phpcsFile->findPrevious( $find, ( $stackPtr - 1 ), null, true ); + if ( \T_DOC_COMMENT_CLOSE_TAG !== $tokens[ $comment_end ]['code'] ) { + // Function doesn't have a doc comment or is using the wrong type of comment. + return false; + } + + $comment_start = $tokens[ $comment_end ]['comment_opener']; + foreach ( $tokens[ $comment_start ]['comment_tags'] as $tag ) { + if ( '@deprecated' === $tokens[ $tag ]['content'] ) { + return true; + } + } + + return false; + } } From 6226cdcfcc055e7d305ad9bef541e3016cf37a4d Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 4 Oct 2019 04:29:22 +0200 Subject: [PATCH 214/241] ValidFunctionName: ignore deprecated functions Check the function docblock for a `@deprecated` tag and if found, bow out. Includes unit tests. Fixes 1797 --- .../ValidFunctionNameSniff.php | 22 ++++++++++++++++++- .../ValidFunctionNameUnitTest.inc | 22 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php index c88835cb6f..d8826ce1cf 100644 --- a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -24,6 +24,7 @@ * @since 0.13.0 Class name changed: this class is now namespaced. * @since 2.0.0 The `get_name_suggestion()` method has been moved to the * WordPress native `Sniff` base class as `get_snake_case_name_suggestion()`. + * @since 2.2.0 Will now ignore functions and methods which are marked as @deprecated. * * Last synced with parent class December 2018 up to commit ee167761d7756273b8ad0ad68bf3db1f2c211bb8. * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -43,6 +44,16 @@ class ValidFunctionNameSniff extends PHPCS_PEAR_ValidFunctionNameSniff { * @return void */ protected function processTokenOutsideScope( File $phpcsFile, $stackPtr ) { + + if ( Sniff::is_function_deprecated( $phpcsFile, $stackPtr ) === true ) { + /* + * Deprecated functions don't have to comply with the naming conventions, + * otherwise functions deprecated in favour of a function with a compliant + * name would still trigger an error. + */ + return; + } + $functionName = $phpcsFile->getDeclarationName( $stackPtr ); if ( ! isset( $functionName ) ) { @@ -51,7 +62,7 @@ protected function processTokenOutsideScope( File $phpcsFile, $stackPtr ) { } if ( '' === ltrim( $functionName, '_' ) ) { - // Ignore special functions. + // Ignore special functions, like __(). return; } @@ -102,6 +113,15 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco return; } + if ( Sniff::is_function_deprecated( $phpcsFile, $stackPtr ) === true ) { + /* + * Deprecated functions don't have to comply with the naming conventions, + * otherwise functions deprecated in favour of a function with a compliant + * name would still trigger an error. + */ + return; + } + $methodName = $phpcsFile->getDeclarationName( $stackPtr ); if ( ! isset( $methodName ) ) { diff --git a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc index 642fe78a80..f0403333ee 100644 --- a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc +++ b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc @@ -123,3 +123,25 @@ abstract class My_Class { public function my_Class() {} public function _MY_CLASS() {} } + +/** + * Function description. + * + * @since 1.2.3 + * @deprecated 2.3.4 + * + * @return void + */ +function __deprecatedFunction() {} + +class Deprecated { + /** + * Function description. + * + * @since 1.2.3 + * @deprecated 2.3.4 + * + * @return void + */ + public static function __deprecatedMethod() {} +} From d5640f852cce350a30f529b9d819a46f60007531 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 4 Oct 2019 04:35:43 +0200 Subject: [PATCH 215/241] PrefixAllGlobals: ignore deprecated functions Check the function docblock for a `@deprecated` tag and if found, bow out. Includes unit tests. Fixes 1797 Note: the same should probably also be done for classes/interfaces/traits/constants marked as deprecated, but that's for another PR. --- .../NamingConventions/PrefixAllGlobalsSniff.php | 12 +++++++++++- .../PrefixAllGlobalsUnitTest.1.inc | 13 +++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index a77bcd0b91..eadf332601 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -21,7 +21,8 @@ * @since 0.12.0 * @since 0.13.0 Class name changed: this class is now namespaced. * @since 1.2.0 Now also checks whether namespaces are prefixed. - * @since 2.2.0 Now also checks variables assigned via the list() construct. + * @since 2.2.0 - Now also checks variables assigned via the list() construct. + * - Now also ignores global functions which are marked as @deprecated. * * @uses \WordPressCS\WordPress\Sniff::$custom_test_class_whitelist */ @@ -382,6 +383,15 @@ public function process_token( $stackPtr ) { return; } + if ( $this->is_function_deprecated( $this->phpcsFile, $stackPtr ) === true ) { + /* + * Deprecated functions don't have to comply with the naming conventions, + * otherwise functions deprecated in favour of a function with a compliant + * name would still trigger an error. + */ + return; + } + $item_name = $this->phpcsFile->getDeclarationName( $stackPtr ); if ( isset( $this->built_in_functions[ $item_name ] ) ) { // Backfill for PHP native function. diff --git a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc index 655096a4c3..12404130e6 100644 --- a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc +++ b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc @@ -471,11 +471,20 @@ function acronym_lists_in_function_scope() { list( $foo['key'], $foo[ $c ] ) = $array; // OK. Variable array key should be ignored. } -// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] +// Issue #1797 - Ignore non-prefixed deprecated functions. +/** + * Function description. + * + * @since 1.2.3 + * @deprecated 2.3.4 + * + * @return void + */ +function deprecated_function() {} /* * Bad: Issue https://github.com/WordPress/WordPress-Coding-Standards/issues/1733. - * + * * Short prefixes are not allowed. The errors are triggered * on LINE 1 for the unit-test, because it's the phpcs:set command that is * wrong, not the implementing code. From b5f989d7876a9d46810b6bd52c249fc127d4c69c Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 7 Oct 2019 06:18:28 +0200 Subject: [PATCH 216/241] DeprecatedClasses: update the sniff Add some more deprecated classes to the list. Refs: * https://core.trac.wordpress.org/ticket/42364 * https://core.trac.wordpress.org/ticket/47699 --- WordPress/Sniffs/WP/DeprecatedClassesSniff.php | 14 ++++++++++++++ WordPress/Tests/WP/DeprecatedClassesUnitTest.inc | 3 +++ WordPress/Tests/WP/DeprecatedClassesUnitTest.php | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/WordPress/Sniffs/WP/DeprecatedClassesSniff.php b/WordPress/Sniffs/WP/DeprecatedClassesSniff.php index 4692eef599..9d1f95bff4 100644 --- a/WordPress/Sniffs/WP/DeprecatedClassesSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedClassesSniff.php @@ -48,6 +48,20 @@ class DeprecatedClassesSniff extends AbstractClassRestrictionsSniff { 'alt' => 'WP_User_Query', 'version' => '3.1.0', ), + + // WP 4.9.0. + 'Customize_New_Menu_Section' => array( + 'version' => '4.9.0', + ), + 'WP_Customize_New_Menu_Control' => array( + 'version' => '4.9.0', + ), + + // WP 5.3.0. + 'Services_JSON' => array( + 'alt' => 'The PHP native JSON extension', + 'version' => '5.3.0', + ), ); diff --git a/WordPress/Tests/WP/DeprecatedClassesUnitTest.inc b/WordPress/Tests/WP/DeprecatedClassesUnitTest.inc index fcd27c2fa3..b0b678d944 100644 --- a/WordPress/Tests/WP/DeprecatedClassesUnitTest.inc +++ b/WordPress/Tests/WP/DeprecatedClassesUnitTest.inc @@ -17,3 +17,6 @@ $a = (new WP_User_Search())->query(); /* * Warning. */ +class Prefix_Menu_section extends Customize_New_Menu_Section {} +WP_Customize_New_Menu_Control::foo(); +$json = new Services_JSON; diff --git a/WordPress/Tests/WP/DeprecatedClassesUnitTest.php b/WordPress/Tests/WP/DeprecatedClassesUnitTest.php index b58576ccf2..01a0554152 100644 --- a/WordPress/Tests/WP/DeprecatedClassesUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedClassesUnitTest.php @@ -36,7 +36,7 @@ public function getErrorList() { * @return array => */ public function getWarningList() { - return array(); + return array_fill( 20, 3, 1 ); } } From e38cee87efefd5c9c97a719f9a0ba0d7a26bc073 Mon Sep 17 00:00:00 2001 From: Mike Hermans Date: Sun, 13 Oct 2019 10:56:36 +0200 Subject: [PATCH 217/241] Docs/WordPress.Arrays.ArrayIndentation (#1744) Adds documentations for the WordPress.Arrays.ArrayIndentation sniff Related to #1722 --- .../Docs/Arrays/ArrayIndentationStandard.xml | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 WordPress/Docs/Arrays/ArrayIndentationStandard.xml diff --git a/WordPress/Docs/Arrays/ArrayIndentationStandard.xml b/WordPress/Docs/Arrays/ArrayIndentationStandard.xml new file mode 100644 index 0000000000..5b9a1deea3 --- /dev/null +++ b/WordPress/Docs/Arrays/ArrayIndentationStandard.xml @@ -0,0 +1,112 @@ + + + + + + + 22, +); + ]]> + + + 22, + ); + ]]> + + + + + + + + 22, + 'comment_count' => array( + 'value' => 25, + 'compare' => '>=', + ), + 'post_type' => array( + 'post', + 'page', + ), +); + ]]> + + + 22, + 'comment_count' => array( + 'value' => 25, + 'compare' => '>=', + ), + 'post_type' => array( + 'post', + 'page', + ), +); + ]]> + + + + + + + + 'start of phrase' + . 'concatented additional phrase' + . 'more text', +); + ]]> + + + 'start of phrase' +. 'concatented additional phrase' +. 'more text', +); + ]]> + + + + + + + + << + start of phrase + concatented additional phrase + more text +EOD +, +); + ]]> + + + From 058be1bc5b2c5f20bcb0fb44603e43abe6315be4 Mon Sep 17 00:00:00 2001 From: Mike Hermans Date: Sun, 13 Oct 2019 22:21:42 +0200 Subject: [PATCH 218/241] Docs/ArrayKeySpacingRestrictions and Array.MultipleStatementAlignment (#1737) Adds documentations for the `WordPress.Arrays.ArrayKeySpacingRestrictions` sniff and the `WordPress.Arrays.MultipleStatementAlignment` sniff. Related to #1722 --- .../ArrayKeySpacingRestrictionsStandard.xml | 27 +++++++++++ .../MultipleStatementAlignmentStandard.xml | 46 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 WordPress/Docs/Arrays/ArrayKeySpacingRestrictionsStandard.xml create mode 100644 WordPress/Docs/Arrays/MultipleStatementAlignmentStandard.xml diff --git a/WordPress/Docs/Arrays/ArrayKeySpacingRestrictionsStandard.xml b/WordPress/Docs/Arrays/ArrayKeySpacingRestrictionsStandard.xml new file mode 100644 index 0000000000..c1e27a1324 --- /dev/null +++ b/WordPress/Docs/Arrays/ArrayKeySpacingRestrictionsStandard.xml @@ -0,0 +1,27 @@ + + + + + + + [ $post_id ]; +$post_title = $post[ 'concatenated' . $title ]; +$post = $posts[ HOME_PAGE ]; +$post = $posts[123]; +$post_title = $post['post_title']; + ]]> + + + [$post_id]; +$post_title = $post['concatenated' . $title ]; +$post = $posts[HOME_PAGE]; +$post = $posts[ 123 ]; +$post_title = $post[ 'post_title' ]; + ]]> + + + diff --git a/WordPress/Docs/Arrays/MultipleStatementAlignmentStandard.xml b/WordPress/Docs/Arrays/MultipleStatementAlignmentStandard.xml new file mode 100644 index 0000000000..b3f87cbbe5 --- /dev/null +++ b/WordPress/Docs/Arrays/MultipleStatementAlignmentStandard.xml @@ -0,0 +1,46 @@ + + + + + + + => 22 ); +$bar = array( 'year' => $current_year ); + ]]> + + + =>22 ); +$bar = array( 'year'=> $current_year ); + ]]> + + + + + + + + => 22, + 'year' => $current_year, + 'monthnum' => $current_month, +); + ]]> + + + => 22, + 'year' => $current_year, + 'monthnum' => $current_month, +); + ]]> + + + From 5c82777d0e4c626eb7da8d23458370dc23b705ea Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 15 Oct 2019 01:02:49 +0200 Subject: [PATCH 219/241] DeprecatedFunctions: update function list ... with functions which will be deprecated in WP 5.3. Not updating the `Sniff::$minimum_supported_version` property yet as WP 5.3 has not yet been released. --- WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php | 14 ++++++++++++++ WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc | 4 ++++ WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php | 4 ++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php b/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php index fb4ad43230..7793917096 100644 --- a/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php @@ -1345,6 +1345,20 @@ class DeprecatedFunctionsSniff extends AbstractFunctionRestrictionsSniff { 'alt' => '', 'version' => '5.1.0', ), + + // WP 5.3.0. + '_wp_json_prepare_data' => array( + 'alt' => '', + 'version' => '5.3.0', + ), + '_wp_privacy_requests_screen_options' => array( + 'alt' => '', + 'version' => '5.3.0', + ), + 'update_user_status' => array( + 'alt' => 'wp_update_user()', + 'version' => '5.3.0', + ), ); /** diff --git a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc index 6a41db6cc6..03c075a44b 100644 --- a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc +++ b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc @@ -341,3 +341,7 @@ wp_ajax_press_this_save_post(); /* ============ WP 5.1 ============ */ insert_blog(); install_blog(); +/* ============ WP 5.3 ============ */ +_wp_json_prepare_data(); +_wp_privacy_requests_screen_options(); +update_user_status(); diff --git a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php index b3b217c7cf..21a90b3b79 100644 --- a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php @@ -75,10 +75,10 @@ public function getErrorList() { */ public function getWarningList() { - $warnings = array_fill( 337, 7, 1 ); + $warnings = array_fill( 337, 11, 1 ); // Unset the lines related to version comments. - unset( $warnings[341] ); + unset( $warnings[341], $warnings[344] ); return $warnings; } From 0e88b837d9d29796b818917fc5a28b0fdc8318b5 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 22 Oct 2019 07:51:33 +0200 Subject: [PATCH 220/241] ValidHookName: minor efficiency tweaks Instead of checking whether a `..._deprecated()` function was matched after the function matching, remove the deprecated hook invocation functions from the target function array in `getGroups()`. This allows the sniff to fail earlier. Also remove redundant check for `$parameters[1]`. If there are no parameters, the `process_parameters()` function wouldn't be called anyway. --- .../NamingConventions/ValidHookNameSniff.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php index 4ce141e142..c8e8a54461 100644 --- a/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php @@ -73,6 +73,13 @@ class ValidHookNameSniff extends AbstractFunctionParameterSniff { */ public function getGroups() { $this->target_functions = $this->hookInvokeFunctions; + + // No need to examine the names of deprecated hooks. + unset( + $this->target_functions['do_action_deprecated'], + $this->target_functions['apply_filters_deprecated'] + ); + return parent::getGroups(); } @@ -89,14 +96,6 @@ public function getGroups() { * @return void */ public function process_parameters( $stackPtr, $group_name, $matched_content, $parameters ) { - // Ignore deprecated hook names. - if ( strpos( $matched_content, '_deprecated' ) > 0 ) { - return; - } - - if ( ! isset( $parameters[1] ) ) { - return; - } $regex = $this->prepare_regex(); From 62d9924f773296870375928de72ab7b959bc6c32 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 24 Oct 2019 01:02:56 +0200 Subject: [PATCH 221/241] ValidHookName: add documentation Related to 1722 --- .../ValidHookNameStandard.xml | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 WordPress/Docs/NamingConventions/ValidHookNameStandard.xml diff --git a/WordPress/Docs/NamingConventions/ValidHookNameStandard.xml b/WordPress/Docs/NamingConventions/ValidHookNameStandard.xml new file mode 100644 index 0000000000..479dbd9ba5 --- /dev/null +++ b/WordPress/Docs/NamingConventions/ValidHookNameStandard.xml @@ -0,0 +1,32 @@ + + + + + + + + 'prefix_hook_name', $var ); + ]]> + + + 'Prefix_Hook_NAME', $var ); + ]]> + + + + + 'prefix_hook_name', $var ); + ]]> + + + 'prefix\hook-name', $var ); + ]]> + + + From 7947bce347122daa530b0b11864d34fb35e6e465 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 5 Oct 2019 03:29:33 +0200 Subject: [PATCH 222/241] New "DateTime.RestrictedFunctions" sniff This introduces a new `WordPress.DateTime.RestrictedFunctions` sniff which initially includes two groups: * `timezone_change` - moved from the `WordPress.WP.TimezoneChange` sniff * `date` - moved from the `WordPress.PHP.RestrictedPHPFunctions` sniff (group not yet in a released WPCS version yet) The `WordPress.WP.TimezoneChange` sniff is now deprecated. * The sniff is no longer included in the WPCS rulesets. * If the sniff is explicitly included via a custom ruleset, deprecation notices will be thrown. * If the `exclude` property is set from with a custom ruleset, a deprecation notice will be thrown. The new sniff is now included in the `Core` ruleset. Note: once WP Core upgrades, the one instance of using `date_default_timezone_set()` in WP Core (in `wp-settings.php`) will need to be whitelisted inline. There are a few more occurrences in the unit tests, but those can be ignored via file based excludes. Fixes 1805 --- WordPress-Core/ruleset.xml | 4 ++ WordPress-Extra/ruleset.xml | 1 - .../DateTime/RestrictedFunctionsSniff.php | 62 ++++++++++++++++ .../PHP/RestrictedPHPFunctionsSniff.php | 8 --- WordPress/Sniffs/WP/TimezoneChangeSniff.php | 72 ++++++++++++++----- .../DateTime/RestrictedFunctionsUnitTest.inc | 9 +++ .../DateTime/RestrictedFunctionsUnitTest.php | 44 ++++++++++++ .../PHP/RestrictedPHPFunctionsUnitTest.inc | 3 - .../PHP/RestrictedPHPFunctionsUnitTest.php | 1 - WordPress/Tests/WP/TimezoneChangeUnitTest.inc | 6 +- WordPress/Tests/WP/TimezoneChangeUnitTest.php | 7 +- WordPress/ruleset.xml | 6 +- 12 files changed, 187 insertions(+), 36 deletions(-) create mode 100644 WordPress/Sniffs/DateTime/RestrictedFunctionsSniff.php create mode 100644 WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.inc create mode 100644 WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.php diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index 5d4c5deb66..949d16efe2 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -519,4 +519,8 @@ + + +
diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index f44b0db786..a795891878 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -145,7 +145,6 @@ - diff --git a/WordPress/Sniffs/DateTime/RestrictedFunctionsSniff.php b/WordPress/Sniffs/DateTime/RestrictedFunctionsSniff.php new file mode 100644 index 0000000000..0da070190c --- /dev/null +++ b/WordPress/Sniffs/DateTime/RestrictedFunctionsSniff.php @@ -0,0 +1,62 @@ + array( + 'type' => 'error', + 'message' => 'Using %s() and similar isn\'t allowed, instead use WP internal timezone support.', + 'functions' => array( + 'date_default_timezone_set', + ), + ), + + /* + * Use gmdate(), not date(). + * Don't rely on the current PHP time zone as it might have been changed by third party code. + * + * @link https://make.wordpress.org/core/2019/09/23/date-time-improvements-wp-5-3/ + * @link https://core.trac.wordpress.org/ticket/46438 + * @link https://github.com/WordPress/WordPress-Coding-Standards/issues/1713 + */ + 'date' => array( + 'type' => 'error', + 'message' => '%s() is affected by runtime timezone changes which can cause date/time to be incorrectly displayed. Use gmdate() instead.', + 'functions' => array( + 'date', + ), + ), + ); + } + +} diff --git a/WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php b/WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php index b7f3bb14a1..280c94d919 100644 --- a/WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php @@ -17,7 +17,6 @@ * @package WPCS\WordPressCodingStandards * * @since 0.14.0 - * @since 2.2.0 New group `date` added. */ class RestrictedPHPFunctionsSniff extends AbstractFunctionRestrictionsSniff { @@ -43,13 +42,6 @@ public function getGroups() { 'create_function', ), ), - 'date' => array( - 'type' => 'error', - 'message' => '%s() is affected by runtime timezone changes which can cause date/time to be incorrectly displayed. Use gmdate() instead.', - 'functions' => array( - 'date', - ), - ), ); } diff --git a/WordPress/Sniffs/WP/TimezoneChangeSniff.php b/WordPress/Sniffs/WP/TimezoneChangeSniff.php index 5712df975c..f376c5e3a3 100644 --- a/WordPress/Sniffs/WP/TimezoneChangeSniff.php +++ b/WordPress/Sniffs/WP/TimezoneChangeSniff.php @@ -9,7 +9,7 @@ namespace WordPressCS\WordPress\Sniffs\WP; -use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\Sniffs\DateTime\RestrictedFunctionsSniff; /** * Disallow the changing of timezone. @@ -23,32 +23,66 @@ * class instead of the upstream `Generic.PHP.ForbiddenFunctions` sniff. * @since 0.13.0 Class name changed: this class is now namespaced. * @since 1.0.0 This sniff has been moved from the `VIP` category to the `WP` category. + * + * @deprecated 2.2.0 Use the `WordPress.DateTime.RestrictedFunctions` sniff instead. + * This `WordPress.WP.TimezoneChange` sniff will be removed in WPCS 3.0.0. */ -class TimezoneChangeSniff extends AbstractFunctionRestrictionsSniff { +class TimezoneChangeSniff extends RestrictedFunctionsSniff { /** - * Groups of functions to restrict. + * Keep track of whether the warnings have been thrown to prevent + * the messages being thrown for every token triggering the sniff. * - * Example: groups => array( - * 'lambda' => array( - * 'type' => 'error' | 'warning', - * 'message' => 'Use anonymous functions instead please!', - * 'functions' => array( 'file_get_contents', 'create_function' ), - * ) - * ) + * @since 2.2.0 + * + * @var array + */ + private $thrown = array( + 'DeprecatedSniff' => false, + 'FoundPropertyForDeprecatedSniff' => false, + ); + + /** + * Don't use. + * + * @deprecated 2.2.0 * * @return array */ public function getGroups() { - return array( - 'timezone_change' => array( - 'type' => 'error', - 'message' => 'Using %s() and similar isn\'t allowed, instead use WP internal timezone support.', - 'functions' => array( - 'date_default_timezone_set', - ), - ), - ); + $groups = parent::getGroups(); + return array( 'timezone_change' => $groups['timezone_change'] ); } + /** + * Don't use. + * + * @since 2.2.0 Added to allow for throwing the deprecation notices. + * @deprecated 2.2.0 + * + * @param int $stackPtr The position of the current token in the stack. + * + * @return void|int + */ + public function process_token( $stackPtr ) { + if ( false === $this->thrown['DeprecatedSniff'] ) { + $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( + 'The "WordPress.WP.TimezoneChange" sniff has been deprecated. Use the "WordPress.DateTime.RestrictedFunctions" sniff instead. Please update your custom ruleset.', + 0, + 'DeprecatedSniff' + ); + } + + if ( ! empty( $this->exclude ) + && false === $this->thrown['FoundPropertyForDeprecatedSniff'] + ) { + $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( + 'The "WordPress.WP.TimezoneChange" sniff has been deprecated. Use the "WordPress.DateTime.RestrictedFunctions" sniff instead. "exclude" property setting found. Please update your custom ruleset.', + 0, + 'FoundPropertyForDeprecatedSniff' + ); + } + + return parent::process_token( $stackPtr ); + } } diff --git a/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.inc b/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.inc new file mode 100644 index 0000000000..25227b5178 --- /dev/null +++ b/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.inc @@ -0,0 +1,9 @@ +setTimezone( new DateTimeZone( 'America/Toronto' ) ); // Yay! + +$post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), date( __( 'F j, Y' ), $now ), date( __( 'g:i a' ), $now ) ); // Error. +$post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), gmdate( __( 'F j, Y' ), $now ), gmdate( __( 'g:i a' ), $now ) ); // OK. diff --git a/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.php b/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.php new file mode 100644 index 0000000000..ecfc78867f --- /dev/null +++ b/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.php @@ -0,0 +1,44 @@ + => + */ + public function getErrorList() { + return array( + 3 => 1, + 8 => 2, + ); + } + + /** + * Returns the lines where warnings should occur. + * + * @return array => + */ + public function getWarningList() { + return array(); + } + +} diff --git a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.inc b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.inc index 2a4e8754b5..84dbd1d7b3 100644 --- a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.inc +++ b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.inc @@ -3,6 +3,3 @@ add_action( 'widgets_init', create_function( '', // Error. 'return register_widget( "time_more_on_time_widget" );' ) ); - -$post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), date( __( 'F j, Y' ), $now ), date( __( 'g:i a' ), $now ) ); // Error. -$post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), gmdate( __( 'F j, Y' ), $now ), gmdate( __( 'g:i a' ), $now ) ); // OK. diff --git a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php index 3d21aa7195..af8707d3cd 100644 --- a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php @@ -28,7 +28,6 @@ class RestrictedPHPFunctionsUnitTest extends AbstractSniffUnitTest { public function getErrorList() { return array( 3 => 1, - 7 => 2, ); } diff --git a/WordPress/Tests/WP/TimezoneChangeUnitTest.inc b/WordPress/Tests/WP/TimezoneChangeUnitTest.inc index 4e38791f9b..c1a374c306 100644 --- a/WordPress/Tests/WP/TimezoneChangeUnitTest.inc +++ b/WordPress/Tests/WP/TimezoneChangeUnitTest.inc @@ -2,5 +2,7 @@ date_default_timezone_set( 'Foo/Bar' ); // Bad. -$date = new DateTime(); -$date->setTimezone( new DateTimeZone( 'America/Toronto' ) ); // Yay! +// phpcs:set WordPress.WP.TimezoneChange exclude[] timezone_change +date_default_timezone_set( 'Foo/Bar' ); // OK. + +// phpcs:set WordPress.WP.TimezoneChange exclude[] diff --git a/WordPress/Tests/WP/TimezoneChangeUnitTest.php b/WordPress/Tests/WP/TimezoneChangeUnitTest.php index 81e86d1e6e..906883077b 100644 --- a/WordPress/Tests/WP/TimezoneChangeUnitTest.php +++ b/WordPress/Tests/WP/TimezoneChangeUnitTest.php @@ -19,6 +19,9 @@ * @since 0.3.0 * @since 0.13.0 Class name changed: this class is now namespaced. * @since 1.0.0 This sniff has been moved from the `VIP` category to the `WP` category. + * @since 2.2.0 The sniff has been deprecated. This unit test file now + * only tests that the deprecation warnings are correctly thrown + * and that the sniff falls through to the parent correctly. */ class TimezoneChangeUnitTest extends AbstractSniffUnitTest { @@ -39,7 +42,9 @@ public function getErrorList() { * @return array => */ public function getWarningList() { - return array(); + return array( + 1 => 2, + ); } } diff --git a/WordPress/ruleset.xml b/WordPress/ruleset.xml index fd24ae6318..20ff9a38cc 100644 --- a/WordPress/ruleset.xml +++ b/WordPress/ruleset.xml @@ -8,6 +8,10 @@ --> - + + + + +
From 864e4fd65be99694f3d6eaf8b638f6bd02c8ef29 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 24 Oct 2019 16:11:07 +0200 Subject: [PATCH 223/241] EscapeOutput: allow for typical pattern with `_deprecated_file()` The first parameter passed to `_deprecated_file()` generally is `basename( __FILE__ )` based on the code currently in WP Core. As the result of that function call is safe, I'm proposing making an exception for that particular code pattern. Includes unit tests. Note: the current code does not allow for comments in the first parameter. This would be rare encounter in these function calls anyway and allowance for it can be added later if needs be. --- WordPress/Sniffs/Security/EscapeOutputSniff.php | 14 ++++++++++++++ WordPress/Tests/Security/EscapeOutputUnitTest.inc | 3 +++ WordPress/Tests/Security/EscapeOutputUnitTest.php | 1 + 3 files changed, 18 insertions(+) diff --git a/WordPress/Sniffs/Security/EscapeOutputSniff.php b/WordPress/Sniffs/Security/EscapeOutputSniff.php index fa4100e4ce..cb33eaaeee 100644 --- a/WordPress/Sniffs/Security/EscapeOutputSniff.php +++ b/WordPress/Sniffs/Security/EscapeOutputSniff.php @@ -198,6 +198,20 @@ public function process_token( $stackPtr ) { $end_of_statement = ( $first_param['end'] + 1 ); unset( $first_param ); } + + /* + * If the first param to `_deprecated_file()` follows the typical `basename( __FILE__ )` + * pattern, it doesn't need to be escaped. + */ + if ( '_deprecated_file' === $function ) { + $first_param = $this->get_function_call_parameter( $stackPtr, 1 ); + + // Quick check. This disregards comments. + if ( preg_match( '`^basename\s*\(\s*__FILE__\s*\)$`', $first_param['raw'] ) === 1 ) { + $stackPtr = ( $first_param['end'] + 2 ); + } + unset( $first_param ); + } } // Checking for the ignore comment, ex: //xss ok. diff --git a/WordPress/Tests/Security/EscapeOutputUnitTest.inc b/WordPress/Tests/Security/EscapeOutputUnitTest.inc index 875f575f23..bd74d93ac9 100644 --- a/WordPress/Tests/Security/EscapeOutputUnitTest.inc +++ b/WordPress/Tests/Security/EscapeOutputUnitTest.inc @@ -292,3 +292,6 @@ echo esc_html( get_the_title() ); // Ok. echo implode( '
', map_deep( $items, 'esc_html' ) ); // Ok. echo implode( '
', map_deep( $items, 'foo' ) ); // Bad. + +_deprecated_file( basename( __FILE__ ), '1.3.0' ); // Ok. +_deprecated_file( $file, '1.3.0' ); // Error. diff --git a/WordPress/Tests/Security/EscapeOutputUnitTest.php b/WordPress/Tests/Security/EscapeOutputUnitTest.php index 1d803fc349..bd81edd244 100644 --- a/WordPress/Tests/Security/EscapeOutputUnitTest.php +++ b/WordPress/Tests/Security/EscapeOutputUnitTest.php @@ -80,6 +80,7 @@ public function getErrorList() { 266 => 1, 289 => 1, 294 => 1, + 297 => 1, ); } From e4f838c19de4f325c1894373498c8070bbaedc7a Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 5 Oct 2019 09:28:30 +0200 Subject: [PATCH 224/241] :sparkles: New DateTime.CurrentTimeTimestamp sniff This new sniff adds a check for use of current_time() to retrieve a timestamp. A (fixable) `error` will be thrown when the `$gmt` parameter is set to `true` or `1`, a `warning` when it is not. Includes unit tests. Includes fixer. Includes documentation. This new sniff has been added to the `Core` ruleset. Fixes 1791 --- WordPress-Core/ruleset.xml | 3 + .../DateTime/CurrentTimeTimestampStandard.xml | 31 ++++ .../DateTime/CurrentTimeTimestampSniff.php | 174 ++++++++++++++++++ .../DateTime/CurrentTimeTimestampUnitTest.inc | 25 +++ .../CurrentTimeTimestampUnitTest.inc.fixed | 22 +++ .../DateTime/CurrentTimeTimestampUnitTest.php | 50 +++++ 6 files changed, 305 insertions(+) create mode 100644 WordPress/Docs/DateTime/CurrentTimeTimestampStandard.xml create mode 100644 WordPress/Sniffs/DateTime/CurrentTimeTimestampSniff.php create mode 100644 WordPress/Tests/DateTime/CurrentTimeTimestampUnitTest.inc create mode 100644 WordPress/Tests/DateTime/CurrentTimeTimestampUnitTest.inc.fixed create mode 100644 WordPress/Tests/DateTime/CurrentTimeTimestampUnitTest.php diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index 949d16efe2..0bff5a0d43 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -523,4 +523,7 @@ See: https://github.com/WordPress/WordPress-Coding-Standards/issues/1713 --> + + +
diff --git a/WordPress/Docs/DateTime/CurrentTimeTimestampStandard.xml b/WordPress/Docs/DateTime/CurrentTimeTimestampStandard.xml new file mode 100644 index 0000000000..add8ed2378 --- /dev/null +++ b/WordPress/Docs/DateTime/CurrentTimeTimestampStandard.xml @@ -0,0 +1,31 @@ + + + + + + + time(); + ]]> + + + current_time( 'timestamp', true ); + ]]> + + + + + 'Y-m-d' ); + ]]> + + + current_time( 'U', false ); + ]]> + + + diff --git a/WordPress/Sniffs/DateTime/CurrentTimeTimestampSniff.php b/WordPress/Sniffs/DateTime/CurrentTimeTimestampSniff.php new file mode 100644 index 0000000000..180ae240d2 --- /dev/null +++ b/WordPress/Sniffs/DateTime/CurrentTimeTimestampSniff.php @@ -0,0 +1,174 @@ + => + */ + protected $target_functions = array( + 'current_time' => true, + ); + + /** + * Process the parameters of a matched function. + * + * @since 2.2.0 + * + * @param int $stackPtr The position of the current token in the stack. + * @param string $group_name The name of the group which was matched. + * @param string $matched_content The token content (function name) which was matched. + * @param array $parameters Array with information about the parameters. + * + * @return void + */ + public function process_parameters( $stackPtr, $group_name, $matched_content, $parameters ) { + /* + * We already know there will be valid open & close parentheses as otherwise the parameter + * retrieval function call would have returned an empty array, so no additional checks needed. + */ + $open_parens = $this->phpcsFile->findNext( \T_OPEN_PARENTHESIS, $stackPtr ); + $close_parens = $this->tokens[ $open_parens ]['parenthesis_closer']; + + /* + * Check whether the first parameter is a timestamp format. + */ + for ( $i = $parameters[1]['start']; $i <= $parameters[1]['end']; $i++ ) { + if ( isset( Tokens::$emptyTokens[ $this->tokens[ $i ]['code'] ] ) ) { + continue; + } + + if ( isset( Tokens::$textStringTokens[ $this->tokens[ $i ]['code'] ] ) ) { + $content_first = trim( $this->strip_quotes( $this->tokens[ $i ]['content'] ) ); + if ( 'U' !== $content_first && 'timestamp' !== $content_first ) { + // Most likely valid use of current_time(). + return; + } + + continue; + } + + if ( isset( Tokens::$heredocTokens[ $this->tokens[ $i ]['code'] ] ) ) { + continue; + } + + /* + * If we're still here, we've encountered an unexpected token, like a variable or + * function call. Bow out as we can't determine the runtime value. + */ + return; + } + + $gmt_true = false; + + /* + * Check whether the second parameter, $gmt, is a set to `true` or `1`. + */ + if ( isset( $parameters[2] ) ) { + $content_second = ''; + if ( 'true' === $parameters[2]['raw'] || '1' === $parameters[2]['raw'] ) { + $content_second = $parameters[2]['raw']; + $gmt_true = true; + } else { + // Do a more extensive parameter check. + for ( $i = $parameters[2]['start']; $i <= $parameters[2]['end']; $i++ ) { + if ( isset( Tokens::$emptyTokens[ $this->tokens[ $i ]['code'] ] ) ) { + continue; + } + + $content_second .= $this->tokens[ $i ]['content']; + } + + if ( 'true' === $content_second || '1' === $content_second ) { + $gmt_true = true; + } + } + } + + /* + * Non-UTC timestamp requested. + */ + if ( false === $gmt_true ) { + $this->phpcsFile->addWarning( + 'Calling current_time() with a $type of "timestamp" or "U" is strongly discouraged as it will not return a Unix (UTC) timestamp. Please consider using a non-timestamp format or otherwise refactoring this code.', + $stackPtr, + 'Requested' + ); + + return; + } + + /* + * UTC timestamp requested. Should use time() instead. + */ + $has_comment = $this->phpcsFile->findNext( Tokens::$commentTokens, ( $stackPtr + 1 ), ( $close_parens + 1 ) ); + $error = 'Don\'t use current_time() for retrieving a Unix (UTC) timestamp. Use time() instead. Found: %s'; + $error_code = 'RequestedUTC'; + + $code_snippet = "current_time( '" . $content_first . "'"; + if ( isset( $content_second ) ) { + $code_snippet .= ', ' . $content_second; + } + $code_snippet .= ' )'; + + if ( false !== $has_comment ) { + // If there are comments, we don't auto-fix as it would remove those comments. + $this->phpcsFile->addError( $error, $stackPtr, $error_code, array( $code_snippet ) ); + + return; + } + + $fix = $this->phpcsFile->addFixableError( $error, $stackPtr, $error_code, array( $code_snippet ) ); + if ( true === $fix ) { + $this->phpcsFile->fixer->beginChangeset(); + + for ( $i = ( $stackPtr + 1 ); $i < $close_parens; $i++ ) { + $this->phpcsFile->fixer->replaceToken( $i, '' ); + } + + $this->phpcsFile->fixer->replaceToken( $stackPtr, 'time(' ); + $this->phpcsFile->fixer->endChangeset(); + } + } + +} diff --git a/WordPress/Tests/DateTime/CurrentTimeTimestampUnitTest.inc b/WordPress/Tests/DateTime/CurrentTimeTimestampUnitTest.inc new file mode 100644 index 0000000000..ac89fb1943 --- /dev/null +++ b/WordPress/Tests/DateTime/CurrentTimeTimestampUnitTest.inc @@ -0,0 +1,25 @@ + => + */ + public function getErrorList() { + return array( + 9 => 1, + 11 => 1, + 17 => 1, + ); + } + + /** + * Returns the lines where warnings should occur. + * + * @return array => + */ + public function getWarningList() { + return array( + 22 => 1, + 23 => 1, + 24 => 1, + 25 => 1, + ); + } + +} From 52de928c942c11743180df0871e777418c602ab1 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 28 Oct 2019 01:31:15 +0100 Subject: [PATCH 225/241] ValidHookName: improve error messages * Trim whitespace off the "expected" and "found" values which are used in the error messages. * Ignore comments and PHPCS annotations when building up the "expected" and "found" values. * Improve line precision by throwing the error on the line where the hook name starts, not the line containing the function call. Includes unit test. The unit test basically only tests part 3 of the change. The error message improvement needs visual inspection as the message content is not tested. --- .../NamingConventions/ValidHookNameSniff.php | 20 +++++++++++++++---- .../ValidHookNameUnitTest.1.inc | 6 ++++++ .../ValidHookNameUnitTest.php | 3 ++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php index c8e8a54461..4c56d96c8f 100644 --- a/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php @@ -105,6 +105,11 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p $expected = array(); for ( $i = $parameters[1]['start']; $i <= $parameters[1]['end']; $i++ ) { + // Skip past comment tokens. + if ( isset( Tokens::$commentTokens[ $this->tokens[ $i ]['code'] ] ) !== false ) { + continue; + } + $content[ $i ] = $this->tokens[ $i ]['content']; $expected[ $i ] = $this->tokens[ $i ]['content']; @@ -165,18 +170,25 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p } } + $first_non_empty = $this->phpcsFile->findNext( + Tokens::$emptyTokens, + $parameters[1]['start'], + ( $parameters[1]['end'] + 1 ), + true + ); + $data = array( - implode( '', $expected ), - implode( '', $content ), + trim( implode( '', $expected ) ), + trim( implode( '', $content ) ), ); if ( $case_errors > 0 ) { $error = 'Hook names should be lowercase. Expected: %s, but found: %s.'; - $this->phpcsFile->addError( $error, $stackPtr, 'NotLowercase', $data ); + $this->phpcsFile->addError( $error, $first_non_empty, 'NotLowercase', $data ); } if ( $underscores > 0 ) { $error = 'Words in hook names should be separated using underscores. Expected: %s, but found: %s.'; - $this->phpcsFile->addWarning( $error, $stackPtr, 'UseUnderscores', $data ); + $this->phpcsFile->addWarning( $error, $first_non_empty, 'UseUnderscores', $data ); } } diff --git a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.1.inc b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.1.inc index 7fd072418e..039ca6484e 100644 --- a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.1.inc +++ b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.1.inc @@ -88,3 +88,9 @@ apply_filters_deprecated( "admin_Head_$Post->ID admin_Head_$Post->ID" ); // Ok. do_action( 'prefix_block_' . $block['blockName'] ); // Ok. do_action( 'prefix_block_' . $block [ 'blockName' ] . '_More_hookname' ); // Error - use lowercase (second part of the hook name). do_action( "prefix_block_{$block['blockName']}" ); // Ok. + +// Don't include comments in the suggestion. +do_action( + // phpcs:ignore Stnd.Cat.Sniff -- For reasons. + 'prefix_hook-name' /* comment */ +); diff --git a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php index dfa253c850..c55be6b044 100644 --- a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php +++ b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php @@ -39,7 +39,7 @@ public function getErrorList( $testFile = 'ValidHookNameUnitTest.1.inc' ) { 28 => 1, 29 => 1, 30 => 1, - 32 => 1, + 33 => 1, 53 => 1, 54 => 1, 55 => 1, @@ -96,6 +96,7 @@ public function getWarningList( $testFile = 'ValidHookNameUnitTest.1.inc' ) { 68 => 1, 72 => 1, 77 => 1, + 95 => 1, ); case 'ValidHookNameUnitTest.2.inc': From ef7f86e583b80820c4751c7c68c9e0a66a83567b Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 28 Oct 2019 21:14:04 +0100 Subject: [PATCH 226/241] PrefixAllGlobals: minor efficiency tweak Similar to 1815, but then for the `PrefixAllGlobals` sniff, allowing it to fail earlier for calls to deprecated hooks. --- .../NamingConventions/PrefixAllGlobalsSniff.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index eadf332601..8374faf675 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -241,7 +241,12 @@ public function register() { * @return array */ public function getGroups() { - $this->target_functions = $this->hookInvokeFunctions; + $this->target_functions = $this->hookInvokeFunctions; + unset( + $this->target_functions['do_action_deprecated'], + $this->target_functions['apply_filters_deprecated'] + ); + $this->target_functions['define'] = true; return parent::getGroups(); @@ -793,11 +798,6 @@ protected function process_list_assignment( $stackPtr ) { */ public function process_parameters( $stackPtr, $group_name, $matched_content, $parameters ) { - // Ignore deprecated hook names. - if ( strpos( $matched_content, '_deprecated' ) > 0 ) { - return; - } - // No matter whether it is a constant definition or a hook call, both use the first parameter. if ( ! isset( $parameters[1] ) ) { return; From c65d63b7261786d2a10eed90a54b436cc098ddaa Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 1 Nov 2019 05:18:43 +0100 Subject: [PATCH 227/241] Update default minimum supported WP version What with the target release date for WPCS 2.2.0 being November 11 and the target release date of WP 5.3 being November 12, updating this property before the release is probably a good idea. --- WordPress/Sniff.php | 2 +- WordPress/Tests/WP/DeprecatedClassesUnitTest.inc | 6 ++++-- WordPress/Tests/WP/DeprecatedClassesUnitTest.php | 9 +++++++-- WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc | 8 ++++---- WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php | 9 +++++---- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index ed6bc3e1b7..15533f7ee0 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -82,7 +82,7 @@ abstract class Sniff implements PHPCS_Sniff { * * @var string WordPress version. */ - public $minimum_supported_version = '4.9'; + public $minimum_supported_version = '5.0'; /** * Custom list of classes which test classes can extend. diff --git a/WordPress/Tests/WP/DeprecatedClassesUnitTest.inc b/WordPress/Tests/WP/DeprecatedClassesUnitTest.inc index b0b678d944..02f3dad196 100644 --- a/WordPress/Tests/WP/DeprecatedClassesUnitTest.inc +++ b/WordPress/Tests/WP/DeprecatedClassesUnitTest.inc @@ -13,10 +13,12 @@ echo \WP_User_Search::prepare_query(); class My_User_Search extends WP_User_Search {} class Our_User_Search implements WP_User_Search {} $a = (new WP_User_Search())->query(); +/* ============ WP 4.9 ============ */ +class Prefix_Menu_section extends Customize_New_Menu_Section {} +WP_Customize_New_Menu_Control::foo(); /* * Warning. */ -class Prefix_Menu_section extends Customize_New_Menu_Section {} -WP_Customize_New_Menu_Control::foo(); +/* ============ WP 5.3 ============ */ $json = new Services_JSON; diff --git a/WordPress/Tests/WP/DeprecatedClassesUnitTest.php b/WordPress/Tests/WP/DeprecatedClassesUnitTest.php index 01a0554152..e5abbb46b7 100644 --- a/WordPress/Tests/WP/DeprecatedClassesUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedClassesUnitTest.php @@ -27,7 +27,12 @@ class DeprecatedClassesUnitTest extends AbstractSniffUnitTest { * @return array => */ public function getErrorList() { - return array_fill( 9, 7, 1 ); + $errors = array_fill( 9, 10, 1 ); + + // Unset the lines related to version comments. + unset( $errors[16] ); + + return $errors; } /** @@ -36,7 +41,7 @@ public function getErrorList() { * @return array => */ public function getWarningList() { - return array_fill( 20, 3, 1 ); + return array_fill( 24, 1, 1 ); } } diff --git a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc index 03c075a44b..b7095678b5 100644 --- a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc +++ b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc @@ -329,15 +329,15 @@ wp_get_network(); wp_kses_js_entities(); /* ============ WP 4.8 ============ */ wp_dashboard_plugins_output(); - -/* - * Warning. - */ /* ============ WP 4.9 ============ */ get_shortcut_link(); is_user_option_local(); wp_ajax_press_this_add_category(); wp_ajax_press_this_save_post(); + +/* + * Warning. + */ /* ============ WP 5.1 ============ */ insert_blog(); install_blog(); diff --git a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php index 21a90b3b79..6f20c09dca 100644 --- a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php @@ -28,7 +28,7 @@ class DeprecatedFunctionsUnitTest extends AbstractSniffUnitTest { */ public function getErrorList() { - $errors = array_fill( 8, 324, 1 ); + $errors = array_fill( 8, 329, 1 ); // Unset the lines related to version comments. unset( @@ -62,7 +62,8 @@ public function getErrorList() { $errors[311], $errors[319], $errors[323], - $errors[330] + $errors[330], + $errors[332] ); return $errors; @@ -75,10 +76,10 @@ public function getErrorList() { */ public function getWarningList() { - $warnings = array_fill( 337, 11, 1 ); + $warnings = array_fill( 342, 6, 1 ); // Unset the lines related to version comments. - unset( $warnings[341], $warnings[344] ); + unset( $warnings[344] ); return $warnings; } From 86d7dbca0de9ecde168a733a071886eface9be13 Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Thu, 31 Oct 2019 12:44:50 +0100 Subject: [PATCH 228/241] Adds documentation for WordPress.WP.CronInterval Update WordPress/Docs/WP/CronIntervalStandard.xml Co-Authored-By: Juliette <663378+jrfnl@users.noreply.github.com> Update WordPress/Docs/WP/CronIntervalStandard.xml Co-Authored-By: Juliette <663378+jrfnl@users.noreply.github.com> Update WordPress/Docs/WP/CronIntervalStandard.xml Co-Authored-By: Juliette <663378+jrfnl@users.noreply.github.com> Update WordPress/Docs/WP/CronIntervalStandard.xml Co-Authored-By: Juliette <663378+jrfnl@users.noreply.github.com> Update WordPress/Docs/WP/CronIntervalStandard.xml Co-Authored-By: Juliette <663378+jrfnl@users.noreply.github.com> Seperates function definition --- WordPress/Docs/WP/CronIntervalStandard.xml | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 WordPress/Docs/WP/CronIntervalStandard.xml diff --git a/WordPress/Docs/WP/CronIntervalStandard.xml b/WordPress/Docs/WP/CronIntervalStandard.xml new file mode 100644 index 0000000000..55a9037d47 --- /dev/null +++ b/WordPress/Docs/WP/CronIntervalStandard.xml @@ -0,0 +1,41 @@ + + + + + + + HOUR_IN_SECONDS, + 'display' => __( 'Every hour' ) + ); + return $schedules; +} + +add_filter( + 'cron_schedules', + 'adjust_schedules' +); + ]]> + + + 9 * 60, + 'display' => __( 'Every 9 minutes' ) + ); + return $schedules; +} + +add_filter( + 'cron_schedules', + 'adjust_schedules' +); + ]]> + + + From ae449aa0f511fd08e0cf057fdc85b5660297ce7b Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Sat, 2 Nov 2019 05:54:09 +0100 Subject: [PATCH 229/241] :sparkles: New NamingConventions.ValidPostTypeSlug sniff Adds a new `WordPress.NamingConventions.ValidPostTypeSlug` sniff. Checks if the first parameter given to a register_post_type() call is actually a valid value. --- WordPress-Extra/ruleset.xml | 3 + .../ValidPostTypeSlugStandard.xml | 117 ++++++++++ .../ValidPostTypeSlugSniff.php | 208 ++++++++++++++++++ .../ValidPostTypeSlugUnitTest.inc | 52 +++++ .../ValidPostTypeSlugUnitTest.php | 76 +++++++ 5 files changed, 456 insertions(+) create mode 100644 WordPress/Docs/NamingConventions/ValidPostTypeSlugStandard.xml create mode 100644 WordPress/Sniffs/NamingConventions/ValidPostTypeSlugSniff.php create mode 100644 WordPress/Tests/NamingConventions/ValidPostTypeSlugUnitTest.inc create mode 100644 WordPress/Tests/NamingConventions/ValidPostTypeSlugUnitTest.php diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index a795891878..4a2f95997a 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -130,6 +130,9 @@ + + +