From be850cb35f2dd931c540e6afebf5e43ce7e302f0 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 22 Jul 2017 19:50:04 +0200 Subject: [PATCH 01/10] PHPCS 3.x compat: Namespace all sniffs which extend from one of the WPCS base sniffs Includes adjustment of FQCN references in `@see` and `@uses` documentation. --- .../AbstractArrayAssignmentRestrictionsSniff.php | 6 +++++- WordPress/AbstractClassRestrictionsSniff.php | 6 +++++- WordPress/AbstractFunctionParameterSniff.php | 6 +++++- WordPress/AbstractFunctionRestrictionsSniff.php | 6 +++++- WordPress/AbstractVariableRestrictionsSniff.php | 6 +++++- WordPress/Sniff.php | 4 +++- .../Arrays/ArrayAssignmentRestrictionsSniff.php | 10 ++++++++-- WordPress/Sniffs/Arrays/ArrayDeclarationSniff.php | 6 +++++- .../Sniffs/Arrays/ArrayDeclarationSpacingSniff.php | 7 ++++++- WordPress/Sniffs/Arrays/ArrayIndentationSniff.php | 7 ++++++- .../Arrays/ArrayKeySpacingRestrictionsSniff.php | 7 ++++++- WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php | 7 ++++++- WordPress/Sniffs/CSRF/NonceVerificationSniff.php | 7 ++++++- WordPress/Sniffs/Classes/ClassInstantiationSniff.php | 10 +++++++--- WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php | 7 ++++++- WordPress/Sniffs/DB/RestrictedClassesSniff.php | 7 ++++++- WordPress/Sniffs/DB/RestrictedFunctionsSniff.php | 7 ++++++- WordPress/Sniffs/Files/FileNameSniff.php | 9 +++++++-- WordPress/Sniffs/Functions/DontExtractSniff.php | 7 ++++++- .../Functions/FunctionCallSignatureNoParamsSniff.php | 7 ++++++- .../Sniffs/Functions/FunctionRestrictionsSniff.php | 10 ++++++++-- .../NamingConventions/PrefixAllGlobalsSniff.php | 9 +++++++-- .../NamingConventions/ValidFunctionNameSniff.php | 1 + .../Sniffs/NamingConventions/ValidHookNameSniff.php | 7 ++++++- .../NamingConventions/ValidVariableNameSniff.php | 8 +++++--- WordPress/Sniffs/PHP/DevelopmentFunctionsSniff.php | 7 ++++++- WordPress/Sniffs/PHP/DiscouragedFunctionsSniff.php | 6 +++++- WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php | 7 ++++++- WordPress/Sniffs/PHP/POSIXFunctionsSniff.php | 7 ++++++- WordPress/Sniffs/PHP/StrictComparisonsSniff.php | 7 ++++++- WordPress/Sniffs/PHP/StrictInArraySniff.php | 7 ++++++- WordPress/Sniffs/PHP/YodaConditionsSniff.php | 7 ++++++- WordPress/Sniffs/VIP/AdminBarRemovalSniff.php | 7 ++++++- WordPress/Sniffs/VIP/CronIntervalSniff.php | 7 ++++++- WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php | 7 ++++++- .../Sniffs/VIP/FileSystemWritesDisallowSniff.php | 7 ++++++- WordPress/Sniffs/VIP/OrderByRandSniff.php | 7 ++++++- WordPress/Sniffs/VIP/PluginMenuSlugSniff.php | 7 ++++++- WordPress/Sniffs/VIP/PostsPerPageSniff.php | 7 ++++++- WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php | 7 ++++++- WordPress/Sniffs/VIP/RestrictedVariablesSniff.php | 7 ++++++- WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php | 7 ++++++- WordPress/Sniffs/VIP/SessionVariableUsageSniff.php | 7 ++++++- WordPress/Sniffs/VIP/SlowDBQuerySniff.php | 7 ++++++- WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php | 9 +++++++-- WordPress/Sniffs/VIP/TimezoneChangeSniff.php | 7 ++++++- WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php | 11 ++++++++--- WordPress/Sniffs/Variables/GlobalVariablesSniff.php | 11 +++++++---- .../Sniffs/Variables/VariableRestrictionsSniff.php | 10 ++++++++-- WordPress/Sniffs/WP/AlternativeFunctionsSniff.php | 7 ++++++- WordPress/Sniffs/WP/CapitalPDangitSniff.php | 7 ++++++- WordPress/Sniffs/WP/DeprecatedClassesSniff.php | 7 ++++++- WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php | 7 ++++++- WordPress/Sniffs/WP/DeprecatedParametersSniff.php | 7 ++++++- WordPress/Sniffs/WP/DiscouragedFunctionsSniff.php | 7 ++++++- WordPress/Sniffs/WP/EnqueuedResourcesSniff.php | 7 ++++++- WordPress/Sniffs/WP/I18nSniff.php | 7 ++++++- WordPress/Sniffs/WP/PreparedSQLSniff.php | 7 ++++++- .../Sniffs/WhiteSpace/CastStructureSpacingSniff.php | 7 ++++++- .../WhiteSpace/ControlStructureSpacingSniff.php | 7 ++++++- .../Sniffs/WhiteSpace/DisallowInlineTabsSniff.php | 7 ++++++- WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php | 1 + WordPress/Sniffs/XSS/EscapeOutputSniff.php | 9 +++++++-- 63 files changed, 371 insertions(+), 77 deletions(-) diff --git a/WordPress/AbstractArrayAssignmentRestrictionsSniff.php b/WordPress/AbstractArrayAssignmentRestrictionsSniff.php index c5cf5fd86b..b5558e14ed 100644 --- a/WordPress/AbstractArrayAssignmentRestrictionsSniff.php +++ b/WordPress/AbstractArrayAssignmentRestrictionsSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress; + +use WordPress\Sniff; + /** * Restricts array assignment of certain keys. * @@ -18,7 +22,7 @@ * `WordPress_Sniffs_Arrays_ArrayAssignmentRestrictionsSniff` to * `WordPress_AbstractArrayAssignmentRestrictionsSniff`. */ -abstract class WordPress_AbstractArrayAssignmentRestrictionsSniff extends WordPress_Sniff { +abstract class AbstractArrayAssignmentRestrictionsSniff extends Sniff { /** * Exclude groups. diff --git a/WordPress/AbstractClassRestrictionsSniff.php b/WordPress/AbstractClassRestrictionsSniff.php index c83dc7e662..b37cd490fe 100644 --- a/WordPress/AbstractClassRestrictionsSniff.php +++ b/WordPress/AbstractClassRestrictionsSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress; + +use WordPress\AbstractFunctionRestrictionsSniff; + /** * Restricts usage of some classes. * @@ -14,7 +18,7 @@ * * @since 0.10.0 */ -abstract class WordPress_AbstractClassRestrictionsSniff extends WordPress_AbstractFunctionRestrictionsSniff { +abstract class AbstractClassRestrictionsSniff extends AbstractFunctionRestrictionsSniff { /** * Regex pattern with placeholder for the class names. diff --git a/WordPress/AbstractFunctionParameterSniff.php b/WordPress/AbstractFunctionParameterSniff.php index f9e7fbc6d5..b201354aa1 100644 --- a/WordPress/AbstractFunctionParameterSniff.php +++ b/WordPress/AbstractFunctionParameterSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress; + +use WordPress\AbstractFunctionRestrictionsSniff; + /** * Advises about parameters used in function calls. * @@ -14,7 +18,7 @@ * * @since 0.11.0 */ -abstract class WordPress_AbstractFunctionParameterSniff extends WordPress_AbstractFunctionRestrictionsSniff { +abstract class AbstractFunctionParameterSniff extends AbstractFunctionRestrictionsSniff { /** * The group name for this group of functions. diff --git a/WordPress/AbstractFunctionRestrictionsSniff.php b/WordPress/AbstractFunctionRestrictionsSniff.php index 81fe126abd..a607d21edf 100644 --- a/WordPress/AbstractFunctionRestrictionsSniff.php +++ b/WordPress/AbstractFunctionRestrictionsSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress; + +use WordPress\Sniff; + /** * Restricts usage of some functions. * @@ -19,7 +23,7 @@ * `WordPress_AbstractFunctionRestrictionsSniff`. * @since 0.11.0 Extends the WordPress_Sniff class. */ -abstract class WordPress_AbstractFunctionRestrictionsSniff extends WordPress_Sniff { +abstract class AbstractFunctionRestrictionsSniff extends Sniff { /** * Exclude groups. diff --git a/WordPress/AbstractVariableRestrictionsSniff.php b/WordPress/AbstractVariableRestrictionsSniff.php index 324f4853c9..5ed71212ee 100644 --- a/WordPress/AbstractVariableRestrictionsSniff.php +++ b/WordPress/AbstractVariableRestrictionsSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress; + +use WordPress\Sniff; + /** * Restricts usage of some variables. * @@ -19,7 +23,7 @@ * `WordPress_AbstractVariableRestrictionsSniff`. * @since 0.11.0 Extends the WordPress_Sniff class. */ -abstract class WordPress_AbstractVariableRestrictionsSniff extends WordPress_Sniff { +abstract class AbstractVariableRestrictionsSniff extends Sniff { /** * Exclude groups. diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index e3746dc5e7..ec47c6dd16 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -7,6 +7,8 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress; + /** * Represents a PHP_CodeSniffer sniff for sniffing WordPress coding standards. * @@ -26,7 +28,7 @@ * In the rare few cases where the array values *do* have meaning, this * is documented in the property documentation.}} */ -abstract class WordPress_Sniff implements PHP_CodeSniffer_Sniff { +abstract class Sniff implements PHP_CodeSniffer_Sniff { /** * List of the functions which verify nonces. diff --git a/WordPress/Sniffs/Arrays/ArrayAssignmentRestrictionsSniff.php b/WordPress/Sniffs/Arrays/ArrayAssignmentRestrictionsSniff.php index 5fbe91df93..f48d1e2cb2 100644 --- a/WordPress/Sniffs/Arrays/ArrayAssignmentRestrictionsSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayAssignmentRestrictionsSniff.php @@ -7,21 +7,27 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\Arrays; + +use WordPress\AbstractArrayAssignmentRestrictionsSniff; + /** * Restricts array assignment of certain keys. * * @package WPCS\WordPressCodingStandards * * @since 0.3.0 + * @since 0.13.0 Class name changed: this class is now namespaced. + * * @deprecated 0.10.0 The functionality which used to be contained in this class has been moved to * the WordPress_AbstractArrayAssignmentRestrictionsSniff class. * This class is left here to prevent backward-compatibility breaks for * custom sniffs extending the old class and references to this * sniff from custom phpcs.xml files. * This file is also still used to unit test the abstract class. - * @see WordPress_AbstractArrayAssignmentRestrictionsSniff + * @see \WordPress\AbstractArrayAssignmentRestrictionsSniff */ -class WordPress_Sniffs_Arrays_ArrayAssignmentRestrictionsSniff extends WordPress_AbstractArrayAssignmentRestrictionsSniff { +class ArrayAssignmentRestrictionsSniff extends AbstractArrayAssignmentRestrictionsSniff { /** * Groups of variables to restrict. diff --git a/WordPress/Sniffs/Arrays/ArrayDeclarationSniff.php b/WordPress/Sniffs/Arrays/ArrayDeclarationSniff.php index b3fbb4560a..9f3e593d74 100644 --- a/WordPress/Sniffs/Arrays/ArrayDeclarationSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayDeclarationSniff.php @@ -7,6 +7,8 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\Arrays; + /** * Enforces WordPress array format, based upon Squiz code. * @@ -19,6 +21,8 @@ * @since 0.11.0 The additional single-line array checks have been moved to their own * sniff WordPress.Arrays.ArrayDeclarationSpacing. * This class now only contains a slimmed down version of the upstream sniff. + * @since 0.13.0 Class name changed: this class is now namespaced. + * * @deprecated 0.13.0 This sniff has now been deprecated. Most checks which were previously * contained herein had recently been excluded in favour of dedicated * sniffs with higher precision. The last remaining checks which were not @@ -27,7 +31,7 @@ * This class is left here to prevent breaking custom rulesets which refer * to this sniff. */ -class WordPress_Sniffs_Arrays_ArrayDeclarationSniff { +class ArrayDeclarationSniff { /** * Don't use. diff --git a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php index 3d7c985cc5..36c075e18d 100644 --- a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\Arrays; + +use WordPress\Sniff; + /** * Enforces WordPress array spacing format. * @@ -30,8 +34,9 @@ * @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. + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_Arrays_ArrayDeclarationSpacingSniff extends WordPress_Sniff { +class ArrayDeclarationSpacingSniff extends Sniff { /** * Token this sniff targets. diff --git a/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php b/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php index 29fb9f6001..9a67948759 100644 --- a/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\Arrays; + +use WordPress\Sniff; + /** * Enforces WordPress array indentation for multi-line arrays. * @@ -15,11 +19,12 @@ * @package WPCS\WordPressCodingStandards * * @since 0.12.0 + * @since 0.13.0 Class name changed: this class is now namespaced. * * {@internal This sniff should eventually be pulled upstream as part of a solution * for https://github.com/squizlabs/PHP_CodeSniffer/issues/582 }} */ -class WordPress_Sniffs_Arrays_ArrayIndentationSniff extends WordPress_Sniff { +class ArrayIndentationSniff extends Sniff { /** * Should tabs be used for indenting? diff --git a/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php b/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php index 851bf91e1f..73e38aa686 100644 --- a/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\Arrays; + +use WordPress\Sniff; + /** * Check for proper spacing in array key references. * @@ -17,8 +21,9 @@ * @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.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_Arrays_ArrayKeySpacingRestrictionsSniff extends WordPress_Sniff { +class ArrayKeySpacingRestrictionsSniff extends Sniff { /** * Returns an array of tokens this test wants to listen for. diff --git a/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php b/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php index 04b5d5661e..f2ef82522d 100644 --- a/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php +++ b/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\Arrays; + +use WordPress\Sniff; + /** * Enforces a comma after each array item and the spacing around it. * @@ -22,8 +26,9 @@ * @package WPCS\WordPressCodingStandards * * @since 0.12.0 + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_Arrays_CommaAfterArrayItemSniff extends WordPress_Sniff { +class CommaAfterArrayItemSniff extends Sniff { /** * Returns an array of tokens this test wants to listen for. diff --git a/WordPress/Sniffs/CSRF/NonceVerificationSniff.php b/WordPress/Sniffs/CSRF/NonceVerificationSniff.php index 215b67ea6d..d9828410df 100644 --- a/WordPress/Sniffs/CSRF/NonceVerificationSniff.php +++ b/WordPress/Sniffs/CSRF/NonceVerificationSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\CSRF; + +use WordPress\Sniff; + /** * Checks that nonce verification accompanies form processing. * @@ -15,8 +19,9 @@ * @package WPCS\WordPressCodingStandards * * @since 0.5.0 + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_CSRF_NonceVerificationSniff extends WordPress_Sniff { +class NonceVerificationSniff extends Sniff { /** * Superglobals to notify about when not accompanied by an nonce check. diff --git a/WordPress/Sniffs/Classes/ClassInstantiationSniff.php b/WordPress/Sniffs/Classes/ClassInstantiationSniff.php index e2a646f598..2465a66c83 100644 --- a/WordPress/Sniffs/Classes/ClassInstantiationSniff.php +++ b/WordPress/Sniffs/Classes/ClassInstantiationSniff.php @@ -7,10 +7,13 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\Classes; + +use WordPress\Sniff; + /** - * WordPress_Sniffs_Classes_ClassInstantiationSniff. - * * Verifies object instantiation statements. + * * - Demand the use of parenthesis. * - Demand no space between the class name and the parenthesis. * - Forbid assigning new by reference. @@ -21,8 +24,9 @@ * @package WPCS\WordPressCodingStandards * * @since 0.12.0 + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_Classes_ClassInstantiationSniff extends WordPress_Sniff { +class ClassInstantiationSniff extends Sniff { /** * A list of tokenizers this sniff supports. diff --git a/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php b/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php index 07ad7d4732..3778fd0372 100644 --- a/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php +++ b/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\CodeAnalysis; + +use WordPress\Sniff; + /** * Checks against empty statements. * @@ -22,8 +26,9 @@ * @package WPCS\WordPressCodingStandards * * @since 0.12.0 + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_CodeAnalysis_EmptyStatementSniff extends WordPress_Sniff { +class EmptyStatementSniff extends Sniff { /** * Returns an array of tokens this test wants to listen for. diff --git a/WordPress/Sniffs/DB/RestrictedClassesSniff.php b/WordPress/Sniffs/DB/RestrictedClassesSniff.php index 37ca463e3a..1083c86c96 100644 --- a/WordPress/Sniffs/DB/RestrictedClassesSniff.php +++ b/WordPress/Sniffs/DB/RestrictedClassesSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\DB; + +use WordPress\AbstractClassRestrictionsSniff; + /** * Verifies that no database related PHP classes are used. * @@ -20,8 +24,9 @@ * @package WPCS\WordPressCodingStandards * * @since 0.10.0 + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_DB_RestrictedClassesSniff extends WordPress_AbstractClassRestrictionsSniff { +class RestrictedClassesSniff extends AbstractClassRestrictionsSniff { /** * Groups of classes to restrict. diff --git a/WordPress/Sniffs/DB/RestrictedFunctionsSniff.php b/WordPress/Sniffs/DB/RestrictedFunctionsSniff.php index 56a84f788d..557d5771e5 100644 --- a/WordPress/Sniffs/DB/RestrictedFunctionsSniff.php +++ b/WordPress/Sniffs/DB/RestrictedFunctionsSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\DB; + +use WordPress\AbstractFunctionRestrictionsSniff; + /** * Verifies that no database related PHP functions are used. * @@ -20,8 +24,9 @@ * @package WPCS\WordPressCodingStandards * * @since 0.10.0 + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_DB_RestrictedFunctionsSniff extends WordPress_AbstractFunctionRestrictionsSniff { +class RestrictedFunctionsSniff extends AbstractFunctionRestrictionsSniff { /** * Groups of functions to restrict. diff --git a/WordPress/Sniffs/Files/FileNameSniff.php b/WordPress/Sniffs/Files/FileNameSniff.php index cec2fa4f50..624edc49d9 100644 --- a/WordPress/Sniffs/Files/FileNameSniff.php +++ b/WordPress/Sniffs/Files/FileNameSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\Files; + +use WordPress\Sniff; + /** * Ensures filenames do not contain underscores. * @@ -22,10 +26,11 @@ * - 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.13.0 Class name changed: this class is now namespaced. * - * @uses WordPress_Sniff::$custom_test_class_whitelist + * @uses \WordPress\Sniff::$custom_test_class_whitelist */ -class WordPress_Sniffs_Files_FileNameSniff extends WordPress_Sniff { +class FileNameSniff extends Sniff { /** * Regex for the theme specific exceptions. diff --git a/WordPress/Sniffs/Functions/DontExtractSniff.php b/WordPress/Sniffs/Functions/DontExtractSniff.php index 3cf949916b..026e6cc52e 100644 --- a/WordPress/Sniffs/Functions/DontExtractSniff.php +++ b/WordPress/Sniffs/Functions/DontExtractSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\Functions; + +use WordPress\AbstractFunctionRestrictionsSniff; + /** * Restricts the usage of extract(). * @@ -15,8 +19,9 @@ * @package WPCS\WordPressCodingStandards * * @since 0.10.0 Previously this check was contained within WordPress_Sniffs_VIP_RestrictedFunctionsSniff. + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_Functions_DontExtractSniff extends WordPress_AbstractFunctionRestrictionsSniff { +class DontExtractSniff extends AbstractFunctionRestrictionsSniff { /** * Groups of functions to restrict. diff --git a/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php b/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php index 1d9bcafcd1..0f94a1f144 100644 --- a/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php +++ b/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\Functions; + +use WordPress\Sniff; + /** * Enforces no whitespace between the parenthesis of a function call without parameters. * @@ -15,8 +19,9 @@ * @package WPCS\WordPressCodingStandards * * @since 0.12.0 + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_Functions_FunctionCallSignatureNoParamsSniff extends WordPress_Sniff { +class FunctionCallSignatureNoParamsSniff extends Sniff { /** * Returns an array of tokens this test wants to listen for. diff --git a/WordPress/Sniffs/Functions/FunctionRestrictionsSniff.php b/WordPress/Sniffs/Functions/FunctionRestrictionsSniff.php index 483e6cb03f..af829d27d0 100644 --- a/WordPress/Sniffs/Functions/FunctionRestrictionsSniff.php +++ b/WordPress/Sniffs/Functions/FunctionRestrictionsSniff.php @@ -7,20 +7,26 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\Functions; + +use WordPress\AbstractFunctionRestrictionsSniff; + /** * Restricts usage of some functions. * * @package WPCS\WordPressCodingStandards * * @since 0.3.0 + * @since 0.13.0 Class name changed: this class is now namespaced. + * * @deprecated 0.10.0 The functionality which used to be contained in this class has been moved to * the WordPress_AbstractFunctionRestrictionsSniff class. * This class is left here to prevent backward-compatibility breaks for * custom sniffs extending the old class and references to this * sniff from custom phpcs.xml files. - * @see WordPress_AbstractFunctionRestrictionsSniff + * @see \WordPress\AbstractFunctionRestrictionsSniff */ -class WordPress_Sniffs_Functions_FunctionRestrictionsSniff extends WordPress_AbstractFunctionRestrictionsSniff { +class FunctionRestrictionsSniff extends AbstractFunctionRestrictionsSniff { /** * Groups of functions to restrict. diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index 856aed26d9..fecbac8773 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -7,16 +7,21 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\NamingConventions; + +use WordPress\AbstractFunctionParameterSniff; + /** * Verify that everything defined in the global namespace is prefixed with a theme/plugin specific prefix. * * @package WPCS\WordPressCodingStandards * * @since 0.12.0 + * @since 0.13.0 Class name changed: this class is now namespaced. * - * @uses WordPress_Sniff::$custom_test_class_whitelist + * @uses \WordPress\Sniff::$custom_test_class_whitelist */ -class WordPress_Sniffs_NamingConventions_PrefixAllGlobalsSniff extends WordPress_AbstractFunctionParameterSniff { +class PrefixAllGlobalsSniff extends AbstractFunctionParameterSniff { /** * Error message template. diff --git a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php index d23effcca8..d4b5f3a9a4 100644 --- a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -19,6 +19,7 @@ * @package WPCS\WordPressCodingStandards * * @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. * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidFunctionNameSniff.php diff --git a/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php index bc4b13611b..0974b7d7a0 100644 --- a/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\NamingConventions; + +use WordPress\AbstractFunctionParameterSniff; + /** * Use lowercase letters in action and filter names. Separate words via underscores. * @@ -21,8 +25,9 @@ * * @since 0.10.0 * @since 0.11.0 Extends the WordPress_AbstractFunctionParameterSniff class. + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_NamingConventions_ValidHookNameSniff extends WordPress_AbstractFunctionParameterSniff { +class ValidHookNameSniff extends AbstractFunctionParameterSniff { /** * Additional word separators. diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index 55a353b700..deac96a7c5 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -10,6 +10,7 @@ if ( ! class_exists( 'PHP_CodeSniffer_Standards_AbstractVariableSniff', true ) ) { throw new PHP_CodeSniffer_Exception( 'Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found' ); } +use WordPress\Sniff; /** * Checks the naming of variables and member variables. @@ -19,6 +20,7 @@ * @package WPCS\WordPressCodingStandards * * @since 0.9.0 + * @since 0.13.0 Class name changed: this class is now namespaced. * * Last synced with base class July 2014 at commit ed257ca0e56ad86cd2a4d6fa38ce0b95141c824f. * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -301,10 +303,10 @@ protected function mergeWhiteList( $phpcs_file ) { || $this->customVariablesWhitelist !== $this->addedCustomProperties['variables'] ) { // Fix property potentially passed as comma-delimited string. - $customProperties = WordPress_Sniff::merge_custom_array( $this->customPropertiesWhitelist, array(), false ); + $customProperties = Sniff::merge_custom_array( $this->customPropertiesWhitelist, array(), false ); if ( ! empty( $this->customVariablesWhitelist ) ) { - $customProperties = WordPress_Sniff::merge_custom_array( + $customProperties = Sniff::merge_custom_array( $this->customVariablesWhitelist, $customProperties, false @@ -317,7 +319,7 @@ protected function mergeWhiteList( $phpcs_file ) { ); } - $this->whitelisted_mixed_case_member_var_names = WordPress_Sniff::merge_custom_array( + $this->whitelisted_mixed_case_member_var_names = Sniff::merge_custom_array( $customProperties, $this->whitelisted_mixed_case_member_var_names ); diff --git a/WordPress/Sniffs/PHP/DevelopmentFunctionsSniff.php b/WordPress/Sniffs/PHP/DevelopmentFunctionsSniff.php index bf2e83654b..a38d190c1a 100644 --- a/WordPress/Sniffs/PHP/DevelopmentFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/DevelopmentFunctionsSniff.php @@ -7,14 +7,19 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\PHP; + +use WordPress\AbstractFunctionRestrictionsSniff; + /** * Restrict the use of various development functions. * * @package WPCS\WordPressCodingStandards * * @since 0.11.0 + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_PHP_DevelopmentFunctionsSniff extends WordPress_AbstractFunctionRestrictionsSniff { +class DevelopmentFunctionsSniff extends AbstractFunctionRestrictionsSniff { /** * Groups of functions to restrict. diff --git a/WordPress/Sniffs/PHP/DiscouragedFunctionsSniff.php b/WordPress/Sniffs/PHP/DiscouragedFunctionsSniff.php index e141eb9446..cef9e83136 100644 --- a/WordPress/Sniffs/PHP/DiscouragedFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/DiscouragedFunctionsSniff.php @@ -7,6 +7,8 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\PHP; + /** * Discourages the use of various native PHP functions and suggests alternatives. * @@ -15,6 +17,8 @@ * @since 0.1.0 * @since 0.10.0 The checks for the POSIX functions have been replaced by the stand-alone * sniff WordPress_Sniffs_PHP_POSIXFunctionsSniff. + * @since 0.13.0 Class name changed: this class is now namespaced. + * * @deprecated 0.11.0 The checks for the PHP development functions have been replaced by the * stand-alone sniff WordPress_Sniffs_PHP_DevelopmentFunctionsSniff. * The checks for the WP deprecated functions have been replaced by the @@ -29,7 +33,7 @@ * function. To check for `register_globals` ini directive use * PHPCompatibility_Sniffs_PHP_DeprecatedIniDirectivesSniff from wimg/PHPCompatibility. */ -class WordPress_Sniffs_PHP_DiscouragedFunctionsSniff { +class DiscouragedFunctionsSniff { /** * Don't use. diff --git a/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php b/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php index 4b8ca5c4c1..a6e12e139c 100644 --- a/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php @@ -7,14 +7,19 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\PHP; + +use WordPress\AbstractFunctionRestrictionsSniff; + /** * Discourages the use of various native PHP functions and suggests alternatives. * * @package WPCS\WordPressCodingStandards * * @since 0.11.0 + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_PHP_DiscouragedPHPFunctionsSniff extends WordPress_AbstractFunctionRestrictionsSniff { +class DiscouragedPHPFunctionsSniff extends AbstractFunctionRestrictionsSniff { /** * Groups of functions to discourage. diff --git a/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php b/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php index 936bdedf1d..cab71a4e16 100644 --- a/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\PHP; + +use WordPress\AbstractFunctionRestrictionsSniff; + /** * Perl compatible regular expressions (PCRE, preg_ functions) should be used in preference * to their POSIX counterparts. @@ -18,8 +22,9 @@ * * @since 0.10.0 Previously this check was contained within WordPress_Sniffs_VIP_RestrictedFunctionsSniff * and the WordPress_Sniffs_PHP_DiscouragedPHPFunctionsSniff. + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_PHP_POSIXFunctionsSniff extends WordPress_AbstractFunctionRestrictionsSniff { +class POSIXFunctionsSniff extends AbstractFunctionRestrictionsSniff { /** * Groups of functions to restrict. diff --git a/WordPress/Sniffs/PHP/StrictComparisonsSniff.php b/WordPress/Sniffs/PHP/StrictComparisonsSniff.php index c87d9a0b9c..e24b98b4b9 100644 --- a/WordPress/Sniffs/PHP/StrictComparisonsSniff.php +++ b/WordPress/Sniffs/PHP/StrictComparisonsSniff.php @@ -7,19 +7,24 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\PHP; + +use WordPress\Sniff; + /** * Enforces Strict Comparison checks, based upon Squiz code. * * @package WPCS\WordPressCodingStandards * * @since 0.4.0 + * @since 0.13.0 Class name changed: this class is now namespaced. * * Last synced with base class ?[unknown date]? at commit ?[unknown commit]?. * It is currently unclear whether this sniff is actually based on Squiz code on whether the above * reference to it is a copy/paste oversight. * @link Possibly: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/Operators/ComparisonOperatorUsageSniff.php */ -class WordPress_Sniffs_PHP_StrictComparisonsSniff extends WordPress_Sniff { +class StrictComparisonsSniff extends Sniff { /** * Returns an array of tokens this test wants to listen for. diff --git a/WordPress/Sniffs/PHP/StrictInArraySniff.php b/WordPress/Sniffs/PHP/StrictInArraySniff.php index cc67f244bb..45a68b9e88 100644 --- a/WordPress/Sniffs/PHP/StrictInArraySniff.php +++ b/WordPress/Sniffs/PHP/StrictInArraySniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\PHP; + +use WordPress\AbstractFunctionParameterSniff; + /** * Flag calling in_array(), array_search() and array_keys() without true as the third parameter. * @@ -19,8 +23,9 @@ * 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.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_PHP_StrictInArraySniff extends WordPress_AbstractFunctionParameterSniff { +class StrictInArraySniff extends AbstractFunctionParameterSniff { /** * The group name for this group of functions. diff --git a/WordPress/Sniffs/PHP/YodaConditionsSniff.php b/WordPress/Sniffs/PHP/YodaConditionsSniff.php index 8cf7e99632..dda70d79ce 100644 --- a/WordPress/Sniffs/PHP/YodaConditionsSniff.php +++ b/WordPress/Sniffs/PHP/YodaConditionsSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\PHP; + +use WordPress\Sniff; + /** * Enforces Yoda conditional statements. * @@ -16,8 +20,9 @@ * * @since 0.3.0 * @since 0.12.0 This class now extends WordPress_Sniff. + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_PHP_YodaConditionsSniff extends WordPress_Sniff { +class YodaConditionsSniff extends Sniff { /** * The tokens that indicate the start of a condition. diff --git a/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php b/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php index 0dd2c5c4f0..a9343d6213 100644 --- a/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php +++ b/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\VIP; + +use WordPress\AbstractFunctionParameterSniff; + /** * Discourages removal of the admin bar. * @@ -18,8 +22,9 @@ * @since 0.11.0 - Extends the WordPress_AbstractFunctionParameterSniff class. * - Added the $remove_only property. * - Now also sniffs for manipulation of the admin bar visibility through CSS. + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_VIP_AdminBarRemovalSniff extends WordPress_AbstractFunctionParameterSniff { +class AdminBarRemovalSniff extends AbstractFunctionParameterSniff { /** * A list of tokenizers this sniff supports. diff --git a/WordPress/Sniffs/VIP/CronIntervalSniff.php b/WordPress/Sniffs/VIP/CronIntervalSniff.php index 1c255a5a5e..1c30f47821 100644 --- a/WordPress/Sniffs/VIP/CronIntervalSniff.php +++ b/WordPress/Sniffs/VIP/CronIntervalSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\VIP; + +use WordPress\Sniff; + /** * Flag cron schedules less than 15 minutes. * @@ -17,8 +21,9 @@ * @since 0.3.0 * @since 0.11.0 - Extends the WordPress_Sniff class. * - Now deals correctly with WP time constants. + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_VIP_CronIntervalSniff extends WordPress_Sniff { +class CronIntervalSniff extends Sniff { /** * Known WP Time constant names and their value. diff --git a/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php b/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php index eb92de3781..a7aa844467 100644 --- a/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php +++ b/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\VIP; + +use WordPress\Sniff; + /** * Flag Database direct queries. * @@ -18,8 +22,9 @@ * @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.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_VIP_DirectDatabaseQuerySniff extends WordPress_Sniff { +class DirectDatabaseQuerySniff extends Sniff { /** * List of custom cache get functions. diff --git a/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php b/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php index e535328f18..104a71a448 100644 --- a/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php +++ b/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\VIP; + +use WordPress\AbstractFunctionRestrictionsSniff; + /** * Disallow Filesystem writes. * @@ -17,8 +21,9 @@ * @since 0.3.0 * @since 0.11.0 Extends the WordPress_AbstractFunctionRestrictionsSniff instead of the * Generic_Sniffs_PHP_ForbiddenFunctionsSniff. + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_VIP_FileSystemWritesDisallowSniff extends WordPress_AbstractFunctionRestrictionsSniff { +class FileSystemWritesDisallowSniff extends AbstractFunctionRestrictionsSniff { /** * If true, an error will be thrown; otherwise a warning. diff --git a/WordPress/Sniffs/VIP/OrderByRandSniff.php b/WordPress/Sniffs/VIP/OrderByRandSniff.php index 158a11312c..e592a98900 100644 --- a/WordPress/Sniffs/VIP/OrderByRandSniff.php +++ b/WordPress/Sniffs/VIP/OrderByRandSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\VIP; + +use WordPress\AbstractArrayAssignmentRestrictionsSniff; + /** * Flag using orderby => rand. * @@ -15,8 +19,9 @@ * @package WPCS\WordPressCodingStandards * * @since 0.9.0 + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_VIP_OrderByRandSniff extends WordPress_AbstractArrayAssignmentRestrictionsSniff { +class OrderByRandSniff extends AbstractArrayAssignmentRestrictionsSniff { /** * Groups of variables to restrict. diff --git a/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php b/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php index e99b0b202f..655d9e7965 100644 --- a/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php +++ b/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\VIP; + +use WordPress\AbstractFunctionParameterSniff; + /** * Warn about __FILE__ for page registration. * @@ -16,8 +20,9 @@ * * @since 0.3.0 * @since 0.11.0 Refactored to extend the new WordPress_AbstractFunctionParameterSniff. + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_VIP_PluginMenuSlugSniff extends WordPress_AbstractFunctionParameterSniff { +class PluginMenuSlugSniff extends AbstractFunctionParameterSniff { /** * The group name for this group of functions. diff --git a/WordPress/Sniffs/VIP/PostsPerPageSniff.php b/WordPress/Sniffs/VIP/PostsPerPageSniff.php index 6db73490ad..d4f28adcb1 100644 --- a/WordPress/Sniffs/VIP/PostsPerPageSniff.php +++ b/WordPress/Sniffs/VIP/PostsPerPageSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\VIP; + +use WordPress\AbstractArrayAssignmentRestrictionsSniff; + /** * Flag returning high or infinite posts_per_page. * @@ -15,8 +19,9 @@ * @package WPCS\WordPressCodingStandards * * @since 0.3.0 + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_VIP_PostsPerPageSniff extends WordPress_AbstractArrayAssignmentRestrictionsSniff { +class PostsPerPageSniff extends AbstractArrayAssignmentRestrictionsSniff { /** * Groups of variables to restrict. diff --git a/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php b/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php index cb58395a72..41914ec235 100644 --- a/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php +++ b/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\VIP; + +use WordPress\AbstractFunctionRestrictionsSniff; + /** * Restricts usage of some functions in VIP context. * @@ -24,8 +28,9 @@ * The check for `parse_url()` and `curl_*` have been moved to the stand-alone sniff * WordPress_Sniffs_WP_AlternativeFunctionsSniff. * The check for `eval()` now defers to the upstream Squiz.PHP.Eval sniff. + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_VIP_RestrictedFunctionsSniff extends WordPress_AbstractFunctionRestrictionsSniff { +class RestrictedFunctionsSniff extends AbstractFunctionRestrictionsSniff { /** * Groups of functions to restrict. diff --git a/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php b/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php index d184daed85..05737ceb59 100644 --- a/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php +++ b/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\VIP; + +use WordPress\AbstractVariableRestrictionsSniff; + /** * Restricts usage of some variables in VIP context. * @@ -15,8 +19,9 @@ * @package WPCS\WordPressCodingStandards * * @since 0.3.0 + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_VIP_RestrictedVariablesSniff extends WordPress_AbstractVariableRestrictionsSniff { +class RestrictedVariablesSniff extends AbstractVariableRestrictionsSniff { /** * Groups of variables to restrict. diff --git a/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php b/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php index 96ed685c86..9ae5c0f1fc 100644 --- a/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php +++ b/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\VIP; + +use WordPress\AbstractFunctionRestrictionsSniff; + /** * Discourages the use of session functions. * @@ -17,8 +21,9 @@ * @since 0.3.0 * @since 0.11.0 Extends the WordPress_AbstractFunctionRestrictionsSniff instead of the * Generic_Sniffs_PHP_ForbiddenFunctionsSniff. + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_VIP_SessionFunctionsUsageSniff extends WordPress_AbstractFunctionRestrictionsSniff { +class SessionFunctionsUsageSniff extends AbstractFunctionRestrictionsSniff { /** * Groups of functions to restrict. diff --git a/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php b/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php index f4b48639fe..74edbef6d4 100644 --- a/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php +++ b/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\VIP; + +use WordPress\Sniff; + /** * Discourages the use of the session variable. * Creating a session writes a file to the server and is unreliable in a multi-server environment. @@ -19,8 +23,9 @@ * @since 0.10.0 The sniff no longer needlessly extends the Generic_Sniffs_PHP_ForbiddenFunctionsSniff * which it didn't use. * @since 0.12.0 This class now extends WordPress_Sniff. + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_VIP_SessionVariableUsageSniff extends WordPress_Sniff { +class SessionVariableUsageSniff extends Sniff { /** * Returns an array of tokens this test wants to listen for. diff --git a/WordPress/Sniffs/VIP/SlowDBQuerySniff.php b/WordPress/Sniffs/VIP/SlowDBQuerySniff.php index 9485cd414d..d3b022fe0a 100644 --- a/WordPress/Sniffs/VIP/SlowDBQuerySniff.php +++ b/WordPress/Sniffs/VIP/SlowDBQuerySniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\VIP; + +use WordPress\AbstractArrayAssignmentRestrictionsSniff; + /** * Flag potentially slow queries. * @@ -18,8 +22,9 @@ * @since 0.12.0 Introduced new and more intuitively named 'slow query' whitelist * comment, replacing the 'tax_query' whitelist comment which is now * deprecated. + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_VIP_SlowDBQuerySniff extends WordPress_AbstractArrayAssignmentRestrictionsSniff { +class SlowDBQuerySniff extends AbstractArrayAssignmentRestrictionsSniff { /** * Groups of variables to restrict. diff --git a/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php b/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php index 5c492065fe..c3b7737250 100644 --- a/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php +++ b/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\VIP; + +use WordPress\Sniff; + /** * Flag any usage of super global input var ( _GET / _POST / etc. ). * @@ -15,9 +19,10 @@ * @package WPCS\WordPressCodingStandards * * @since 0.3.0 - * @since 0.4.0 This class now extends WordPress_Sniff. + * @since 0.4.0 This class now extends WordPress_Sniff. + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_VIP_SuperGlobalInputUsageSniff extends WordPress_Sniff { +class SuperGlobalInputUsageSniff extends Sniff { /** * Returns an array of tokens this test wants to listen for. diff --git a/WordPress/Sniffs/VIP/TimezoneChangeSniff.php b/WordPress/Sniffs/VIP/TimezoneChangeSniff.php index 2fe0fc1c01..5740f9eb7e 100644 --- a/WordPress/Sniffs/VIP/TimezoneChangeSniff.php +++ b/WordPress/Sniffs/VIP/TimezoneChangeSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\VIP; + +use WordPress\AbstractFunctionRestrictionsSniff; + /** * Disallow the changing of timezone. * @@ -17,8 +21,9 @@ * @since 0.3.0 * @since 0.11.0 Extends the WordPress_AbstractFunctionRestrictionsSniff instead of the * Generic_Sniffs_PHP_ForbiddenFunctionsSniff. + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_VIP_TimezoneChangeSniff extends WordPress_AbstractFunctionRestrictionsSniff { +class TimezoneChangeSniff extends AbstractFunctionRestrictionsSniff { /** * Groups of functions to restrict. diff --git a/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php b/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php index 3edc57549f..04a5e8701f 100644 --- a/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php +++ b/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\VIP; + +use WordPress\Sniff; + /** * Flag any non-validated/sanitized input ( _GET / _POST / etc. ). * @@ -15,10 +19,11 @@ * @package WPCS\WordPressCodingStandards * * @since 0.3.0 - * @since 0.4.0 This class now extends WordPress_Sniff. - * @since 0.5.0 Method getArrayIndexKey() has been moved to WordPress_Sniff. + * @since 0.4.0 This class now extends WordPress_Sniff. + * @since 0.5.0 Method getArrayIndexKey() has been moved to WordPress_Sniff. + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_VIP_ValidatedSanitizedInputSniff extends WordPress_Sniff { +class ValidatedSanitizedInputSniff extends Sniff { /** * Check for validation functions for a variable within its own parenthesis only. diff --git a/WordPress/Sniffs/Variables/GlobalVariablesSniff.php b/WordPress/Sniffs/Variables/GlobalVariablesSniff.php index 55214417eb..68386b7c4f 100644 --- a/WordPress/Sniffs/Variables/GlobalVariablesSniff.php +++ b/WordPress/Sniffs/Variables/GlobalVariablesSniff.php @@ -7,9 +7,11 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\Variables; + +use WordPress\Sniff; + /** - * WordPress_Sniffs_Variables_GlobalVariablesSniff. - * * Warns about overwriting WordPress native global variables. * * @package WPCS\WordPressCodingStandards @@ -17,10 +19,11 @@ * @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.13.0 Class name changed: this class is now namespaced. * - * @uses WordPress_Sniff::$custom_test_class_whitelist + * @uses \WordPress\Sniff::$custom_test_class_whitelist */ -class WordPress_Sniffs_Variables_GlobalVariablesSniff extends WordPress_Sniff { +class GlobalVariablesSniff extends Sniff { /** * Returns an array of tokens this test wants to listen for. diff --git a/WordPress/Sniffs/Variables/VariableRestrictionsSniff.php b/WordPress/Sniffs/Variables/VariableRestrictionsSniff.php index f28a07af45..9b85e725af 100644 --- a/WordPress/Sniffs/Variables/VariableRestrictionsSniff.php +++ b/WordPress/Sniffs/Variables/VariableRestrictionsSniff.php @@ -7,21 +7,27 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\Variables; + +use WordPress\AbstractVariableRestrictionsSniff; + /** * Restricts usage of some variables. * * @package WPCS\WordPressCodingStandards * * @since 0.3.0 + * @since 0.13.0 Class name changed: this class is now namespaced. + * * @deprecated 0.10.0 The functionality which used to be contained in this class has been moved to * the WordPress_AbstractVariableRestrictionsSniff class. * This class is left here to prevent backward-compatibility breaks for * custom sniffs extending the old class and references to this * sniff from custom phpcs.xml files. * This file is also still used to unit test the abstract class. - * @see WordPress_AbstractVariableRestrictionsSniff + * @see \WordPress\AbstractVariableRestrictionsSniff */ -class WordPress_Sniffs_Variables_VariableRestrictionsSniff extends WordPress_AbstractVariableRestrictionsSniff { +class VariableRestrictionsSniff extends AbstractVariableRestrictionsSniff { /** * Groups of variables to restrict. diff --git a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php index 7deda9d7bf..e96d41a557 100644 --- a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php +++ b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php @@ -7,14 +7,19 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\WP; + +use WordPress\AbstractFunctionRestrictionsSniff; + /** * Discourages the use of various functions and suggests (WordPress) alternatives. * * @package WPCS\WordPressCodingStandards * * @since 0.11.0 + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_WP_AlternativeFunctionsSniff extends WordPress_AbstractFunctionRestrictionsSniff { +class AlternativeFunctionsSniff extends AbstractFunctionRestrictionsSniff { /** * Groups of functions to restrict. diff --git a/WordPress/Sniffs/WP/CapitalPDangitSniff.php b/WordPress/Sniffs/WP/CapitalPDangitSniff.php index b80964d9ed..b2ead93d9f 100644 --- a/WordPress/Sniffs/WP/CapitalPDangitSniff.php +++ b/WordPress/Sniffs/WP/CapitalPDangitSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\WP; + +use WordPress\Sniff; + /** * Capital P Dangit! * @@ -15,8 +19,9 @@ * @package WPCS\WordPressCodingStandards * * @since 0.12.0 + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_WP_CapitalPDangitSniff extends WordPress_Sniff { +class CapitalPDangitSniff extends Sniff { /** * Regex to match a large number or spelling variations of WordPress in text strings. diff --git a/WordPress/Sniffs/WP/DeprecatedClassesSniff.php b/WordPress/Sniffs/WP/DeprecatedClassesSniff.php index 3145c82198..05d0428f11 100644 --- a/WordPress/Sniffs/WP/DeprecatedClassesSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedClassesSniff.php @@ -7,14 +7,19 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\WP; + +use WordPress\AbstractClassRestrictionsSniff; + /** * Restricts the use of deprecated WordPress classes and suggests alternatives. * * @package WPCS\WordPressCodingStandards * * @since 0.12.0 + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_WP_DeprecatedClassesSniff extends WordPress_AbstractClassRestrictionsSniff { +class DeprecatedClassesSniff extends AbstractClassRestrictionsSniff { /** * Minimum WordPress version. diff --git a/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php b/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php index 1604e17594..d2cc749104 100644 --- a/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php @@ -7,14 +7,19 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\WP; + +use WordPress\AbstractFunctionRestrictionsSniff; + /** * Restricts the use of various deprecated WordPress functions and suggests alternatives. * * @package WPCS\WordPressCodingStandards * * @since 0.11.0 + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_WP_DeprecatedFunctionsSniff extends WordPress_AbstractFunctionRestrictionsSniff { +class DeprecatedFunctionsSniff extends AbstractFunctionRestrictionsSniff { /** * Minimum WordPress version. diff --git a/WordPress/Sniffs/WP/DeprecatedParametersSniff.php b/WordPress/Sniffs/WP/DeprecatedParametersSniff.php index c04190127d..7f0c26e04b 100644 --- a/WordPress/Sniffs/WP/DeprecatedParametersSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedParametersSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\WP; + +use WordPress\AbstractFunctionParameterSniff; + /** * Check for usage of deprecated parameters in WP functions and suggest alternative based on the parameter passed. * @@ -19,8 +23,9 @@ * @package WPCS\WordPressCodingStandards * * @since 0.12.0 + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_WP_DeprecatedParametersSniff extends WordPress_AbstractFunctionParameterSniff { +class DeprecatedParametersSniff extends AbstractFunctionParameterSniff { /** * The group name for this group of functions. diff --git a/WordPress/Sniffs/WP/DiscouragedFunctionsSniff.php b/WordPress/Sniffs/WP/DiscouragedFunctionsSniff.php index a2045f2396..8e1deb763c 100644 --- a/WordPress/Sniffs/WP/DiscouragedFunctionsSniff.php +++ b/WordPress/Sniffs/WP/DiscouragedFunctionsSniff.php @@ -7,14 +7,19 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\WP; + +use WordPress\AbstractFunctionRestrictionsSniff; + /** * Discourages the use of various WordPress functions and suggests alternatives. * * @package WPCS\WordPressCodingStandards * * @since 0.11.0 + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_WP_DiscouragedFunctionsSniff extends WordPress_AbstractFunctionRestrictionsSniff { +class DiscouragedFunctionsSniff extends AbstractFunctionRestrictionsSniff { /** * Groups of functions to restrict. diff --git a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php index 8b2fe574e9..ea9af15b9f 100644 --- a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php +++ b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\WP; + +use WordPress\Sniff; + /** * Makes sure scripts and styles are enqueued and not explicitly echo'd. * @@ -16,8 +20,9 @@ * * @since 0.3.0 * @since 0.12.0 This class now extends WordPress_Sniff. + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_WP_EnqueuedResourcesSniff extends WordPress_Sniff { +class EnqueuedResourcesSniff extends Sniff { /** * Returns an array of tokens this test wants to listen for. diff --git a/WordPress/Sniffs/WP/I18nSniff.php b/WordPress/Sniffs/WP/I18nSniff.php index 7a1bf7f5ea..06536475d4 100644 --- a/WordPress/Sniffs/WP/I18nSniff.php +++ b/WordPress/Sniffs/WP/I18nSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\WP; + +use WordPress\Sniff; + /** * Makes sure WP internationalization functions are used properly. * @@ -20,8 +24,9 @@ * - Now has the ability to handle text-domain set via the command-line * 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. */ -class WordPress_Sniffs_WP_I18nSniff extends WordPress_Sniff { +class I18nSniff extends Sniff { /** * These Regexes copied from http://php.net/manual/en/function.sprintf.php#93552 diff --git a/WordPress/Sniffs/WP/PreparedSQLSniff.php b/WordPress/Sniffs/WP/PreparedSQLSniff.php index 85d3202ae1..e9fef1af06 100644 --- a/WordPress/Sniffs/WP/PreparedSQLSniff.php +++ b/WordPress/Sniffs/WP/PreparedSQLSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\WP; + +use WordPress\Sniff; + /** * Sniff for prepared SQL. * @@ -17,8 +21,9 @@ * @package WPCS\WordPressCodingStandards * * @since 0.8.0 + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_WP_PreparedSQLSniff extends WordPress_Sniff { +class PreparedSQLSniff extends Sniff { /** * The lists of $wpdb methods. diff --git a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php index 16bc7de9e3..f5c3466932 100755 --- a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\WhiteSpace; + +use WordPress\Sniff; + /** * Ensure cast statements don't contain whitespace, but *are* surrounded by whitespace, based upon Squiz code. * @@ -18,8 +22,9 @@ * @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.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_WhiteSpace_CastStructureSpacingSniff extends WordPress_Sniff { +class CastStructureSpacingSniff extends Sniff { /** * Returns an array of tokens this test wants to listen for. diff --git a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php index 736913567d..88ad2be200 100644 --- a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\WhiteSpace; + +use WordPress\Sniff; + /** * Enforces spacing around logical operators and assignments, based upon Squiz code. * @@ -16,13 +20,14 @@ * @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.13.0 Class name changed: this class is now namespaced. * * Last synced with base class 2017-01-15 at commit b024ad84656c37ef5733c6998ebc1e60957b2277. * Note: This class has diverged quite far from the original. All the same, checking occassionally * to see if there are upstream fixes made from which this sniff can benefit, is warranted. * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php */ -class WordPress_Sniffs_WhiteSpace_ControlStructureSpacingSniff extends WordPress_Sniff { +class ControlStructureSpacingSniff extends Sniff { /** * Check for blank lines on start/end of control structures. diff --git a/WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php b/WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php index 7ca26d2c2b..f8555e550b 100644 --- a/WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php +++ b/WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\WhiteSpace; + +use WordPress\Sniff; + /** * Enforces using spaces for mid-line alignment. * @@ -15,8 +19,9 @@ * @package WPCS\WordPressCodingStandards * * @since 0.12.0 + * @since 0.13.0 Class name changed: this class is now namespaced. */ -class WordPress_Sniffs_WhiteSpace_DisallowInlineTabsSniff extends WordPress_Sniff { +class DisallowInlineTabsSniff extends Sniff { /** * The --tab-width CLI value that is being used. diff --git a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php index 921dfcd462..7677bd3f08 100644 --- a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php @@ -28,6 +28,7 @@ * T_BOOLEAN_NOT and the logical operators (`&&` and the like) - via the * registration method and changing the value of the customizable * $ignoreNewlines property. + * @since 0.13.0 Class name changed: this class is now namespaced. * * Last synced with base class June 2017 at commit 41127aa4764536f38f504fb3f7b8831f05919c89. * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php diff --git a/WordPress/Sniffs/XSS/EscapeOutputSniff.php b/WordPress/Sniffs/XSS/EscapeOutputSniff.php index 70e2693393..7af4d77ff5 100644 --- a/WordPress/Sniffs/XSS/EscapeOutputSniff.php +++ b/WordPress/Sniffs/XSS/EscapeOutputSniff.php @@ -7,6 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ +namespace WordPress\Sniffs\XSS; + +use WordPress\Sniff; + /** * Verifies that all outputted strings are escaped. * @@ -20,8 +24,9 @@ * have been moved to the WordPress_Sniff parent class. * @since 0.12.0 This sniff will now also check for output escaping when using shorthand * echo tags ` Date: Sat, 22 Jul 2017 20:24:14 +0200 Subject: [PATCH 02/10] PHPCS 3.x compat: Namespace all sniffs which extend an upstream sniff --- .../Sniffs/NamingConventions/ValidFunctionNameSniff.php | 8 ++++---- .../Sniffs/NamingConventions/ValidVariableNameSniff.php | 8 ++++---- WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php index d4b5f3a9a4..e9960b4e1b 100644 --- a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -if ( ! class_exists( 'PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff', true ) ) { - throw new PHP_CodeSniffer_Exception( 'Class PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff not found' ); -} +namespace WordPress\Sniffs\NamingConventions; + +use PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff as PHPCS_PEAR_ValidFunctionNameSniff; /** * Enforces WordPress function name and method name format, based upon Squiz code. @@ -27,7 +27,7 @@ * {@internal While this class extends the PEAR parent, it does not actually use the checks * contained in the parent. It only uses the properties and the token registration from the parent.}} */ -class WordPress_Sniffs_NamingConventions_ValidFunctionNameSniff extends PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff { +class ValidFunctionNameSniff extends PHPCS_PEAR_ValidFunctionNameSniff { /** * Additional double underscore prefixed methods specific to certain PHP native extensions. diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index deac96a7c5..5b950885fd 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -if ( ! class_exists( 'PHP_CodeSniffer_Standards_AbstractVariableSniff', true ) ) { - throw new PHP_CodeSniffer_Exception( 'Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found' ); -} +namespace WordPress\Sniffs\NamingConventions; + +use PHP_CodeSniffer_Standards_AbstractVariableSniff as PHPCS_AbstractVariableSniff; use WordPress\Sniff; /** @@ -25,7 +25,7 @@ * Last synced with base class July 2014 at commit ed257ca0e56ad86cd2a4d6fa38ce0b95141c824f. * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php */ -class WordPress_Sniffs_NamingConventions_ValidVariableNameSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff { +class ValidVariableNameSniff extends PHPCS_AbstractVariableSniff { /** * PHP Reserved Vars. diff --git a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php index 7677bd3f08..9f5376354f 100644 --- a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -if ( ! class_exists( 'Squiz_Sniffs_WhiteSpace_OperatorSpacingSniff', true ) ) { - throw new PHP_CodeSniffer_Exception( 'Class Squiz_Sniffs_WhiteSpace_OperatorSpacingSniff not found' ); -} +namespace WordPress\Sniffs\WhiteSpace; + +use Squiz_Sniffs_WhiteSpace_OperatorSpacingSniff as PHPCS_Squiz_OperatorSpacingSniff; /** * Verify operator spacing, uses the Squiz sniff, but additionally also sniffs for the `!` (boolean not) operator. @@ -33,7 +33,7 @@ * Last synced with base class June 2017 at commit 41127aa4764536f38f504fb3f7b8831f05919c89. * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php */ -class WordPress_Sniffs_WhiteSpace_OperatorSpacingSniff extends Squiz_Sniffs_WhiteSpace_OperatorSpacingSniff { +class OperatorSpacingSniff extends PHPCS_Squiz_OperatorSpacingSniff { /** * Allow newlines instead of spaces. From 5c4759149ffbd774e4a425473a2a82f06bdf99d0 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 20 Jul 2017 05:13:44 +0200 Subject: [PATCH 03/10] PHPCS 3.x compat: Fix all references to upstream PHPCS classes * Add use statements for all PHPCS class references. * Where possible use the PHPCS 3.x class name as a use alias to make the future change of dropping 2.x support easier. --- .../AbstractFunctionRestrictionsSniff.php | 5 +- WordPress/Sniff.php | 50 ++++++++++--------- .../Sniffs/Arrays/ArrayDeclarationSniff.php | 8 +-- .../Arrays/ArrayDeclarationSpacingSniff.php | 3 +- .../Sniffs/Arrays/ArrayIndentationSniff.php | 3 +- .../Arrays/CommaAfterArrayItemSniff.php | 5 +- .../Classes/ClassInstantiationSniff.php | 7 +-- .../CodeAnalysis/EmptyStatementSniff.php | 3 +- WordPress/Sniffs/Files/FileNameSniff.php | 6 +-- .../FunctionCallSignatureNoParamsSniff.php | 7 +-- .../PrefixAllGlobalsSniff.php | 25 +++++----- .../ValidFunctionNameSniff.php | 19 +++---- .../ValidVariableNameSniff.php | 29 +++++------ .../Sniffs/PHP/DiscouragedFunctionsSniff.php | 8 +-- WordPress/Sniffs/PHP/YodaConditionsSniff.php | 15 +++--- WordPress/Sniffs/VIP/AdminBarRemovalSniff.php | 5 +- WordPress/Sniffs/VIP/CronIntervalSniff.php | 3 +- .../Sniffs/VIP/DirectDatabaseQuerySniff.php | 3 +- .../Sniffs/Variables/GlobalVariablesSniff.php | 5 +- WordPress/Sniffs/WP/CapitalPDangitSniff.php | 5 +- .../Sniffs/WP/EnqueuedResourcesSniff.php | 3 +- WordPress/Sniffs/WP/I18nSniff.php | 7 +-- .../WhiteSpace/CastStructureSpacingSniff.php | 3 +- .../ControlStructureSpacingSniff.php | 15 +++--- .../WhiteSpace/OperatorSpacingSniff.php | 3 +- WordPress/Sniffs/XSS/EscapeOutputSniff.php | 9 ++-- 26 files changed, 142 insertions(+), 112 deletions(-) diff --git a/WordPress/AbstractFunctionRestrictionsSniff.php b/WordPress/AbstractFunctionRestrictionsSniff.php index a607d21edf..cba5f6bbb7 100644 --- a/WordPress/AbstractFunctionRestrictionsSniff.php +++ b/WordPress/AbstractFunctionRestrictionsSniff.php @@ -10,6 +10,7 @@ namespace WordPress; use WordPress\Sniff; +use PHP_CodeSniffer_Tokens as Tokens; /** * Restricts usage of some functions. @@ -210,7 +211,7 @@ 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 ) ] ) ) { - $prev = $this->phpcsFile->findPrevious( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true ); + $prev = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true ); if ( false !== $prev ) { // Skip sniffing if calling a same-named method, or on function definitions. @@ -226,7 +227,7 @@ public function is_targetted_token( $stackPtr ) { // Skip namespaced functions, ie: \foo\bar() not \bar(). if ( T_NS_SEPARATOR === $this->tokens[ $prev ]['code'] ) { - $pprev = $this->phpcsFile->findPrevious( PHP_CodeSniffer_Tokens::$emptyTokens, ( $prev - 1 ), null, true ); + $pprev = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $prev - 1 ), null, true ); if ( false !== $pprev && T_STRING === $this->tokens[ $pprev ]['code'] ) { return false; } diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index ec47c6dd16..5cb011120f 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -9,6 +9,10 @@ namespace WordPress; +use PHP_CodeSniffer_Sniff as PHPCS_Sniff; +use PHP_CodeSniffer_File as File; +use PHP_CodeSniffer_Tokens as Tokens; + /** * Represents a PHP_CodeSniffer sniff for sniffing WordPress coding standards. * @@ -28,7 +32,7 @@ * In the rare few cases where the array values *do* have meaning, this * is documented in the property documentation.}} */ -abstract class Sniff implements PHP_CodeSniffer_Sniff { +abstract class Sniff implements PHPCS_Sniff { /** * List of the functions which verify nonces. @@ -798,7 +802,7 @@ abstract class Sniff implements PHP_CodeSniffer_Sniff { * * @since 0.4.0 * - * @var PHP_CodeSniffer_File + * @var \PHP_CodeSniffer\Files\File */ protected $phpcsFile; @@ -816,14 +820,14 @@ abstract class Sniff implements PHP_CodeSniffer_Sniff { * * @since 0.11.0 * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return int|void Integer stack pointer to skip forward or void to continue * normal file processing. */ - public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { + public function process( File $phpcsFile, $stackPtr ) { $this->init( $phpcsFile ); return $this->process_token( $stackPtr ); } @@ -848,9 +852,9 @@ abstract public function process_token( $stackPtr ); * * @since 0.4.0 * - * @param PHP_CodeSniffer_File $phpcsFile The file currently being processed. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file currently being processed. */ - protected function init( PHP_CodeSniffer_File $phpcsFile ) { + protected function init( File $phpcsFile ) { $this->phpcsFile = $phpcsFile; $this->tokens = $phpcsFile->getTokens(); } @@ -1200,7 +1204,7 @@ protected function is_assignment( $stackPtr ) { } $next_non_empty = $this->phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens + Tokens::$emptyTokens , ( $stackPtr + 1 ) , null , true @@ -1214,7 +1218,7 @@ protected function is_assignment( $stackPtr ) { } // If the next token is an assignment, that's all we need to know. - if ( isset( PHP_CodeSniffer_Tokens::$assignmentTokens[ $this->tokens[ $next_non_empty ]['code'] ] ) ) { + if ( isset( Tokens::$assignmentTokens[ $this->tokens[ $next_non_empty ]['code'] ] ) ) { return true; } @@ -1394,7 +1398,7 @@ protected function is_safe_casted( $stackPtr ) { // Get the last non-empty token. $prev = $this->phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$emptyTokens + Tokens::$emptyTokens , ( $stackPtr - 1 ) , null , true @@ -1481,7 +1485,7 @@ protected function is_sanitized( $stackPtr, $require_unslash = false ) { * to resolve the function name, do so. */ $first_non_empty = $this->phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, $callback['start'], ( $callback['end'] + 1 ), true @@ -1538,7 +1542,7 @@ protected function get_array_access_key( $stackPtr ) { // Find the next non-empty token. $open_bracket = $this->phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true @@ -1704,19 +1708,19 @@ protected function is_comparison( $stackPtr ) { // Find the previous non-empty token. We check before the var first because // yoda conditions are usually expected. $previous_token = $this->phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true ); - if ( isset( PHP_CodeSniffer_Tokens::$comparisonTokens[ $this->tokens[ $previous_token ]['code'] ] ) ) { + if ( isset( Tokens::$comparisonTokens[ $this->tokens[ $previous_token ]['code'] ] ) ) { return true; } // Maybe the comparison operator is after this. $next_token = $this->phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true @@ -1726,14 +1730,14 @@ protected function is_comparison( $stackPtr ) { while ( T_OPEN_SQUARE_BRACKET === $this->tokens[ $next_token ]['code'] ) { $next_token = $this->phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ( $this->tokens[ $next_token ]['bracket_closer'] + 1 ), null, true ); } - if ( isset( PHP_CodeSniffer_Tokens::$comparisonTokens[ $this->tokens[ $next_token ]['code'] ] ) ) { + if ( isset( Tokens::$comparisonTokens[ $this->tokens[ $next_token ]['code'] ] ) ) { return true; } @@ -1829,7 +1833,7 @@ public function does_function_call_have_parameters( $stackPtr ) { return false; } - $next_non_empty = $this->phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); + $next_non_empty = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); // Deal with short array syntax. if ( 'T_OPEN_SHORT_ARRAY' === $this->tokens[ $stackPtr ]['type'] ) { @@ -1856,7 +1860,7 @@ public function does_function_call_have_parameters( $stackPtr ) { } $close_parenthesis = $this->tokens[ $next_non_empty ]['parenthesis_closer']; - $next_next_non_empty = $this->phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $next_non_empty + 1 ), ( $close_parenthesis + 1 ), true ); + $next_next_non_empty = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $next_non_empty + 1 ), ( $close_parenthesis + 1 ), true ); if ( $next_next_non_empty === $close_parenthesis ) { // No parameters. @@ -1932,7 +1936,7 @@ public function get_function_call_parameters( $stackPtr ) { $nestedParenthesisCount = 0; } else { - $opener = $this->phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); + $opener = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); $closer = $this->tokens[ $opener ]['parenthesis_closer']; $nestedParenthesisCount = 1; @@ -1982,7 +1986,7 @@ public function get_function_call_parameters( $stackPtr ) { * Prevents code like the following from setting a third parameter: * functionCall( $param1, $param2, ); */ - $has_next_param = $this->phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $next_comma + 1 ), $closer, true, null, true ); + $has_next_param = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $next_comma + 1 ), $closer, true, null, true ); if ( false === $has_next_param ) { break; } @@ -2154,7 +2158,7 @@ public function get_declared_namespace_name( $stackPtr ) { return false; } - $nextToken = $this->phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); + $nextToken = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); if ( T_OPEN_CURLY_BRACKET === $this->tokens[ $nextToken ]['code'] ) { // Declaration for global namespace when using multiple namespaces in a file. // I.e.: `namespace {}`. diff --git a/WordPress/Sniffs/Arrays/ArrayDeclarationSniff.php b/WordPress/Sniffs/Arrays/ArrayDeclarationSniff.php index 9f3e593d74..2f9899f1c7 100644 --- a/WordPress/Sniffs/Arrays/ArrayDeclarationSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayDeclarationSniff.php @@ -9,6 +9,8 @@ namespace WordPress\Sniffs\Arrays; +use PHP_CodeSniffer_File as File; + /** * Enforces WordPress array format, based upon Squiz code. * @@ -49,11 +51,11 @@ public function register() { * * @deprecated 0.13.0 * - * @param PHP_CodeSniffer_File $phpcsFile A PHP_CodeSniffer file. - * @param int $stackPtr The position of the token. + * @param \PHP_CodeSniffer\Files\File $phpcsFile A PHP_CodeSniffer file. + * @param int $stackPtr The position of the token. * * @return void */ - public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) {} + public function process( File $phpcsFile, $stackPtr ) {} } // End class. diff --git a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php index 36c075e18d..95b1c167ba 100644 --- a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\Arrays; use WordPress\Sniff; +use PHP_CodeSniffer_Tokens as Tokens; /** * Enforces WordPress array spacing format. @@ -219,7 +220,7 @@ protected function process_single_line_array( $stackPtr, $opener, $closer ) { * interpreted as alignment whitespace. */ $first_non_empty = $this->phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, $item['start'], ( $item['end'] + 1 ), true diff --git a/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php b/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php index 9a67948759..b9de09f59b 100644 --- a/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\Arrays; use WordPress\Sniff; +use PHP_CodeSniffer_Tokens as Tokens; /** * Enforces WordPress array indentation for multi-line arrays. @@ -69,7 +70,7 @@ public function register() { * * Existing heredoc, nowdoc and inline HTML indentation should be respected at all times. */ - $this->ignore_tokens = PHP_CodeSniffer_Tokens::$heredocTokens; + $this->ignore_tokens = Tokens::$heredocTokens; unset( $this->ignore_tokens[ T_START_HEREDOC ], $this->ignore_tokens[ T_START_NOWDOC ] ); $this->ignore_tokens[ T_INLINE_HTML ] = T_INLINE_HTML; diff --git a/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php b/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php index f2ef82522d..16614102f3 100644 --- a/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php +++ b/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\Arrays; use WordPress\Sniff; +use PHP_CodeSniffer_Tokens as Tokens; /** * Enforces a comma after each array item and the spacing around it. @@ -114,7 +115,7 @@ public function process_token( $stackPtr ) { } $last_content = $this->phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, $item['end'], $item['start'], true @@ -155,7 +156,7 @@ public function process_token( $stackPtr ) { if ( $last_content !== $item['end'] // Ignore whitespace at the end of a multi-line item if it is the end of a heredoc/nowdoc. && ( true === $single_line - || ! isset( PHP_CodeSniffer_Tokens::$heredocTokens[ $this->tokens[ $last_content ]['code'] ] ) ) + || ! isset( Tokens::$heredocTokens[ $this->tokens[ $last_content ]['code'] ] ) ) ) { $newlines = 0; $spaces = 0; diff --git a/WordPress/Sniffs/Classes/ClassInstantiationSniff.php b/WordPress/Sniffs/Classes/ClassInstantiationSniff.php index 2465a66c83..85a7d2ca7c 100644 --- a/WordPress/Sniffs/Classes/ClassInstantiationSniff.php +++ b/WordPress/Sniffs/Classes/ClassInstantiationSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\Classes; use WordPress\Sniff; +use PHP_CodeSniffer_Tokens as Tokens; /** * Verifies object instantiation statements. @@ -58,7 +59,7 @@ public function register() { * * Currently does not account for classnames passed as a variable variable. */ - $this->classname_tokens = PHP_CodeSniffer_Tokens::$emptyTokens; + $this->classname_tokens = Tokens::$emptyTokens; $this->classname_tokens[ T_NS_SEPARATOR ] = T_NS_SEPARATOR; $this->classname_tokens[ T_STRING ] = T_STRING; $this->classname_tokens[ T_SELF ] = T_SELF; @@ -100,7 +101,7 @@ public function process_token( $stackPtr ) { */ if ( 'PHP' === $this->phpcsFile->tokenizerType ) { $prev_non_empty = $this->phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ($stackPtr - 1), null, true @@ -139,7 +140,7 @@ public function process_token( $stackPtr ) { // Walk back to the last part of the class name. $has_comment = false; for ( $classname_ptr = ( $next_non_empty_after_class_name - 1 ); $classname_ptr >= $stackPtr; $classname_ptr-- ) { - if ( ! isset( PHP_CodeSniffer_Tokens::$emptyTokens[ $this->tokens[ $classname_ptr ]['code'] ] ) ) { + if ( ! isset( Tokens::$emptyTokens[ $this->tokens[ $classname_ptr ]['code'] ] ) ) { // Prevent a false positive on variable variables, disregard them for now. if ( $stackPtr === $classname_ptr ) { return; diff --git a/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php b/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php index 3778fd0372..c79f3f08ad 100644 --- a/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php +++ b/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\CodeAnalysis; use WordPress\Sniff; +use PHP_CodeSniffer_Tokens as Tokens; /** * Checks against empty statements. @@ -57,7 +58,7 @@ public function process_token( $stackPtr ) { */ case 'T_SEMICOLON': $prevNonEmpty = $this->phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true diff --git a/WordPress/Sniffs/Files/FileNameSniff.php b/WordPress/Sniffs/Files/FileNameSniff.php index 624edc49d9..a0328c1ac5 100644 --- a/WordPress/Sniffs/Files/FileNameSniff.php +++ b/WordPress/Sniffs/Files/FileNameSniff.php @@ -118,7 +118,7 @@ class FileNameSniff extends Sniff { * @return array */ public function register() { - if ( defined( 'PHP_CODESNIFFER_IN_TESTS' ) ) { + if ( defined( '\PHP_CODESNIFFER_IN_TESTS' ) ) { $this->class_exceptions = array_merge( $this->class_exceptions, $this->unittest_class_exceptions ); } @@ -195,8 +195,8 @@ public function process_token( $stackPtr ) { if ( ( 'Template' === trim( $this->tokens[ $subpackage ]['content'] ) && $this->tokens[ $subpackage_tag ]['line'] === $this->tokens[ $subpackage ]['line'] ) - && ( ( ! defined( 'PHP_CODESNIFFER_IN_TESTS' ) && '-template.php' !== $fileName_end ) - || ( defined( 'PHP_CODESNIFFER_IN_TESTS' ) && '-template.inc' !== $fileName_end ) ) + && ( ( ! defined( '\PHP_CODESNIFFER_IN_TESTS' ) && '-template.php' !== $fileName_end ) + || ( defined( '\PHP_CODESNIFFER_IN_TESTS' ) && '-template.inc' !== $fileName_end ) ) && false === $has_class ) { $this->phpcsFile->addError( diff --git a/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php b/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php index 0f94a1f144..cb321a0cd4 100644 --- a/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php +++ b/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\Functions; use WordPress\Sniff; +use PHP_CodeSniffer_Tokens as Tokens; /** * Enforces no whitespace between the parenthesis of a function call without parameters. @@ -29,7 +30,7 @@ class FunctionCallSignatureNoParamsSniff extends Sniff { * @return array */ public function register() { - return PHP_CodeSniffer_Tokens::$functionNameTokens; + return Tokens::$functionNameTokens; } /** @@ -42,7 +43,7 @@ public function register() { public function process_token( $stackPtr ) { // Find the next non-empty token. - $openParenthesis = $this->phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); + $openParenthesis = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); if ( T_OPEN_PARENTHESIS !== $this->tokens[ $openParenthesis ]['code'] ) { // Not a function call. @@ -55,7 +56,7 @@ public function process_token( $stackPtr ) { } // Find the previous non-empty token. - $search = PHP_CodeSniffer_Tokens::$emptyTokens; + $search = Tokens::$emptyTokens; $search[] = T_BITWISE_AND; $previous = $this->phpcsFile->findPrevious( $search, ( $stackPtr - 1 ), null, true ); if ( T_FUNCTION === $this->tokens[ $previous ]['code'] ) { diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index fecbac8773..ad0ec98481 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\NamingConventions; use WordPress\AbstractFunctionParameterSniff; +use PHP_CodeSniffer_Tokens as Tokens; /** * Verify that everything defined in the global namespace is prefixed with a theme/plugin specific prefix. @@ -272,7 +273,7 @@ public function process_token( $stackPtr ) { return; } - $constant_name_ptr = $this->phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); + $constant_name_ptr = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); if ( false === $constant_name_ptr ) { // Live coding. return; @@ -329,7 +330,7 @@ protected function process_variable_variable( $stackPtr ) { // Is this a variable variable ? // Not concerned with nested ones as those will be recognized on their own token. - $next_non_empty = $this->phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); + $next_non_empty = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); if ( false === $next_non_empty || ! isset( $indicators[ $this->tokens[ $next_non_empty ]['code'] ] ) ) { return; } @@ -341,14 +342,14 @@ protected function process_variable_variable( $stackPtr ) { $next_non_empty = $this->tokens[ $next_non_empty ]['bracket_closer']; } - $maybe_assignment = $this->phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $next_non_empty + 1 ), null, true, null, true ); + $maybe_assignment = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $next_non_empty + 1 ), null, true, null, true ); while ( false !== $maybe_assignment && T_OPEN_SQUARE_BRACKET === $this->tokens[ $maybe_assignment ]['code'] && isset( $this->tokens[ $maybe_assignment ]['bracket_closer'] ) ) { $maybe_assignment = $this->phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ( $this->tokens[ $maybe_assignment ]['bracket_closer'] + 1 ), null, true, @@ -361,7 +362,7 @@ protected function process_variable_variable( $stackPtr ) { return; } - if ( ! isset( PHP_CodeSniffer_Tokens::$assignmentTokens[ $this->tokens[ $maybe_assignment ]['code'] ] ) ) { + if ( ! isset( Tokens::$assignmentTokens[ $this->tokens[ $maybe_assignment ]['code'] ] ) ) { // Not an assignment. return; } @@ -435,13 +436,13 @@ protected function process_variable_assignment( $stackPtr ) { } if ( 'GLOBALS' === $variable_name ) { - $array_open = $this->phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); + $array_open = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); if ( false === $array_open || T_OPEN_SQUARE_BRACKET !== $this->tokens[ $array_open ]['code'] ) { // Live coding or something very silly. return; } - $array_key = $this->phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $array_open + 1 ), null, true, null, true ); + $array_key = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $array_open + 1 ), null, true, null, true ); if ( false === $array_key ) { // No key found, nothing to do. return; @@ -451,7 +452,7 @@ protected function process_variable_assignment( $stackPtr ) { $variable_name = $this->strip_quotes( $this->tokens[ $array_key ]['content'] ); // Check whether a prefix is needed. - if ( isset( PHP_CodeSniffer_Tokens::$stringTokens[ $this->tokens[ $array_key ]['code'] ] ) + if ( isset( Tokens::$stringTokens[ $this->tokens[ $array_key ]['code'] ] ) && $this->variable_prefixed_or_whitelisted( $variable_name ) === true ) { return; @@ -470,7 +471,7 @@ protected function process_variable_assignment( $stackPtr ) { // If the first part was dynamic, throw a warning. $is_error = false; } - } elseif ( ! isset( PHP_CodeSniffer_Tokens::$stringTokens[ $this->tokens[ $array_key ]['code'] ] ) ) { + } elseif ( ! isset( Tokens::$stringTokens[ $this->tokens[ $array_key ]['code'] ] ) ) { // Dynamic array key, throw a warning. $is_error = false; } @@ -580,7 +581,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p } else { // This may be a dynamic hook/constant name. $first_non_empty = $this->phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, $parameters[1]['start'], ( $parameters[1]['end'] + 1 ), true @@ -593,7 +594,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p $first_non_empty_content = $this->strip_quotes( $this->tokens[ $first_non_empty ]['content'] ); // Try again with just the first token if it's a text string. - if ( isset( PHP_CodeSniffer_Tokens::$stringTokens[ $this->tokens[ $first_non_empty ]['code'] ] ) + if ( isset( Tokens::$stringTokens[ $this->tokens[ $first_non_empty ]['code'] ] ) && $this->is_prefixed( $first_non_empty_content ) === true ) { return; @@ -612,7 +613,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p // Start of hook/constant name is dynamic, throw a warning. $is_error = false; } - } elseif ( ! isset( PHP_CodeSniffer_Tokens::$stringTokens[ $this->tokens[ $first_non_empty ]['code'] ] ) ) { + } elseif ( ! isset( Tokens::$stringTokens[ $this->tokens[ $first_non_empty ]['code'] ] ) ) { // Dynamic hook/constant name, throw a warning. $is_error = false; } diff --git a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php index e9960b4e1b..4f27b7d993 100644 --- a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\NamingConventions; use PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff as PHPCS_PEAR_ValidFunctionNameSniff; +use PHP_CodeSniffer_File as File; /** * Enforces WordPress function name and method name format, based upon Squiz code. @@ -55,13 +56,13 @@ class ValidFunctionNameSniff extends PHPCS_PEAR_ValidFunctionNameSniff { /** * Processes the tokens outside the scope. * - * @param PHP_CodeSniffer_File $phpcsFile The file being processed. - * @param int $stackPtr The position where this token was - * found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being processed. + * @param int $stackPtr The position where this token was + * found. * * @return void */ - protected function processTokenOutsideScope( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { + protected function processTokenOutsideScope( File $phpcsFile, $stackPtr ) { $functionName = $phpcsFile->getDeclarationName( $stackPtr ); if ( ! isset( $functionName ) ) { @@ -101,14 +102,14 @@ protected function processTokenOutsideScope( PHP_CodeSniffer_File $phpcsFile, $s /** * Processes the tokens within the scope. * - * @param PHP_CodeSniffer_File $phpcsFile The file being processed. - * @param int $stackPtr The position where this token was - * found. - * @param int $currScope The position of the current scope. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being processed. + * @param int $stackPtr The position where this token was + * found. + * @param int $currScope The position of the current scope. * * @return void */ - protected function processTokenWithinScope( PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope ) { + protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currScope ) { $methodName = $phpcsFile->getDeclarationName( $stackPtr ); if ( ! isset( $methodName ) ) { diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index 5b950885fd..3a10912b24 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\NamingConventions; use PHP_CodeSniffer_Standards_AbstractVariableSniff as PHPCS_AbstractVariableSniff; +use PHP_CodeSniffer_File as File; use WordPress\Sniff; /** @@ -122,13 +123,13 @@ class ValidVariableNameSniff extends PHPCS_AbstractVariableSniff { /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcs_file The file being scanned. - * @param int $stack_ptr The position of the current token in the - * stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcs_file The file being scanned. + * @param int $stack_ptr The position of the current token in the + * stack passed in $tokens. * * @return void */ - protected function processVariable( PHP_CodeSniffer_File $phpcs_file, $stack_ptr ) { + protected function processVariable( File $phpcs_file, $stack_ptr ) { $tokens = $phpcs_file->getTokens(); $var_name = ltrim( $tokens[ $stack_ptr ]['content'], '$' ); @@ -208,13 +209,13 @@ protected function processVariable( PHP_CodeSniffer_File $phpcs_file, $stack_ptr /** * Processes class member variables. * - * @param PHP_CodeSniffer_File $phpcs_file The file being scanned. - * @param int $stack_ptr The position of the current token in the - * stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcs_file The file being scanned. + * @param int $stack_ptr The position of the current token in the + * stack passed in $tokens. * * @return void */ - protected function processMemberVar( PHP_CodeSniffer_File $phpcs_file, $stack_ptr ) { + protected function processMemberVar( File $phpcs_file, $stack_ptr ) { $tokens = $phpcs_file->getTokens(); @@ -242,13 +243,13 @@ protected function processMemberVar( PHP_CodeSniffer_File $phpcs_file, $stack_pt /** * Processes the variable found within a double quoted string. * - * @param PHP_CodeSniffer_File $phpcs_file The file being scanned. - * @param int $stack_ptr The position of the double quoted - * string. + * @param \PHP_CodeSniffer\Files\File $phpcs_file The file being scanned. + * @param int $stack_ptr The position of the double quoted + * string. * * @return void */ - protected function processVariableInString( PHP_CodeSniffer_File $phpcs_file, $stack_ptr ) { + protected function processVariableInString( File $phpcs_file, $stack_ptr ) { $tokens = $phpcs_file->getTokens(); @@ -294,11 +295,11 @@ public static function isSnakeCase( $var_name ) { * * @since 0.10.0 * - * @param PHP_CodeSniffer_File $phpcs_file The file being scanned. + * @param \PHP_CodeSniffer\Files\File $phpcs_file The file being scanned. * * @return void */ - protected function mergeWhiteList( $phpcs_file ) { + protected function mergeWhiteList( File $phpcs_file ) { if ( $this->customPropertiesWhitelist !== $this->addedCustomProperties['properties'] || $this->customVariablesWhitelist !== $this->addedCustomProperties['variables'] ) { diff --git a/WordPress/Sniffs/PHP/DiscouragedFunctionsSniff.php b/WordPress/Sniffs/PHP/DiscouragedFunctionsSniff.php index cef9e83136..763ab86b24 100644 --- a/WordPress/Sniffs/PHP/DiscouragedFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/DiscouragedFunctionsSniff.php @@ -9,6 +9,8 @@ namespace WordPress\Sniffs\PHP; +use PHP_CodeSniffer_File as File; + /** * Discourages the use of various native PHP functions and suggests alternatives. * @@ -51,11 +53,11 @@ public function register() { * * @deprecated 0.11.0 * - * @param PHP_CodeSniffer_File $phpcsFile A PHP_CodeSniffer file. - * @param int $stackPtr The position of the token. + * @param \PHP_CodeSniffer\Files\File $phpcsFile A PHP_CodeSniffer file. + * @param int $stackPtr The position of the token. * * @return void */ - public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) {} + public function process( File $phpcsFile, $stackPtr ) {} } diff --git a/WordPress/Sniffs/PHP/YodaConditionsSniff.php b/WordPress/Sniffs/PHP/YodaConditionsSniff.php index dda70d79ce..6da38d9ac8 100644 --- a/WordPress/Sniffs/PHP/YodaConditionsSniff.php +++ b/WordPress/Sniffs/PHP/YodaConditionsSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\PHP; use WordPress\Sniff; +use PHP_CodeSniffer_Tokens as Tokens; /** * Enforces Yoda conditional statements. @@ -40,8 +41,8 @@ class YodaConditionsSniff extends Sniff { */ public function register() { - $starters = PHP_CodeSniffer_Tokens::$booleanOperators; - $starters += PHP_CodeSniffer_Tokens::$assignmentTokens; + $starters = Tokens::$booleanOperators; + $starters += Tokens::$assignmentTokens; $starters[ T_CASE ] = T_CASE; $starters[ T_RETURN ] = T_RETURN; $starters[ T_SEMICOLON ] = T_SEMICOLON; @@ -75,7 +76,7 @@ public function process_token( $stackPtr ) { for ( $i = $stackPtr; $i > $start; $i-- ) { // Ignore whitespace. - if ( isset( PHP_CodeSniffer_Tokens::$emptyTokens[ $this->tokens[ $i ]['code'] ] ) ) { + if ( isset( Tokens::$emptyTokens[ $this->tokens[ $i ]['code'] ] ) ) { continue; } @@ -98,15 +99,15 @@ public function process_token( $stackPtr ) { } // Check if this is a var to var comparison, e.g.: if ( $var1 == $var2 ). - $next_non_empty = $this->phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); + $next_non_empty = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); - if ( isset( PHP_CodeSniffer_Tokens::$castTokens[ $this->tokens[ $next_non_empty ]['code'] ] ) ) { - $next_non_empty = $this->phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $next_non_empty + 1 ), null, true ); + if ( isset( Tokens::$castTokens[ $this->tokens[ $next_non_empty ]['code'] ] ) ) { + $next_non_empty = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $next_non_empty + 1 ), null, true ); } 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( PHP_CodeSniffer_Tokens::$emptyTokens, array( T_DOUBLE_COLON ) ) + array_merge( Tokens::$emptyTokens, array( T_DOUBLE_COLON ) ) , ( $next_non_empty + 1 ) , null , true diff --git a/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php b/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php index a9343d6213..0dbdb5086a 100644 --- a/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php +++ b/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\VIP; use WordPress\AbstractFunctionParameterSniff; +use PHP_CodeSniffer_Tokens as Tokens; /** * Discourages removal of the admin bar. @@ -140,7 +141,7 @@ class AdminBarRemovalSniff extends AbstractFunctionParameterSniff { */ public function register() { // Set up all string targets. - $this->string_tokens = PHP_CodeSniffer_Tokens::$textStringTokens; + $this->string_tokens = Tokens::$textStringTokens; $targets = $this->string_tokens; @@ -361,7 +362,7 @@ protected function process_css_style( $stackPtr ) { $opener = $this->phpcsFile->findPrevious( T_OPEN_CURLY_BRACKET, $stackPtr ); if ( false !== $opener ) { for ( $i = ( $opener - 1 ); $i >= 0; $i-- ) { - if ( isset( PHP_CodeSniffer_Tokens::$commentTokens[ $this->tokens[ $i ]['code'] ] ) + if ( isset( Tokens::$commentTokens[ $this->tokens[ $i ]['code'] ] ) || T_CLOSE_CURLY_BRACKET === $this->tokens[ $i ]['code'] ) { break; diff --git a/WordPress/Sniffs/VIP/CronIntervalSniff.php b/WordPress/Sniffs/VIP/CronIntervalSniff.php index 1c30f47821..aa6309fa75 100644 --- a/WordPress/Sniffs/VIP/CronIntervalSniff.php +++ b/WordPress/Sniffs/VIP/CronIntervalSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\VIP; use WordPress\Sniff; +use PHP_CodeSniffer_Tokens as Tokens; /** * Flag cron schedules less than 15 minutes. @@ -78,7 +79,7 @@ public function process_token( $stackPtr ) { } // Detect callback function name. - $callbackArrayPtr = $this->phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, $callback['start'], ( $callback['end'] + 1 ), true ); + $callbackArrayPtr = $this->phpcsFile->findNext( Tokens::$emptyTokens, $callback['start'], ( $callback['end'] + 1 ), true ); // If callback is array, get second element. if ( false !== $callbackArrayPtr diff --git a/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php b/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php index a7aa844467..c5d1e7c36c 100644 --- a/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php +++ b/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\VIP; use WordPress\Sniff; +use PHP_CodeSniffer_Tokens as Tokens; /** * Flag Database direct queries. @@ -152,7 +153,7 @@ public function process_token( $stackPtr ) { // Check for Database Schema Changes. $_pos = $stackPtr; - while ( $_pos = $this->phpcsFile->findNext( PHP_CodeSniffer_Tokens::$textStringTokens, ( $_pos + 1 ), $endOfStatement, false, null, true ) ) { + while ( $_pos = $this->phpcsFile->findNext( Tokens::$textStringTokens, ( $_pos + 1 ), $endOfStatement, false, null, true ) ) { if ( preg_match( '#\b(?:ALTER|CREATE|DROP)\b#i', $this->tokens[ $_pos ]['content'] ) > 0 ) { $this->phpcsFile->addError( 'Attempting a database schema change is highly discouraged.', $_pos, 'SchemaChange' ); } diff --git a/WordPress/Sniffs/Variables/GlobalVariablesSniff.php b/WordPress/Sniffs/Variables/GlobalVariablesSniff.php index 68386b7c4f..9ec1db806e 100644 --- a/WordPress/Sniffs/Variables/GlobalVariablesSniff.php +++ b/WordPress/Sniffs/Variables/GlobalVariablesSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\Variables; use WordPress\Sniff; +use PHP_CodeSniffer_Tokens as Tokens; /** * Warns about overwriting WordPress native global variables. @@ -48,7 +49,7 @@ public function process_token( $stackPtr ) { $token = $this->tokens[ $stackPtr ]; if ( T_VARIABLE === $token['code'] && '$GLOBALS' === $token['content'] ) { - $bracketPtr = $this->phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); + $bracketPtr = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); if ( false === $bracketPtr || T_OPEN_SQUARE_BRACKET !== $this->tokens[ $bracketPtr ]['code'] || ! isset( $this->tokens[ $bracketPtr ]['bracket_closer'] ) ) { return; @@ -145,7 +146,7 @@ public function process_token( $stackPtr ) { && in_array( $this->tokens[ $ptr ]['content'], $search, true ) ) { // Don't throw false positives for static class properties. - $previous = $this->phpcsFile->findPrevious( PHP_CodeSniffer_Tokens::$emptyTokens, ( $ptr - 1 ), null, true, null, true ); + $previous = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $ptr - 1 ), null, true, null, true ); if ( false !== $previous && T_DOUBLE_COLON === $this->tokens[ $previous ]['code'] ) { continue; } diff --git a/WordPress/Sniffs/WP/CapitalPDangitSniff.php b/WordPress/Sniffs/WP/CapitalPDangitSniff.php index b2ead93d9f..ca42817f48 100644 --- a/WordPress/Sniffs/WP/CapitalPDangitSniff.php +++ b/WordPress/Sniffs/WP/CapitalPDangitSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\WP; use WordPress\Sniff; +use PHP_CodeSniffer_Tokens as Tokens; /** * Capital P Dangit! @@ -191,9 +192,9 @@ public function process_token( $stackPtr ) { // Ignore any text strings which are array keys `$var['key']` as this is a false positive in 80% of all cases. if ( T_CONSTANT_ENCAPSED_STRING === $this->tokens[ $stackPtr ]['code'] ) { - $prevToken = $this->phpcsFile->findPrevious( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true, null, true ); + $prevToken = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true, null, true ); if ( false !== $prevToken && T_OPEN_SQUARE_BRACKET === $this->tokens[ $prevToken ]['code'] ) { - $nextToken = $this->phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); + $nextToken = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); if ( false !== $nextToken && T_CLOSE_SQUARE_BRACKET === $this->tokens[ $nextToken ]['code'] ) { return; } diff --git a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php index ea9af15b9f..965a28abe7 100644 --- a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php +++ b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\WP; use WordPress\Sniff; +use PHP_CodeSniffer_Tokens as Tokens; /** * Makes sure scripts and styles are enqueued and not explicitly echo'd. @@ -30,7 +31,7 @@ class EnqueuedResourcesSniff extends Sniff { * @return array */ public function register() { - return PHP_CodeSniffer_Tokens::$textStringTokens; + return Tokens::$textStringTokens; } /** diff --git a/WordPress/Sniffs/WP/I18nSniff.php b/WordPress/Sniffs/WP/I18nSniff.php index 06536475d4..64e2102752 100644 --- a/WordPress/Sniffs/WP/I18nSniff.php +++ b/WordPress/Sniffs/WP/I18nSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\WP; use WordPress\Sniff; +use PHP_CodeSniffer_Tokens as Tokens; /** * Makes sure WP internationalization functions are used properly. @@ -178,7 +179,7 @@ public function process_token( $stack_ptr ) { for ( $i = ( $func_open_paren_token + 1 ); $i < $this->tokens[ $func_open_paren_token ]['parenthesis_closer']; $i++ ) { $this_token = $this->tokens[ $i ]; $this_token['token_index'] = $i; - if ( isset( PHP_CodeSniffer_Tokens::$emptyTokens[ $this_token['code'] ] ) ) { + if ( isset( Tokens::$emptyTokens[ $this_token['code'] ] ) ) { continue; } if ( T_COMMA === $this_token['code'] ) { @@ -188,7 +189,7 @@ public function process_token( $stack_ptr ) { } // Merge consecutive single or double quoted strings (when they span multiple lines). - if ( isset( PHP_CodeSniffer_Tokens::$textStringTokens[ $this_token['code'] ] ) ) { + if ( isset( Tokens::$textStringTokens[ $this_token['code'] ] ) ) { for ( $j = ( $i + 1 ); $j < $this->tokens[ $func_open_paren_token ]['parenthesis_closer']; $j++ ) { if ( $this_token['code'] === $this->tokens[ $j ]['code'] ) { $this_token['content'] .= $this->tokens[ $j ]['content']; @@ -526,7 +527,7 @@ protected function check_for_translator_comment( $stack_ptr, $args ) { continue; } - $previous_comment = $this->phpcsFile->findPrevious( PHP_CodeSniffer_Tokens::$commentTokens, ( $stack_ptr - 1 ) ); + $previous_comment = $this->phpcsFile->findPrevious( Tokens::$commentTokens, ( $stack_ptr - 1 ) ); if ( false !== $previous_comment ) { /* diff --git a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php index f5c3466932..75b420145f 100755 --- a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\WhiteSpace; use WordPress\Sniff; +use PHP_CodeSniffer_Tokens as Tokens; /** * Ensure cast statements don't contain whitespace, but *are* surrounded by whitespace, based upon Squiz code. @@ -32,7 +33,7 @@ class CastStructureSpacingSniff extends Sniff { * @return array */ public function register() { - return PHP_CodeSniffer_Tokens::$castTokens; + return Tokens::$castTokens; } /** diff --git a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php index 88ad2be200..e923fd3877 100644 --- a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\WhiteSpace; use WordPress\Sniff; +use PHP_CodeSniffer_Tokens as Tokens; /** * Enforces spacing around logical operators and assignments, based upon Squiz code. @@ -165,7 +166,7 @@ public function process_token( $stackPtr ) { } } - $parenthesisOpener = $this->phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); + $parenthesisOpener = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); // If this is a function declaration. if ( T_FUNCTION === $this->tokens[ $stackPtr ]['code'] ) { @@ -178,7 +179,7 @@ public function process_token( $stackPtr ) { // This function returns by reference (function &function_name() {}). $parenthesisOpener = $this->phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ( $parenthesisOpener + 1 ), null, true @@ -188,7 +189,7 @@ public function process_token( $stackPtr ) { if ( isset( $function_name_ptr ) ) { $parenthesisOpener = $this->phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ( $parenthesisOpener + 1 ), null, true @@ -216,7 +217,7 @@ public function process_token( $stackPtr ) { if ( isset( $this->tokens[ $parenthesisOpener ]['parenthesis_closer'] ) ) { $usePtr = $this->phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ( $this->tokens[ $parenthesisOpener ]['parenthesis_closer'] + 1 ), null, true, @@ -330,7 +331,7 @@ public function process_token( $stackPtr ) { $this->phpcsFile->fixer->addContentBefore( $parenthesisCloser, ' ' ); } } elseif ( ' ' !== $this->tokens[ ( $parenthesisCloser - 1 ) ]['content'] ) { - $prevNonEmpty = $this->phpcsFile->findPrevious( PHP_CodeSniffer_Tokens::$emptyTokens, ( $parenthesisCloser - 1 ), null, true ); + $prevNonEmpty = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $parenthesisCloser - 1 ), null, true ); if ( $this->tokens[ ( $parenthesisCloser ) ]['line'] === $this->tokens[ ( $prevNonEmpty + 1 ) ]['line'] ) { $error = 'Expected exactly one space before closing parenthesis; "%s" found.'; $fix = $this->phpcsFile->addFixableError( @@ -435,7 +436,7 @@ public function process_token( $stackPtr ) { if ( $firstContent !== $scopeCloser ) { $lastContent = $this->phpcsFile->findPrevious( T_WHITESPACE, ( $scopeCloser - 1 ), null, true ); - $lastNonEmptyContent = $this->phpcsFile->findPrevious( PHP_CodeSniffer_Tokens::$emptyTokens, ( $scopeCloser - 1 ), null, true ); + $lastNonEmptyContent = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $scopeCloser - 1 ), null, true ); $checkToken = $lastContent; if ( isset( $this->tokens[ $lastNonEmptyContent ]['scope_condition'] ) ) { @@ -485,7 +486,7 @@ public function process_token( $stackPtr ) { if ( T_COMMENT === $this->tokens[ $trailingContent ]['code'] ) { // Special exception for code where the comment about // an ELSE or ELSEIF is written between the control structures. - $nextCode = $this->phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $scopeCloser + 1 ), null, true ); + $nextCode = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $scopeCloser + 1 ), null, true ); if ( T_ELSE === $this->tokens[ $nextCode ]['code'] || T_ELSEIF === $this->tokens[ $nextCode ]['code'] ) { $trailingContent = $nextCode; diff --git a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php index 9f5376354f..25cc4c390d 100644 --- a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\WhiteSpace; use Squiz_Sniffs_WhiteSpace_OperatorSpacingSniff as PHPCS_Squiz_OperatorSpacingSniff; +use PHP_CodeSniffer_Tokens as Tokens; /** * Verify operator spacing, uses the Squiz sniff, but additionally also sniffs for the `!` (boolean not) operator. @@ -53,7 +54,7 @@ class OperatorSpacingSniff extends PHPCS_Squiz_OperatorSpacingSniff { public function register() { $tokens = parent::register(); $tokens[ T_BOOLEAN_NOT ] = T_BOOLEAN_NOT; - $logical_operators = PHP_CodeSniffer_Tokens::$booleanOperators; + $logical_operators = Tokens::$booleanOperators; // Using array union to auto-dedup. return $tokens + $logical_operators; diff --git a/WordPress/Sniffs/XSS/EscapeOutputSniff.php b/WordPress/Sniffs/XSS/EscapeOutputSniff.php index 7af4d77ff5..eb6ac8fe02 100644 --- a/WordPress/Sniffs/XSS/EscapeOutputSniff.php +++ b/WordPress/Sniffs/XSS/EscapeOutputSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\XSS; use WordPress\Sniff; +use PHP_CodeSniffer_Tokens as Tokens; /** * Verifies that all outputted strings are escaped. @@ -198,7 +199,7 @@ public function process_token( $stackPtr ) { $function = $this->tokens[ $stackPtr ]['content']; // Find the opening parenthesis (if present; T_ECHO might not have it). - $open_paren = $this->phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); + $open_paren = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); // If function, not T_ECHO nor T_PRINT. if ( T_STRING === $this->tokens[ $stackPtr ]['code'] ) { @@ -260,7 +261,7 @@ public function process_token( $stackPtr ) { if ( ! isset( $end_of_statement ) ) { $end_of_statement = $this->phpcsFile->findNext( array( T_SEMICOLON, T_CLOSE_TAG ), $stackPtr ); - $last_token = $this->phpcsFile->findPrevious( PHP_CodeSniffer_Tokens::$emptyTokens, ( $end_of_statement - 1 ), null, true ); + $last_token = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $end_of_statement - 1 ), null, true ); // Check for the ternary operator. We only need to do this here if this // echo is lacking parenthesis. Otherwise it will be handled below. @@ -286,7 +287,7 @@ public function process_token( $stackPtr ) { for ( $i = $stackPtr; $i < $end_of_statement; $i++ ) { // Ignore whitespaces and comments. - if ( isset( PHP_CodeSniffer_Tokens::$emptyTokens[ $this->tokens[ $i ]['code'] ] ) ) { + if ( isset( Tokens::$emptyTokens[ $this->tokens[ $i ]['code'] ] ) ) { continue; } @@ -388,7 +389,7 @@ public function process_token( $stackPtr ) { // Get the first parameter (name of function being used on the array). $mapped_function = $this->phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, + Tokens::$emptyTokens, ( $function_opener + 1 ), $this->tokens[ $function_opener ]['parenthesis_closer'], true From 744fc5907ae110261dfc264aee33963583012f60 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 20 Jul 2017 12:16:36 +0200 Subject: [PATCH 04/10] PHPCS 3.x compat: Make sure checks for PHP native functions/etc are done in the global namespace --- .../NamingConventions/PrefixAllGlobalsSniff.php | 12 ++++++------ .../NamingConventions/PrefixAllGlobalsUnitTest.php | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index ad0ec98481..c16a9a21b9 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -207,7 +207,7 @@ public function process_token( $stackPtr ) { } $item_name = $this->phpcsFile->getDeclarationName( $stackPtr ); - if ( function_exists( $item_name ) ) { + if ( function_exists( '\\' . $item_name ) ) { // Backfill for PHP native function. return; } @@ -234,14 +234,14 @@ public function process_token( $stackPtr ) { switch ( $this->tokens[ $stackPtr ]['type'] ) { case 'T_CLASS': - if ( class_exists( $item_name ) ) { + if ( class_exists( '\\' . $item_name ) ) { // Backfill for PHP native class. return; } break; case 'T_INTERFACE': - if ( interface_exists( $item_name ) ) { + if ( interface_exists( '\\' . $item_name ) ) { // Backfill for PHP native interface. return; } @@ -251,7 +251,7 @@ public function process_token( $stackPtr ) { break; case 'T_TRAIT': - if ( function_exists( 'trait_exists' ) && trait_exists( $item_name ) ) { + if ( function_exists( '\trait_exists' ) && trait_exists( '\\' . $item_name ) ) { // Backfill for PHP native trait. return; } @@ -280,7 +280,7 @@ public function process_token( $stackPtr ) { } $item_name = $this->tokens[ $constant_name_ptr ]['content']; - if ( defined( $item_name ) ) { + if ( defined( '\\' . $item_name ) ) { // Backfill for PHP native constant. return; } @@ -620,7 +620,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p } if ( 'define' === $matched_content ) { - if ( defined( $raw_content ) ) { + if ( defined( '\\' . $raw_content ) ) { // Backfill for PHP native constant. return; } diff --git a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php index 48433e6698..3d24c48125 100644 --- a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php +++ b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php @@ -53,10 +53,10 @@ public function getErrorList( $testFile = 'PrefixAllGlobalsUnitTest.inc' ) { 154 => ( PHP_VERSION_ID >= 50300 ) ? 0 : 1, // PHPCS on PHP 5.2 does not recognize namespaces. 155 => ( PHP_VERSION_ID >= 50300 ) ? 0 : 1, // PHPCS on PHP 5.2 does not recognize namespaces. // Backfills. - 225 => ( function_exists( 'mb_strpos' ) ) ? 0 : 1, - 230 => ( function_exists( 'array_column' ) ) ? 0 : 1, - 234 => ( defined( 'E_DEPRECATED' ) ) ? 0 : 1, - 238 => ( class_exists( 'IntlTimeZone' ) ) ? 0 : 1, + 225 => ( function_exists( '\mb_strpos' ) ) ? 0 : 1, + 230 => ( function_exists( '\array_column' ) ) ? 0 : 1, + 234 => ( defined( '\E_DEPRECATED' ) ) ? 0 : 1, + 238 => ( class_exists( '\IntlTimeZone' ) ) ? 0 : 1, ); case 'PrefixAllGlobalsUnitTest.1.inc': From 51cdbb3fc67fc02553ee28d209e8311adebf5518 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 21 Jul 2017 00:26:47 +0200 Subject: [PATCH 05/10] PHPCS 3.x compat: Add helper class & implement use A number of PHPCS 2.x classes have been split out over several classes in PHPCS 3.x. Aliasing the new classname to the old would therefore not be a good idea. This helper class acts as a compatibility layer for these cases. The helper class only addresses the most common functionality needed and is by no means exhaustive. The helper class contains one function which is currently not (yet) used `get_version()`. This method was added in anticipation of continuing support for both PHPCS 3.x as well as 2.x for another year. PHPCS 3.x is likely to bring functionality which will not be available in PHPCS 2.x, so being able to retrieve the PHPCS version will, at some point, probably be helpful. N.B. The class name for this class has to be in CamelCaps (without underscore) as otherwise the PHPCS 2.x autoloader can not find it. --- WordPress/PHPCSHelper.php | 115 ++++++++++++++++++ .../Sniffs/Arrays/ArrayIndentationSniff.php | 9 +- .../PrefixAllGlobalsSniff.php | 3 +- WordPress/Sniffs/WP/I18nSniff.php | 3 +- .../WhiteSpace/DisallowInlineTabsSniff.php | 9 +- WordPress/Tests/WP/I18nUnitTest.php | 6 +- 6 files changed, 127 insertions(+), 18 deletions(-) create mode 100644 WordPress/PHPCSHelper.php diff --git a/WordPress/PHPCSHelper.php b/WordPress/PHPCSHelper.php new file mode 100644 index 0000000000..8817900680 --- /dev/null +++ b/WordPress/PHPCSHelper.php @@ -0,0 +1,115 @@ +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']; + } + } + + return $tab_width; + } + +} diff --git a/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php b/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php index b9de09f59b..e8c04b14ee 100644 --- a/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\Arrays; use WordPress\Sniff; +use WordPress\PHPCSHelper; use PHP_CodeSniffer_Tokens as Tokens; /** @@ -89,13 +90,7 @@ public function register() { */ public function process_token( $stackPtr ) { if ( ! isset( $this->tab_width ) ) { - $cli_values = $this->phpcsFile->phpcs->cli->getCommandLineValues(); - if ( ! isset( $cli_values['tabWidth'] ) || 0 === $cli_values['tabWidth'] ) { - // We have no idea how wide tabs are, so assume 4 spaces for fixing. - $this->tab_width = 4; - } else { - $this->tab_width = $cli_values['tabWidth']; - } + $this->tab_width = PHPCSHelper::get_tab_width( $this->phpcsFile ); } /* diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index c16a9a21b9..0cb2269248 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\NamingConventions; use WordPress\AbstractFunctionParameterSniff; +use WordPress\PHPCSHelper; use PHP_CodeSniffer_Tokens as Tokens; /** @@ -156,7 +157,7 @@ public function process_token( $stackPtr ) { } // Allow overruling the prefixes set in a ruleset via the command line. - $cl_prefixes = trim( PHP_CodeSniffer::getConfigData( 'prefixes' ) ); + $cl_prefixes = trim( PHPCSHelper::get_config_data( 'prefixes' ) ); if ( ! empty( $cl_prefixes ) ) { $this->prefixes = $cl_prefixes; } diff --git a/WordPress/Sniffs/WP/I18nSniff.php b/WordPress/Sniffs/WP/I18nSniff.php index 64e2102752..d33714ba57 100644 --- a/WordPress/Sniffs/WP/I18nSniff.php +++ b/WordPress/Sniffs/WP/I18nSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\WP; use WordPress\Sniff; +use WordPress\PHPCSHelper; use PHP_CodeSniffer_Tokens as Tokens; /** @@ -146,7 +147,7 @@ public function process_token( $stack_ptr ) { $token = $this->tokens[ $stack_ptr ]; // Allow overruling the text_domain set in a ruleset via the command line. - $cl_text_domain = trim( PHP_CodeSniffer::getConfigData( 'text_domain' ) ); + $cl_text_domain = trim( PHPCSHelper::get_config_data( 'text_domain' ) ); if ( ! empty( $cl_text_domain ) ) { $this->text_domain = $cl_text_domain; } diff --git a/WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php b/WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php index f8555e550b..cf19c31854 100644 --- a/WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php +++ b/WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php @@ -10,6 +10,7 @@ namespace WordPress\Sniffs\WhiteSpace; use WordPress\Sniff; +use WordPress\PHPCSHelper; /** * Enforces using spaces for mid-line alignment. @@ -50,13 +51,7 @@ public function register() { */ public function process_token( $stackPtr ) { if ( ! isset( $this->tab_width ) ) { - $cli_values = $this->phpcsFile->phpcs->cli->getCommandLineValues(); - if ( ! isset( $cli_values['tabWidth'] ) || 0 === $cli_values['tabWidth'] ) { - // We have no idea how wide tabs are, so assume 4 spaces for fixing. - $this->tab_width = 4; - } else { - $this->tab_width = $cli_values['tabWidth']; - } + $this->tab_width = PHPCSHelper::get_tab_width( $this->phpcsFile ); } $check_tokens = array( diff --git a/WordPress/Tests/WP/I18nUnitTest.php b/WordPress/Tests/WP/I18nUnitTest.php index a2de453114..edfc318a8e 100644 --- a/WordPress/Tests/WP/I18nUnitTest.php +++ b/WordPress/Tests/WP/I18nUnitTest.php @@ -7,6 +7,8 @@ * @license https://opensource.org/licenses/MIT MIT */ +use WordPress\PHPCSHelper; + /** * Unit test class for the I18n sniff. * @@ -20,14 +22,14 @@ class WordPress_Tests_WP_I18nUnitTest extends AbstractSniffUnitTest { */ protected function setUp() { parent::setUp(); - PHP_CodeSniffer::setConfigData( 'text_domain', 'my-slug,default', true ); + PHPCSHelper::set_config_data( 'text_domain', 'my-slug,default', true ); } /** * Reset the $groups property. */ protected function tearDown() { - PHP_CodeSniffer::setConfigData( 'text_domain', null, true ); + PHPCSHelper::set_config_data( 'text_domain', null, true ); parent::tearDown(); } From 3112d5a16598afe7ee25bd667a088a464a5ea651 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 22 Jul 2017 20:37:32 +0200 Subject: [PATCH 06/10] PHPCS 3.x compat: Alias PHPCS 3.x classes to their PHPCS 2.x counterparts Notes: * The file is automatically loaded by PHPCS using the new `` option. This option, when encountered in the ruleset, is ignored by previous PHPCS versions, so can be used safely and will automatically make sure the file is only loaded for PHPCS 3.x. * The file is loaded after the PHPCS native autoloader has started, but before any sniffs are loaded making for a clean way to add the aliases and prevent fatal 'class not found' errors. * Each class alias statement has to be wrapped in a `class_exists` condition to prevent fatal `class already declared` errors when this ruleset is used in combination with other external ruleset(s) which use the same/similar methodology to create PHPCS cross-version compatibility. The `` ruleset directive was added in PHPCS 3.0.1 in response to issue squizlabs/PHP_CodeSniffer#1469 --- WordPress-Core/ruleset.xml | 2 ++ WordPress-Extra/ruleset.xml | 2 ++ WordPress-VIP/ruleset.xml | 2 ++ WordPress/PHPCSAliases.php | 50 +++++++++++++++++++++++++++++++++++++ WordPress/ruleset.xml | 4 ++- 5 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 WordPress/PHPCSAliases.php diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index f31faff851..d763d610e8 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -2,6 +2,8 @@ Non-controversial generally-agreed upon WordPress Coding Standards + ./../WordPress/PHPCSAliases.php + diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index 59cb2686bf..370dc23a5f 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -2,6 +2,8 @@ Best practices beyond core WordPress Coding Standards + ./../WordPress/PHPCSAliases.php + diff --git a/WordPress-VIP/ruleset.xml b/WordPress-VIP/ruleset.xml index bbe5c82359..23c386b6a6 100644 --- a/WordPress-VIP/ruleset.xml +++ b/WordPress-VIP/ruleset.xml @@ -2,6 +2,8 @@ WordPress VIP Coding Standards + ./../WordPress/PHPCSAliases.php + + /Test/AllTests.php + /Test/Standards/*.php + diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000000..f5c2cf0ceb --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,8 @@ + + + From 3070fb27f4fa59c3cc097a2524bd57d6733c8d71 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 24 Jul 2017 17:57:20 +0200 Subject: [PATCH 10/10] PHPCS 3.x compat: Update readme, build script and config files Travis: * No longer test the build against PHP 5.2. * Only test against PHP 5.3 icw PHPCS 2.x. * Test all other PHP versions against both PHPCS 2.x as well as `master` (3.x). * Test the build against PHPCS 3.x using the `master` branch. * Removed allowance for build failures against `master`. * Adjusted phpunit command to allow for testing on both PHPCS 2.x as well as 3.x. Composer: * Add the minimum required PHP version. * Make the PHPCS requirement more specific and allow for PHPCS 3.x. "Own" PHPCS custom ruleset: * Enforce PSR1 namespaces. Readme: * Adjusted (minimum) requirements information. * Updated installation instructions. * Updated travis example code. Contributing * Updated unit test instructions. * Updated example sniff code. * Removed reference to potentially upstreaming WPCS to PHPCS as reason for using the PHPCS unit test suite. Let's be fair: the sniffs ought to be unit tested anyway, no matter what. * Update unit testing conventions example. The example was referring to a now deprecated sniff, so selected another sniff for the example code. --- .travis.yml | 44 +++++-------- CONTRIBUTING.md | 172 +++++++++++++++++++++++++++++++----------------- README.md | 15 +++-- bin/phpcs.xml | 3 + composer.json | 3 +- 5 files changed, 144 insertions(+), 93 deletions(-) diff --git a/.travis.yml b/.travis.yml index b31d43db6e..0ab146b878 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ dist: trusty cache: apt: true - + language: - php @@ -14,11 +14,12 @@ php: - 5.6 - 7.0 - 7.1 + - nightly env: - # Branch for patches against 2.x. `master` is now 3.x which WPCS is not (yet) compatible with. - - PHPCS_BRANCH=2.9 LINT=1 - # Tagged release + # `master` is now 3.x. + - PHPCS_BRANCH=master LINT=1 + # Lowest tagged release in the 2.x series with which WPCS is compatible. - PHPCS_BRANCH=2.9.0 matrix: @@ -31,38 +32,27 @@ matrix: apt: packages: - libxml2-utils - # Run against PHPCS 3.0. I just picked to run it against 5.6. - - php: 5.6 - env: PHPCS_BRANCH=master + # Run against HHVM and PHP nightly. - php: hhvm sudo: required - dist: trusty + dist: trusty group: edge - env: PHPCS_BRANCH=2.9 LINT=1 - - php: nightly - env: PHPCS_BRANCH=2.9 LINT=1 - # Test PHP 5.3 with short_open_tags set to On (is Off by default) - - php: 5.3 - env: PHPCS_BRANCH=2.9 SHORT_OPEN_TAGS=true - dist: precise + env: PHPCS_BRANCH=master LINT=1 + + # 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 + 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 - dist: precise - - php: 5.2 - env: PHPCS_BRANCH=2.9 - dist: precise - - php: 5.2 - env: PHPCS_BRANCH=2.9.0 + env: PHPCS_BRANCH=2.9.0 SHORT_OPEN_TAGS=true dist: precise + allow_failures: # Allow failures for unstable builds. - php: nightly - php: hhvm - - env: PHPCS_BRANCH=master before_install: - export XMLLINT_INDENT=" " @@ -82,8 +72,10 @@ script: # Lint the PHP files against parse errors. - if [[ "$LINT" == "1" ]]; then if find . -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." ]]; then phpunit --filter WordPress /tmp/phpcs/tests/AllTests.php; fi - - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --filter WordPress /tmp/phpcs/tests/AllTests.php; fi + - 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 $PHPCS_DIR/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 $PHPCS_DIR/tests/AllTests.php; fi # WordPress Coding Standards. # @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards # @link http://pear.php.net/package/PHP_CodeSniffer/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 30093967ec..ac4c14a776 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,11 +24,15 @@ When you introduce new `public` sniff properties, or your sniff extends a class 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. +To this end, the `WordPress\Sniff::has_whitelist_comment()` method was introduced. Example usage: ```php -class WordPress_Sniffs_CSRF_NonceVerificationSniff extends WordPress_Sniff { +namespace WordPress\Sniffs\CSRF; + +use WordPress\Sniff; + +class NonceVerificationSniff extends Sniff { public function process_token( $stackPtr ) { @@ -48,92 +52,140 @@ When you introduce a new whitelist comment, please don't forget to update the [w # Unit Testing -TL;DR +## Pre-requisites +* WordPress-Coding-Standards +* PHP CodeSniffer 2.9.x or 3.x +* PHPUnit 4.x or 5.x -If you have installed `phpcs` and the WordPress-Coding-Standards as [noted in the README](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards#how-to-use-this), then you can navigate to the directory where the `phpcs` repo is checked out and do: +The WordPress Coding Standards use the PHP CodeSniffer native unit test suite for unit testing the sniffs. -```sh -composer install -vendor/bin/phpunit --filter WordPress tests/AllTests.php +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`. + +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. + +## Before running the unit tests + +N.B.: _If you used Composer to install the WordPress Coding Standards, you can skip this step._ + +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. +```xml + + + + + ``` +## 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. + +* 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: + ```sh + phpunit --bootstrap="./Test/phpcs2-bootstrap.php" --filter WordPress ./Test/AllTests.php + ``` + Expected output: +``` +PHPUnit 4.8.19 by Sebastian Bergmann and contributors. -[![asciicast](https://asciinema.org/a/98078.png)](https://asciinema.org/a/98078) +Runtime: PHP 7.1.3 with Xdebug 2.5.1 +Configuration: /WordPressCS/phpunit.xml + +...................................................... -You can ignore any skipped tests as these are for `PHP_CodeSniffer` external tools. +Tests generated 558 unique error codes; 48 were fixable (8.6%) -The reason why we need to checkout from `PHP_CodeSniffer` git repo to run the tests is because -PEAR installation is intended for ready-to-use not for development. At some point `WordPress-Coding-Standards` -might be submitted to `PHP_CodeSniffer` repo and using their existing convention for unit tests -will eventually help them to test the code before merging in. +Time: 12.25 seconds, Memory: 24.00Mb + +OK (54 tests, 0 assertions) +``` + +[![asciicast](https://asciinema.org/a/98078.png)](https://asciinema.org/a/98078) ## Unit Testing conventions -If you see inside the `WordPress/Tests`, the structure mimics the `WordPress/Sniffs`. For example, -the `WordPress/Sniffs/Arrays/ArrayDeclarationSniff.php` sniff has unit test class defined in -`WordPress/Tests/Arrays/ArrayDeclarationUnitTest.php` that check `WordPress/Tests/Arrays/ArrayDeclarationUnitTest.inc` -file. See the file naming convention? Lets take a look what inside `ArrayDeclarationUnitTest.php`: +If you look inside the `WordPress/Tests` subdirectory, you'll see the structure mimics the `WordPress/Sniffs` subdirectory structure. For example, the `WordPress/Sniffs/PHP/POSIXFunctionsSniff.php` sniff has its unit test class defined in `WordPress/Tests/PHP/POSIXFunctionsUnitTest.php` which checks the `WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc` test case file. See the file naming convention? + +Lets take a look at what's inside `POSIXFunctionsUnitTest.php`: ```php ... -class WordPress_Tests_Arrays_ArrayDeclarationUnitTest extends AbstractSniffUnitTest -{ - public function getErrorList() - { - return array( - 3 => 1, - 7 => 1, - 9 => 1, - 16 => 1, - 31 => 2, - ); - - }//end getErrorList() -} +namespace WordPress\Tests\PHP; + +use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; + +class POSIXFunctionsUnitTest extends AbstractSniffUnitTest { + + /** + * Returns the lines where errors should occur. + * + * @return array => + */ + public function getErrorList() { + return array( + 13 => 1, + 16 => 1, + 18 => 1, + 20 => 1, + 22 => 1, + 24 => 1, + 26 => 1, + ); + + } ... ``` -Also note the class name convention. The method `getErrorList` MUST return an array of line numbers -indicating errors (when running `phpcs`) found in `WordPress/Tests/Arrays/ArrayDeclarationUnitTest.inc`. +Also note the class name convention. The method `getErrorList()` MUST return an array of line numbers indicating errors (when running `phpcs`) found in `WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc`. If you run: ```sh $ cd /path-to-cloned/phpcs -$ ./scripts/phpcs --standard=Wordpress -s CodeSniffer/Standards/WordPress/Tests/Arrays/ArrayDeclarationUnitTest.inc +$ ./bin/phpcs --standard=Wordpress -s /path/to/WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc --sniffs=WordPress.PHP.POSIXFunctions ... -------------------------------------------------------------------------------- -FOUND 8 ERROR(S) AND 2 WARNING(S) AFFECTING 6 LINE(S) +FOUND 7 ERRORS AFFECTING 7 LINES -------------------------------------------------------------------------------- - 3 | ERROR | Array keyword should be lower case; expected "array" but found - | | "Array" (WordPress.Arrays.ArrayDeclaration) - 7 | ERROR | There must be no space between the Array keyword and the - | | opening parenthesis (WordPress.Arrays.ArrayDeclaration) - 9 | ERROR | Empty array declaration must have no space between the - | | parentheses (WordPress.Arrays.ArrayDeclaration) - 12 | WARNING | No space after opening parenthesis of array is bad style - | | (WordPress.Arrays.ArrayDeclaration) - 12 | WARNING | No space before closing parenthesis of array is bad style - | | (WordPress.Arrays.ArrayDeclaration) - 16 | ERROR | Each line in an array declaration must end in a comma - | | (WordPress.Arrays.ArrayDeclaration) - 31 | ERROR | Expected 1 space between "'type'" and double arrow; 0 found - | | (WordPress.Arrays.ArrayDeclaration) - 31 | ERROR | Expected 1 space between double arrow and "'post'"; 0 found - | | (WordPress.Arrays.ArrayDeclaration) - 31 | ERROR | Expected 1 space before "=>"; 0 found - | | (WordPress.WhiteSpace.OperatorSpacing) - 31 | ERROR | Expected 1 space after "=>"; 0 found - | | (WordPress.WhiteSpace.OperatorSpacing) + 13 | ERROR | ereg() has been deprecated since PHP 5.3 and removed in PHP 7.0, + | | please use preg_match() instead. + | | (WordPress.PHP.POSIXFunctions.ereg_ereg) + 16 | ERROR | eregi() has been deprecated since PHP 5.3 and removed in PHP 7.0, + | | please use preg_match() instead. + | | (WordPress.PHP.POSIXFunctions.ereg_eregi) + 18 | ERROR | ereg_replace() has been deprecated since PHP 5.3 and removed in PHP + | | 7.0, please use preg_replace() instead. + | | (WordPress.PHP.POSIXFunctions.ereg_replace_ereg_replace) + 20 | ERROR | eregi_replace() has been deprecated since PHP 5.3 and removed in PHP + | | 7.0, please use preg_replace() instead. + | | (WordPress.PHP.POSIXFunctions.ereg_replace_eregi_replace) + 22 | ERROR | split() has been deprecated since PHP 5.3 and removed in PHP 7.0, + | | please use explode(), str_split() or preg_split() instead. + | | (WordPress.PHP.POSIXFunctions.split_split) + 24 | ERROR | spliti() has been deprecated since PHP 5.3 and removed in PHP 7.0, + | | please use explode(), str_split() or preg_split() instead. + | | (WordPress.PHP.POSIXFunctions.split_spliti) + 26 | ERROR | sql_regcase() has been deprecated since PHP 5.3 and removed in PHP + | | 7.0, please use preg_match() instead. + | | (WordPress.PHP.POSIXFunctions.ereg_sql_regcase) -------------------------------------------------------------------------------- .... ``` +You'll see the line number and number of ERRORs we need to return in the `getErrorList()` method. -You'll see the line number and number of ERRORs we need to return in `getErrorList` method. -In line #31 there are two ERRORs belong to `WordPress.WhiteSpace.OperatorSpacing` sniff and -it MUST not included in `ArrayDeclarationUnitTest` (that's why we only return 2 errros for line #31). -Also there's `getWarningList` method in unit test class that returns an array of line numbers -indicating WARNINGs. +The `--sniffs=...` directive limits the output to the sniff you are testing. ## Sniff Code Standards diff --git a/README.md b/README.md index b8b701db8b..d131ad2c10 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,8 @@ This project is a collection of [PHP_CodeSniffer](https://github.com/squizlabs/P ### Requirements -The WordPress Coding Standards require PHP 5.2 or higher and the [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) version **2.9.0** or higher. -The WordPress Coding Standards are currently [not compatible with the upcoming PHPCS 3 release](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/718). +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. ### Composer @@ -58,7 +58,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 `wpcs/vendor/bin` path to a PATH environment in your operating system. +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. #### Installing WPCS as a dependency @@ -96,10 +96,13 @@ 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` directory to your `PATH` environment variable via your `.bashrc`. +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`. You should then see `WordPress-Core` et al listed when you run `phpcs -i`. @@ -241,7 +244,7 @@ before_install: # 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 # Set install path for WordPress Coding Standards. - - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/scripts/phpcs --config-set installed_paths $SNIFFS_DIR; fi + - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/bin/phpcs --config-set installed_paths $SNIFFS_DIR; fi # After CodeSniffer install you should refresh your path. - if [[ "$SNIFF" == "1" ]]; then phpenv rehash; fi @@ -251,7 +254,7 @@ script: # for example: `--standard=wpcs.xml`. # You can use any of the normal PHPCS command line arguments in the command: # https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage - - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/scripts/phpcs -p . --standard=WordPress; fi + - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/bin/phpcs -p . --standard=WordPress; fi ``` diff --git a/bin/phpcs.xml b/bin/phpcs.xml index b39b2cf4ff..904cec2b93 100644 --- a/bin/phpcs.xml +++ b/bin/phpcs.xml @@ -13,4 +13,7 @@ + + + diff --git a/composer.json b/composer.json index a26ee8b553..1b5e513a83 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ } ], "require" : { - "squizlabs/php_codesniffer": "^2.9.0" + "php" : ">=5.3", + "squizlabs/php_codesniffer": "^2.9.0 || ^3.0.2" }, "suggest" : { "dealerdirect/phpcodesniffer-composer-installer": "*"