diff --git a/WordPress/AbstractArrayAssignmentRestrictionsSniff.php b/WordPress/AbstractArrayAssignmentRestrictionsSniff.php index f875bc9d7c..3329826316 100644 --- a/WordPress/AbstractArrayAssignmentRestrictionsSniff.php +++ b/WordPress/AbstractArrayAssignmentRestrictionsSniff.php @@ -2,17 +2,21 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Restricts array assignment of certain keys. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @package WPCS\WordPressCodingStandards + * + * @since 0.3.0 + * @since 0.10.0 Class became a proper abstract class. This was already the behaviour. + * Moved the file and renamed the class from + * `WordPress_Sniffs_Arrays_ArrayAssignmentRestrictionsSniff` to + * `WordPress_AbstractArrayAssignmentRestrictionsSniff`. */ abstract class WordPress_AbstractArrayAssignmentRestrictionsSniff extends WordPress_Sniff { @@ -47,7 +51,7 @@ public function register() { T_DOUBLE_QUOTED_STRING, ); - } // end register() + } /** * Groups of variables to restrict. @@ -195,4 +199,4 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { */ abstract public function callback( $key, $val, $line, $group ); -} // end class +} // End class. diff --git a/WordPress/AbstractClassRestrictionsSniff.php b/WordPress/AbstractClassRestrictionsSniff.php index bcb2164958..a9a4e82426 100644 --- a/WordPress/AbstractClassRestrictionsSniff.php +++ b/WordPress/AbstractClassRestrictionsSniff.php @@ -2,17 +2,17 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Restricts usage of some classes. * - * @category PHP - * @package PHP_CodeSniffer - * @author Juliette Reinders Folmer + * @package WPCS\WordPressCodingStandards + * + * @since 0.10.0 */ abstract class WordPress_AbstractClassRestrictionsSniff extends WordPress_AbstractFunctionRestrictionsSniff { @@ -51,8 +51,9 @@ abstract class WordPress_AbstractClassRestrictionsSniff extends WordPress_Abstra * Documented here for clarity. Not (re)defined as it is already defined in the parent class. * * @return array + * + abstract public function getGroups(); */ - // abstract public function getGroups(); /** * Returns an array of tokens this test wants to listen for. @@ -72,7 +73,7 @@ public function register() { T_IMPLEMENTS, ); - } // end register() + } /** * Processes this test, when one of its tokens is encountered. @@ -178,13 +179,13 @@ protected function prepare_name_for_regex( $classname ) { /** * See if the classname was found in a namespaced file and if so, add the namespace to the classname. * - * @param string $classname The full classname as found. - * @param object $phpcsFile Instance of phpcsFile. - * @param array $tokens The token stack for this file. - * @param int $search_from The token position to search up from. + * @param string $classname The full classname as found. + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @param array $tokens The token stack for this file. + * @param int $search_from The token position to search up from. * @return string Classname, potentially prefixed with the namespace. */ - protected function get_namespaced_classname( $classname, $phpcsFile, $tokens, $search_from ) { + protected function get_namespaced_classname( $classname, PHP_CodeSniffer_File $phpcsFile, $tokens, $search_from ) { // Don't do anything if this is already a fully qualified classname. if ( empty( $classname ) || '\\' === $classname[0] ) { return $classname; @@ -216,12 +217,12 @@ protected function get_namespaced_classname( $classname, $phpcsFile, $tokens, $s /** * Determine the namespace name based on whether this is a scoped namespace or a file namespace. * - * @param object $phpcsFile Instance of phpcsFile. - * @param array $tokens The token stack for this file. - * @param int $search_from The token position to search up from. + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @param array $tokens The token stack for this file. + * @param int $search_from The token position to search up from. * @return string Namespace name or empty string if it couldn't be determined or no namespace applied. */ - protected function determine_namespace( $phpcsFile, $tokens, $search_from ) { + protected function determine_namespace( PHP_CodeSniffer_File $phpcsFile, $tokens, $search_from ) { $namespace = ''; if ( ! empty( $tokens[ $search_from ]['conditions'] ) ) { @@ -247,12 +248,12 @@ protected function determine_namespace( $phpcsFile, $tokens, $search_from ) { /** * Get the namespace name based on the position of the namespace scope opener. * - * @param object $phpcsFile Instance of phpcsFile. - * @param array $tokens The token stack for this file. - * @param int $t_namespace_token The token position to search from. + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @param array $tokens The token stack for this file. + * @param int $t_namespace_token The token position to search from. * @return string Namespace name. */ - protected function get_namespace_name( $phpcsFile, $tokens, $t_namespace_token ) { + protected function get_namespace_name( PHP_CodeSniffer_File $phpcsFile, $tokens, $t_namespace_token ) { $nameEnd = ( $phpcsFile->findNext( array( T_OPEN_CURLY_BRACKET, T_WHITESPACE, T_SEMICOLON ), ( $t_namespace_token + 2 ) ) - 1 ); $length = ( $nameEnd - ( $t_namespace_token + 1 ) ); $namespace = $phpcsFile->getTokensAsString( ( $t_namespace_token + 2 ), $length ); @@ -260,4 +261,4 @@ protected function get_namespace_name( $phpcsFile, $tokens, $t_namespace_token ) return $namespace; } -} // end class +} // End class. diff --git a/WordPress/AbstractFunctionRestrictionsSniff.php b/WordPress/AbstractFunctionRestrictionsSniff.php index 4598c1a742..e21341fd75 100644 --- a/WordPress/AbstractFunctionRestrictionsSniff.php +++ b/WordPress/AbstractFunctionRestrictionsSniff.php @@ -2,17 +2,21 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Restricts usage of some functions. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @package WPCS\WordPressCodingStandards + * + * @since 0.3.0 + * @since 0.10.0 Class became a proper abstract class. This was already the behaviour. + * Moved the file and renamed the class from + * `WordPress_Sniffs_Functions_FunctionRestrictionsSniff` to + * `WordPress_AbstractFunctionRestrictionsSniff`. */ abstract class WordPress_AbstractFunctionRestrictionsSniff implements PHP_CodeSniffer_Sniff { @@ -209,4 +213,4 @@ protected function prepare_name_for_regex( $function ) { return $function; } -} // end class +} // End class. diff --git a/WordPress/AbstractVariableRestrictionsSniff.php b/WordPress/AbstractVariableRestrictionsSniff.php index 530f809313..5cd5bdbfc4 100644 --- a/WordPress/AbstractVariableRestrictionsSniff.php +++ b/WordPress/AbstractVariableRestrictionsSniff.php @@ -2,17 +2,21 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Restricts usage of some variables. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @package WPCS\WordPressCodingStandards + * + * @since 0.3.0 + * @since 0.10.0 Class became a proper abstract class. This was already the behaviour. + * Moved the file and renamed the class from + * `WordPress_Sniffs_Variables_VariableRestrictionsSniff` to + * `WordPress_AbstractVariableRestrictionsSniff`. */ abstract class WordPress_AbstractVariableRestrictionsSniff implements PHP_CodeSniffer_Sniff { @@ -48,7 +52,7 @@ public function register() { T_DOUBLE_QUOTED_STRING, ); - } // end register() + } /** * Groups of variables to restrict. @@ -76,7 +80,7 @@ abstract public function getGroups(); * @param int $stackPtr The position of the current token * in the stack passed in $tokens. * - * @return void + * @return int|void If no groups are found, a stack pointer to indicate to skip the current one is passed. */ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); @@ -111,7 +115,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { $var = $token['content']; } elseif ( in_array( $token['code'], array( T_OBJECT_OPERATOR, T_DOUBLE_COLON, T_DOUBLE_QUOTED_STRING ), true ) && ! empty( $group['object_vars'] ) ) { - // Object var, ex: $foo->bar / $foo::bar / Foo::bar / Foo::$bar + // Object var, ex: $foo->bar / $foo::bar / Foo::bar / Foo::$bar . $patterns = array_merge( $patterns, $group['object_vars'] ); $owner = $phpcsFile->findPrevious( array( T_VARIABLE, T_STRING ), $stackPtr ); @@ -165,6 +169,12 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } // end process() + /** + * Transform a wildcard pattern to a usable regex pattern. + * + * @param string $pattern Pattern. + * @return string + */ private function test_patterns( $pattern ) { $pattern = preg_quote( $pattern, '#' ); $pattern = preg_replace( @@ -173,6 +183,6 @@ private function test_patterns( $pattern ) { $pattern ); return $pattern; - } // end test_patterns() + } -} // end class +} // End class. diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index ee010cd4f8..9e7f8bd8b0 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -2,8 +2,9 @@ /** * Represents a PHP_CodeSniffer sniff for sniffing WordPress coding standards. * - * @category PHP - * @package PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** @@ -11,10 +12,8 @@ * * Provides a bootstrap for the sniffs, to reduce code duplication. * - * @category PHP - * @package PHP_CodeSniffer - * @version 0.4.0 - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 0.4.0 */ abstract class WordPress_Sniff implements PHP_CodeSniffer_Sniff { @@ -461,7 +460,7 @@ abstract class WordPress_Sniff implements PHP_CodeSniffer_Sniff { /** * A list of superglobals that incorporate user input. * - * @since 0.4.0 + * @since 0.5.0 * * @var string[] */ @@ -578,7 +577,7 @@ protected function has_whitelist_comment( $comment, $stackPtr ) { * * $array['key'][ $foo ][ something() ] = $bar; * - * @since 0.4.0 + * @since 0.5.0 * * @param int $stackPtr The index of the token in the stack. This must points to * either a T_VARIABLE or T_CLOSE_SQUARE_BRACKET token. @@ -613,7 +612,7 @@ protected function is_assignment( $stackPtr ) { return true; } - // Check if this is an array assignment, e.g., $var['key'] = 'val'; + // Check if this is an array assignment, e.g., `$var['key'] = 'val';` . if ( T_OPEN_SQUARE_BRACKET === $tokens[ $next_non_empty ]['code'] ) { return $this->is_assignment( $tokens[ $next_non_empty ]['bracket_closer'] ); } @@ -633,14 +632,14 @@ protected function is_assignment( $stackPtr ) { protected function has_nonce_check( $stackPtr ) { /** - * @var array { - * A cache of the scope that we last checked for nonce verification in. + * A cache of the scope that we last checked for nonce verification in. * - * @var string $file The name of the file. - * @var int $start The index of the token where the scope started. - * @var int $end The index of the token where the scope ended. - * @var bool|int $nonce_check The index of the token where an nonce - * check was found, or false if none was found. + * @var array { + * @var string $file The name of the file. + * @var int $start The index of the token where the scope started. + * @var int $end The index of the token where the scope ended. + * @var bool|int $nonce_check The index of the token where an nonce check + * was found, or false if none was found. * } */ static $last; @@ -973,7 +972,6 @@ protected function get_array_access_key( $stackPtr ) { protected function is_validated( $stackPtr, $array_key = null, $in_condition_only = false ) { if ( $in_condition_only ) { - /* This is a stricter check, requiring the variable to be used only within the validation condition. @@ -1004,7 +1002,6 @@ protected function is_validated( $stackPtr, $array_key = null, $in_condition_onl $scope_end = $condition['parenthesis_closer']; } else { - /* We are are more loose, requiring only that the variable be validated in the same function/file scope as it is used. @@ -1130,6 +1127,8 @@ protected function is_comparison( $stackPtr ) { * This function will check the token and return 'closure', 'trait', or 'class', * based on which of these uses the use is being used for. * + * @since 0.7.0 + * * @param int $stackPtr The position of the token to check. * * @return string The type of use. @@ -1157,6 +1156,8 @@ protected function get_use_type( $stackPtr ) { * * Check if '$' is followed by a valid variable name, and that it is not preceded by an escape sequence. * + * @since 0.9.0 + * * @param string $string A T_DOUBLE_QUOTED_STRING token. * * @return array Variable names (without '$' sigil). diff --git a/WordPress/Sniffs/Arrays/ArrayAssignmentRestrictionsSniff.php b/WordPress/Sniffs/Arrays/ArrayAssignmentRestrictionsSniff.php index 0fb0f044b9..309303d785 100644 --- a/WordPress/Sniffs/Arrays/ArrayAssignmentRestrictionsSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayAssignmentRestrictionsSniff.php @@ -2,24 +2,24 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Restricts array assignment of certain keys. * - * @deprecated 0.1.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. + * @package WPCS\WordPressCodingStandards * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @since 0.3.0 + * @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 */ class WordPress_Sniffs_Arrays_ArrayAssignmentRestrictionsSniff extends WordPress_AbstractArrayAssignmentRestrictionsSniff { @@ -56,4 +56,4 @@ public function callback( $key, $val, $line, $group ) { return true; } // end callback() -} // end class +} // End class. diff --git a/WordPress/Sniffs/Arrays/ArrayDeclarationSniff.php b/WordPress/Sniffs/Arrays/ArrayDeclarationSniff.php index 49c4675033..7e0d6ccad4 100644 --- a/WordPress/Sniffs/Arrays/ArrayDeclarationSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayDeclarationSniff.php @@ -1,12 +1,10 @@ - * @author Greg Sherwood - * @author Marc McIntyre + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ if ( ! class_exists( 'Squiz_Sniffs_Arrays_ArrayDeclarationSniff', true ) ) { @@ -14,18 +12,40 @@ } /** - * Enforces WordPress array format. + * Enforces WordPress array format, based upon Squiz code. + * + * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#indentation + * + * @package WPCS\WordPressCodingStandards + * + * @since 0.1.0 + * @since 0.5.0 Now extends `Squiz_Sniffs_Arrays_ArrayDeclarationSniff`. + * + * @todo Check whether the upstream PRs have been merged and released and if possible, + * remove duplicate logic. + * Ref: commit 3ea49d2b56f248d83bed890f9f5246d67c775d54 + * "The upstream version is similar, except that we exclude a few errors. + * Unfortunately we have to actually comment out the code rather than just + * using the upstream sniff and `` in our ruleset, due to a bug + * (squizlabs/PHP_CodeSniffer#582). (I've also included a fix for another + * bug, squizlabs/PHP_CodeSniffer#584.) Because of this, we cannot yet + * eliminate duplicated logic from this child sniff." * - * @category PHP - * @package PHP_CodeSniffer - * @author John Godley - * @author Greg Sherwood - * @author Marc McIntyre + * Last synced with parent class ?[unknown date]? at commit ?[unknown commit]?. + * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php */ class WordPress_Sniffs_Arrays_ArrayDeclarationSniff extends Squiz_Sniffs_Arrays_ArrayDeclarationSniff { /** + * Process a single line array. + * * @since 0.5.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 int $arrayStart Position of the array opener in the token stack. + * @param int $arrayEnd Position of the array closer in the token stack. */ public function processSingleLineArray( PHP_CodeSniffer_File $phpcsFile, $stackPtr, $arrayStart, $arrayEnd ) { @@ -85,7 +105,15 @@ public function processSingleLineArray( PHP_CodeSniffer_File $phpcsFile, $stackP } /** + * Process a multi-line array. + * * @since 0.5.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 int $arrayStart Position of the array opener in the token stack. + * @param int $arrayEnd Position of the array closer in the token stack. */ public function processMultiLineArray( PHP_CodeSniffer_File $phpcsFile, $stackPtr, $arrayStart, $arrayEnd ) { $tokens = $phpcsFile->getTokens(); @@ -458,9 +486,8 @@ public function processMultiLineArray( PHP_CodeSniffer_File $phpcsFile, $stackPt $nextComma = $i; break; } - } // end for + } // End for. - //if ( $nextComma === false || ( $tokens[ $nextComma ]['line'] !== $valueLine ) ) { if ( false === $nextComma ) { $error = 'Each line in an array declaration must end in a comma'; $fix = $phpcsFile->addFixableError( $error, $index['value'], 'NoComma' ); @@ -496,4 +523,4 @@ public function processMultiLineArray( PHP_CodeSniffer_File $phpcsFile, $stackPt } // end processMultiLineArray() -} // end class +} // End class. diff --git a/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php b/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php index 1950547ed6..c02272f13a 100644 --- a/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php @@ -2,19 +2,20 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Check for proper spacing in array key references. * - * @link http://make.wordpress.org/core/handbook/coding-standards/php/#space-usage + * @link http://make.wordpress.org/core/handbook/coding-standards/php/#space-usage * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @package WPCS\WordPressCodingStandards + * + * @since 0.3.0 + * @since 0.7.0 This sniff now has the ability to fix a number of the issues it flags. */ class WordPress_Sniffs_Arrays_ArrayKeySpacingRestrictionsSniff implements PHP_CodeSniffer_Sniff { @@ -28,7 +29,7 @@ public function register() { T_OPEN_SQUARE_BRACKET, ); - } // end register() + } /** * Processes this test, when one of its tokens is encountered. @@ -85,4 +86,4 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } // end process() -} // end class +} // End class. diff --git a/WordPress/Sniffs/CSRF/NonceVerificationSniff.php b/WordPress/Sniffs/CSRF/NonceVerificationSniff.php index 7bc92b3a3b..2ba0a2d7a9 100644 --- a/WordPress/Sniffs/CSRF/NonceVerificationSniff.php +++ b/WordPress/Sniffs/CSRF/NonceVerificationSniff.php @@ -1,23 +1,20 @@ + * @since 0.5.0 */ class WordPress_Sniffs_CSRF_NonceVerificationSniff extends WordPress_Sniff { @@ -134,4 +131,4 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } // end process() -} // end class +} // End class. diff --git a/WordPress/Sniffs/Classes/ClassOpeningStatementSniff.php b/WordPress/Sniffs/Classes/ClassOpeningStatementSniff.php index 23d432836b..c4b9a4b571 100644 --- a/WordPress/Sniffs/Classes/ClassOpeningStatementSniff.php +++ b/WordPress/Sniffs/Classes/ClassOpeningStatementSniff.php @@ -2,24 +2,27 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * WordPress_Classes_ClassOpeningStatementSniff. - * * Checks that the opening brace of a class or interface is on the same line * as the class declaration. * * Also checks that the brace is the last thing on that line and has precisely one space before it. * - * Loosely based on Generic_Sniffs_Functions_OpeningFunctionBraceKernighanRitchieSniff. + * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#brace-style + * + * @package WPCS\WordPressCodingStandards + * + * @since 0.10.0 * - * @category PHP - * @package PHP_CodeSniffer - * @author Juliette Reinders Folmer + * {@internal Upstream PR https://github.com/squizlabs/PHP_CodeSniffer/pull/1070 has been merged. + * If and when the WPCS minimum PHPCS version would be upped to the version + * that PR is contained in - probably v 2.7.0 -, this sniff and associated unit tests + * can be replaced by the upstream sniff Generic.Classes.OpeningBraceSameLine.}} */ class WordPress_Sniffs_Classes_ClassOpeningStatementSniff implements PHP_CodeSniffer_Sniff { @@ -35,7 +38,7 @@ public function register() { T_TRAIT, ); - } // end register() + } /** * Processes this test, when one of its tokens is encountered. @@ -129,6 +132,6 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } } - } // end process() + } // End process(). -} // end class +} // End class. diff --git a/WordPress/Sniffs/Classes/ValidClassNameSniff.php b/WordPress/Sniffs/Classes/ValidClassNameSniff.php index c5c2bd31f2..90f3dd2094 100644 --- a/WordPress/Sniffs/Classes/ValidClassNameSniff.php +++ b/WordPress/Sniffs/Classes/ValidClassNameSniff.php @@ -1,30 +1,23 @@ - * @author Marc McIntyre - * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) - * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence - * @version CVS: $Id: ValidClassNameSniff.php,v 1.6 2008/05/19 05:59:25 squiz Exp $ - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * Squiz_Sniffs_Classes_ValidClassNameSniff. + * Ensures classes are in camel caps, and the first letter is capitalised. * - * Ensures classes are in camel caps, and the first letter is capitalised + * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#naming-conventions * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) - * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence - * @version Release: 1.2.0RC1 - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * + * @since 0.1.0 + * + * Last synced with base class ?[unknown date]? at commit ?[unknown commit]?. + * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/Classes/ValidClassNameSniff.php */ class WordPress_Sniffs_Classes_ValidClassNameSniff implements PHP_CodeSniffer_Sniff { @@ -39,7 +32,7 @@ public function register() { T_INTERFACE, ); - } // end register() + } /** * Processes this test, when one of its tokens is encountered. @@ -79,4 +72,4 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } // end process() -} // end class +} // End class. diff --git a/WordPress/Sniffs/DB/RestrictedClassesSniff.php b/WordPress/Sniffs/DB/RestrictedClassesSniff.php index f036014a2c..e9bdbc762a 100644 --- a/WordPress/Sniffs/DB/RestrictedClassesSniff.php +++ b/WordPress/Sniffs/DB/RestrictedClassesSniff.php @@ -2,9 +2,9 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** @@ -15,11 +15,11 @@ * helps keep your code forward-compatible and, in cases where results are cached in memory, * it can be many times faster." * - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#database-queries + * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#database-queries * - * @category PHP - * @package PHP_CodeSniffer - * @author Juliette Reinders Folmer + * @package WPCS\WordPressCodingStandards + * + * @since 0.10.0 */ class WordPress_Sniffs_DB_RestrictedClassesSniff extends WordPress_AbstractClassRestrictionsSniff { @@ -52,4 +52,4 @@ public function getGroups() { ); } -} // end class +} // End class. diff --git a/WordPress/Sniffs/DB/RestrictedFunctionsSniff.php b/WordPress/Sniffs/DB/RestrictedFunctionsSniff.php index 8fb9735aa2..17a65ea723 100644 --- a/WordPress/Sniffs/DB/RestrictedFunctionsSniff.php +++ b/WordPress/Sniffs/DB/RestrictedFunctionsSniff.php @@ -2,9 +2,9 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** @@ -15,11 +15,11 @@ * helps keep your code forward-compatible and, in cases where results are cached in memory, * it can be many times faster." * - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#database-queries + * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#database-queries * - * @category PHP - * @package PHP_CodeSniffer - * @author Juliette Reinders Folmer + * @package WPCS\WordPressCodingStandards + * + * @since 0.10.0 */ class WordPress_Sniffs_DB_RestrictedFunctionsSniff extends WordPress_AbstractFunctionRestrictionsSniff { @@ -59,4 +59,4 @@ public function getGroups() { ); } -} // end class +} // End class. diff --git a/WordPress/Sniffs/Files/FileNameSniff.php b/WordPress/Sniffs/Files/FileNameSniff.php index 4e24b72b8a..8c7887df97 100644 --- a/WordPress/Sniffs/Files/FileNameSniff.php +++ b/WordPress/Sniffs/Files/FileNameSniff.php @@ -2,19 +2,19 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * WordPress_Sniffs_Files_FileNameSniff. - * * Ensures filenames do not contain underscores. * - * @category PHP - * @package PHP_CodeSniffer - * @author John Godley + * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#naming-conventions + * + * @package WPCS\WordPressCodingStandards + * + * @since 0.1.0 */ class WordPress_Sniffs_Files_FileNameSniff implements PHP_CodeSniffer_Sniff { @@ -26,7 +26,7 @@ class WordPress_Sniffs_Files_FileNameSniff implements PHP_CodeSniffer_Sniff { public function register() { return array( T_OPEN_TAG ); - } // end register() + } /** * Processes this test, when one of its tokens is encountered. @@ -51,4 +51,4 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } // end process() -} // end class +} // End class. diff --git a/WordPress/Sniffs/Functions/DontExtractSniff.php b/WordPress/Sniffs/Functions/DontExtractSniff.php index 86bdd044ad..0c91e4587a 100644 --- a/WordPress/Sniffs/Functions/DontExtractSniff.php +++ b/WordPress/Sniffs/Functions/DontExtractSniff.php @@ -2,19 +2,19 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Restricts the usage of extract(). * - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#dont-extract + * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#dont-extract * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @package WPCS\WordPressCodingStandards + * + * @since 0.10.0 Previously this check was contained within WordPress_Sniffs_VIP_RestrictedFunctionsSniff. */ class WordPress_Sniffs_Functions_DontExtractSniff extends WordPress_AbstractFunctionRestrictionsSniff { @@ -45,4 +45,4 @@ public function getGroups() { ); } // end getGroups() -} // end class +} // End class. diff --git a/WordPress/Sniffs/Functions/FunctionRestrictionsSniff.php b/WordPress/Sniffs/Functions/FunctionRestrictionsSniff.php index eeae1eddb0..f32bfe9234 100644 --- a/WordPress/Sniffs/Functions/FunctionRestrictionsSniff.php +++ b/WordPress/Sniffs/Functions/FunctionRestrictionsSniff.php @@ -2,23 +2,23 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Restricts usage of some functions. * - * @deprecated 0.1.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. + * @package WPCS\WordPressCodingStandards * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @since 0.3.0 + * @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 */ class WordPress_Sniffs_Functions_FunctionRestrictionsSniff extends WordPress_AbstractFunctionRestrictionsSniff { @@ -39,4 +39,4 @@ public function getGroups() { return array(); } -} // end class +} // End class. diff --git a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php index ee98295cab..f339ffc183 100644 --- a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -1,10 +1,10 @@ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ if ( ! class_exists( 'PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff', true ) ) { @@ -14,14 +14,14 @@ /** * Enforces WordPress function name and method name format, based upon Squiz code. * - * @link https://make.wordpress.org/core/handbook/coding-standards/php/#naming-conventions + * @link https://make.wordpress.org/core/handbook/coding-standards/php/#naming-conventions * - * Last synced with parent class July 2016 at commit 916b09a. - * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/NamingConventions/ValidFunctionNameSniff.php + * @package WPCS\WordPressCodingStandards * - * @category PHP - * @package PHP_CodeSniffer - * @author John Godley + * @since 0.1.0 + * + * 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 */ class WordPress_Sniffs_NamingConventions_ValidFunctionNameSniff extends PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff { @@ -173,9 +173,11 @@ protected function processTokenWithinScope( PHP_CodeSniffer_File $phpcsFile, $st } // end processTokenWithinScope() /** - * Returns the name of the class that the specified class implements. + * Returns the name of the interface that the specified class implements. + * + * Returns FALSE on error or if there is no implemented interface name. * - * Returns FALSE on error or if there is no implemented class name. + * @since 0.5.0 * * @param int $stackPtr The stack position of the class. * @param PHP_CodeSniffer_File $phpcsFile The stack position of the class. @@ -218,4 +220,4 @@ public function findImplementedInterfaceName( $stackPtr, $phpcsFile ) { return $name; } // end findExtendedClassName() -} // end class +} // End class. diff --git a/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php index c322c3dabe..af90f1c95d 100644 --- a/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php @@ -2,9 +2,9 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** @@ -15,11 +15,11 @@ * * Hook names invoked with `do_action_deprecated()` and `apply_filters_deprecated()` are ignored. * - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#naming-conventions + * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#naming-conventions * - * @category PHP - * @package PHP_CodeSniffer - * @author Juliette Reinders Folmer + * @package WPCS\WordPressCodingStandards + * + * @since 0.10.0 */ class WordPress_Sniffs_NamingConventions_ValidHookNameSniff implements PHP_CodeSniffer_Sniff { @@ -69,7 +69,7 @@ public function register() { T_STRING, ); - } // end register() + } /** * Processes this test, when one of its tokens is encountered. @@ -281,4 +281,4 @@ protected function transform_complex_string( $string, $regex, $transform_type = return implode( '', $output ); } // end transform_complex_string() -} // end class +} // End class. diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index 655fbd8bee..7dae7edcfb 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -1,18 +1,10 @@ - * @author Marc McIntyre - * @author Weston Ruter - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ if ( ! class_exists( 'PHP_CodeSniffer_Standards_AbstractVariableSniff', true ) ) { @@ -20,19 +12,16 @@ } /** - * WordPress_Sniffs_NamingConventions_ValidVariableNameSniff. - * * Checks the naming of variables and member variables. * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @author Weston Ruter - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#naming-conventions + * + * @package WPCS\WordPressCodingStandards + * + * @since 0.9.0 + * + * 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 { @@ -241,6 +230,6 @@ protected function processVariableInString( PHP_CodeSniffer_File $phpcs_file, $s */ static function isSnakeCase( $var_name ) { return (bool) preg_match( '/^[a-z0-9_]+$/', $var_name ); - } // end isSnakeCase() + } -} // end class +} // End class. diff --git a/WordPress/Sniffs/PHP/DisallowAlternativePHPTagsSniff.php b/WordPress/Sniffs/PHP/DisallowAlternativePHPTagsSniff.php index e2690c16b6..b73e7d31ef 100644 --- a/WordPress/Sniffs/PHP/DisallowAlternativePHPTagsSniff.php +++ b/WordPress/Sniffs/PHP/DisallowAlternativePHPTagsSniff.php @@ -2,9 +2,9 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP\CodeSniffer\WordPress-Coding-Standards - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** @@ -12,11 +12,16 @@ * * If alternative PHP open tags are found, this sniff can fix both the open and close tags. * - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/580 + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/580 * - * @category PHP - * @package PHP\CodeSniffer\WordPress-Coding-Standards - * @author Juliette Reinders Folmer + * @package WPCS\WordPressCodingStandards + * + * @since 0.10.0 + * + * {@internal If and when the upstream PR https://github.com/squizlabs/PHP_CodeSniffer/pull/1084 + * would be merged and the WPCS minimum PHPCS version would be upped to the version + * that PR is contained in, this sniff and associated unit tests can be replaced by + * the upstream sniff Generic.PHP.DisallowAlternativePHPTags.}} */ class WordPress_Sniffs_PHP_DisallowAlternativePHPTagsSniff implements PHP_CodeSniffer_Sniff { @@ -200,7 +205,7 @@ private function find_closing_tag( PHP_CodeSniffer_File $phpcsFile, $tokens, $st * @param int $close_tag_pointer Stack pointer to the PHP close tag. * @param bool $echo Whether to add 'echo' or not. */ - private function add_changeset( $phpcsFile, $tokens, $open_tag_pointer, $close_tag_pointer, $echo = false ) { + private function add_changeset( PHP_CodeSniffer_File $phpcsFile, $tokens, $open_tag_pointer, $close_tag_pointer, $echo = false ) { // Build up the open tag replacement and make sure there's always whitespace behind it. $open_replacement = ' + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ if ( ! class_exists( 'Generic_Sniffs_PHP_ForbiddenFunctionsSniff', true ) ) { @@ -12,13 +12,13 @@ } /** - * WordPress_Sniffs_PHP_DiscouragedFunctionsSniff. + * Discourages the use of various functions and suggests (WordPress) alternatives. * - * Discourages the use of debug functions and suggests deprecated WordPress alternatives + * @package WPCS\WordPressCodingStandards * - * @category PHP - * @package PHP_CodeSniffer - * @author John Godley + * @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. */ class WordPress_Sniffs_PHP_DiscouragedFunctionsSniff extends Generic_Sniffs_PHP_ForbiddenFunctionsSniff { @@ -88,4 +88,4 @@ public function register() { return $register; } -} // end class +} // End class. diff --git a/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php b/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php index 2ab56a9a99..8a78541c70 100644 --- a/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php @@ -2,21 +2,22 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Perl compatible regular expressions (PCRE, preg_ functions) should be used in preference * to their POSIX counterparts. * - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#regular-expressions - * @link http://php.net/manual/en/ref.regex.php + * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#regular-expressions + * @link http://php.net/manual/en/ref.regex.php * - * @category PHP - * @package PHP_CodeSniffer - * @author Juliette Reinders Folmer + * @package WPCS\WordPressCodingStandards + * + * @since 0.10.0 Previously this check was contained within WordPress_Sniffs_VIP_RestrictedFunctionsSniff + * and the WordPress_Sniffs_PHP_DiscouragedFunctionsSniff. */ class WordPress_Sniffs_PHP_POSIXFunctionsSniff extends WordPress_AbstractFunctionRestrictionsSniff { @@ -66,4 +67,4 @@ public function getGroups() { ); } // end getGroups() -} // end class +} // End class. diff --git a/WordPress/Sniffs/PHP/StrictComparisonsSniff.php b/WordPress/Sniffs/PHP/StrictComparisonsSniff.php index 1f42761541..0386e801f0 100644 --- a/WordPress/Sniffs/PHP/StrictComparisonsSniff.php +++ b/WordPress/Sniffs/PHP/StrictComparisonsSniff.php @@ -2,17 +2,22 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Enforces Strict Comparison checks, based upon Squiz code. * - * @category PHP - * @package PHP_CodeSniffer - * @author Matt Robinson + * @package WPCS\WordPressCodingStandards + * + * @since 0.4.0 + * + * 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 { @@ -27,7 +32,7 @@ public function register() { T_IS_NOT_EQUAL, ); - } // end register() + } /** * Processes this test, when one of its tokens is encountered. @@ -46,6 +51,6 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { $phpcsFile->addWarning( $error, $stackPtr, 'LooseComparison' ); } - } // end process() + } -} // end class +} // End class. diff --git a/WordPress/Sniffs/PHP/StrictInArraySniff.php b/WordPress/Sniffs/PHP/StrictInArraySniff.php index bda11b7932..2ef72fb9ad 100644 --- a/WordPress/Sniffs/PHP/StrictInArraySniff.php +++ b/WordPress/Sniffs/PHP/StrictInArraySniff.php @@ -2,18 +2,22 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Flag calling in_array(), array_search() and array_keys() without true as the third parameter. * - * @link https://vip.wordpress.com/documentation/code-review-what-we-look-for/#using-in_array-without-strict-parameter + * @link https://vip.wordpress.com/documentation/code-review-what-we-look-for/#using-in_array-without-strict-parameter * - * @category PHP - * @package PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * + * @since 0.9.0 + * @since 0.10.0 This sniff not only checks for `in_array()`, but also `array_search()` and `array_keys()`. + * The sniff no longer needlessly extends the WordPress_Sniffs_Arrays_ArrayAssignmentRestrictionsSniff + * which it didn't use. */ class WordPress_Sniffs_PHP_StrictInArraySniff implements PHP_CodeSniffer_Sniff { @@ -29,6 +33,8 @@ class WordPress_Sniffs_PHP_StrictInArraySniff implements PHP_CodeSniffer_Sniff { * @link http://php.net/array-search * @link http://php.net/array-keys * + * @since 0.10.0 + * * @var array => */ protected $array_functions = array( @@ -123,4 +129,4 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } } // end process() -} // end class +} // End class. diff --git a/WordPress/Sniffs/PHP/YodaConditionsSniff.php b/WordPress/Sniffs/PHP/YodaConditionsSniff.php index 02e2bc0f70..f7ba541aad 100644 --- a/WordPress/Sniffs/PHP/YodaConditionsSniff.php +++ b/WordPress/Sniffs/PHP/YodaConditionsSniff.php @@ -1,20 +1,20 @@ - * @author Greg Sherwood - * @author Marc McIntyre + * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#yoda-conditions + * + * @package WPCS\WordPressCodingStandards + * + * @since 0.3.0 */ class WordPress_Sniffs_PHP_YodaConditionsSniff implements PHP_CodeSniffer_Sniff { @@ -31,7 +31,7 @@ public function register() { T_IS_NOT_IDENTICAL, ); - } // end register() + } /** * Processes this test, when one of its tokens is encountered. @@ -102,4 +102,4 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } // end process() -} // end class +} // End class. diff --git a/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php b/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php index a9b1fbd4bd..f2a7083983 100644 --- a/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php +++ b/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php @@ -2,17 +2,19 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Discourages removal of the admin bar. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#removing-the-admin-bar + * + * @package WPCS\WordPressCodingStandards + * + * @since 0.3.0 */ class WordPress_Sniffs_VIP_AdminBarRemovalSniff implements PHP_CodeSniffer_Sniff { @@ -28,7 +30,7 @@ public function register() { T_DOUBLE_QUOTED_STRING, ); - } // end register() + } /** * Processes this test, when one of its tokens is encountered. @@ -47,4 +49,4 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } } // end process() -} // end class +} // End class. diff --git a/WordPress/Sniffs/VIP/CronIntervalSniff.php b/WordPress/Sniffs/VIP/CronIntervalSniff.php index 036ef5b0a7..6cec70acf7 100644 --- a/WordPress/Sniffs/VIP/CronIntervalSniff.php +++ b/WordPress/Sniffs/VIP/CronIntervalSniff.php @@ -2,17 +2,19 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Flag cron schedules less than 15 minutes. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#cron-schedules-less-than-15-minutes-or-expensive-events + * + * @package WPCS\WordPressCodingStandards + * + * @since 0.3.0 */ class WordPress_Sniffs_VIP_CronIntervalSniff implements PHP_CodeSniffer_Sniff { @@ -27,7 +29,7 @@ public function register() { T_DOUBLE_QUOTED_STRING, ); - } // end register() + } /** * Processes this test, when one of its tokens is encountered. @@ -129,8 +131,19 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } // end process() - public function confused( $phpcsFile, $stackPtr ) { - $phpcsFile->addWarning( 'Detected changing of cron_schedules, but could not detect the interval value.', $stackPtr, 'ChangeDetected' ); - } // end confused() + /** + * Add warning about unclear cron schedule change. + * + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. + */ + public function confused( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { + $phpcsFile->addWarning( + 'Detected changing of cron_schedules, but could not detect the interval value.', + $stackPtr, + 'ChangeDetected' + ); + } -} // end class +} // End class. diff --git a/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php b/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php index bd19a84368..73a4c0d860 100644 --- a/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php +++ b/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php @@ -2,19 +2,21 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Flag Database direct queries. * - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/69 + * @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#direct-database-queries + * @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#database-alteration * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @package WPCS\WordPressCodingStandards + * + * @since 0.3.0 + * @since 0.6.0 Removed the add_unique_message() function as it is no longer needed. */ class WordPress_Sniffs_VIP_DirectDatabaseQuerySniff implements PHP_CodeSniffer_Sniff { @@ -78,7 +80,7 @@ public function register() { T_VARIABLE, ); - } // end register() + } /** * Processes this test, when one of its tokens is encountered. @@ -210,4 +212,4 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } // end process() -} // end class +} // End class. diff --git a/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php b/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php index ba53a7429d..674a077793 100644 --- a/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php +++ b/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php @@ -2,9 +2,9 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ if ( ! class_exists( 'Generic_Sniffs_PHP_ForbiddenFunctionsSniff', true ) ) { @@ -14,11 +14,11 @@ /** * Disallow Filesystem writes. * - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/69 + * @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#filesystem-writes * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @package WPCS\WordPressCodingStandards + * + * @since 0.3.0 */ class WordPress_Sniffs_VIP_FileSystemWritesDisallowSniff extends Generic_Sniffs_PHP_ForbiddenFunctionsSniff { @@ -68,6 +68,8 @@ class WordPress_Sniffs_VIP_FileSystemWritesDisallowSniff extends Generic_Sniffs_ /** * Generates the error or warning for this sniff. * + * Overloads parent addError method. + * * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. * @param int $stackPtr The position of the forbidden function * in the token array. @@ -86,6 +88,6 @@ protected function addError( $phpcsFile, $stackPtr, $function, $pattern = null ) $phpcsFile->addWarning( $error, $stackPtr, 'FileWriteDetected', $data ); } - } // end addError() + } -} // end class +} // End class. diff --git a/WordPress/Sniffs/VIP/OrderByRandSniff.php b/WordPress/Sniffs/VIP/OrderByRandSniff.php index 9e05d9aae1..158a11312c 100644 --- a/WordPress/Sniffs/VIP/OrderByRandSniff.php +++ b/WordPress/Sniffs/VIP/OrderByRandSniff.php @@ -2,18 +2,19 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Flag using orderby => rand. * - * @link https://vip.wordpress.com/documentation/code-review-what-we-look-for/#order-by-rand + * @link https://vip.wordpress.com/documentation/code-review-what-we-look-for/#order-by-rand * - * @category PHP - * @package PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * + * @since 0.9.0 */ class WordPress_Sniffs_VIP_OrderByRandSniff extends WordPress_AbstractArrayAssignmentRestrictionsSniff { @@ -49,6 +50,6 @@ public function callback( $key, $val, $line, $group ) { } else { return false; } - } // end callback() + } -} // end class +} // End class. diff --git a/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php b/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php index 4a6ea1ba27..807cf2c24b 100644 --- a/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php +++ b/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php @@ -2,20 +2,27 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Warn about __FILE__ for page registration. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#using-__file__-for-page-registration + * + * @package WPCS\WordPressCodingStandards + * + * @since 0.3.0 */ class WordPress_Sniffs_VIP_PluginMenuSlugSniff implements PHP_CodeSniffer_Sniff { + /** + * Functions which can be used to add pages to the WP Admin menu. + * + * @var array + */ public $add_menu_functions = array( 'add_menu_page', 'add_object_page', @@ -44,7 +51,7 @@ public function register() { T_STRING, ); - } // end register() + } /** * Processes this test, when one of its tokens is encountered. @@ -72,6 +79,6 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { $phpcsFile->addError( 'Using __FILE__ for menu slugs risks exposing filesystem structure.', $stackPtr, 'Using__FILE__' ); } - } // end process() + } -} // end class +} // End class. diff --git a/WordPress/Sniffs/VIP/PostsPerPageSniff.php b/WordPress/Sniffs/VIP/PostsPerPageSniff.php index 23d456cb6a..fbc22a5a36 100644 --- a/WordPress/Sniffs/VIP/PostsPerPageSniff.php +++ b/WordPress/Sniffs/VIP/PostsPerPageSniff.php @@ -2,17 +2,19 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Flag returning high or infinite posts_per_page. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#no-limit-queries + * + * @package WPCS\WordPressCodingStandards + * + * @since 0.3.0 */ class WordPress_Sniffs_VIP_PostsPerPageSniff extends WordPress_AbstractArrayAssignmentRestrictionsSniff { @@ -72,6 +74,6 @@ public function callback( $key, $val, $line, $group ) { return 'Detected high pagination limit, `%s` is set to `%s`'; } } - } // end callback() + } -} // end class +} // End class. diff --git a/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php b/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php index 50ccb710ec..9cbfd3c4a7 100644 --- a/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php +++ b/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php @@ -2,17 +2,20 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Restricts usage of some functions in VIP context. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @package WPCS\WordPressCodingStandards + * + * @since 0.3.0 + * @since 0.10.0 The checks for `extract()` and the POSIX functions have been replaced by + * the stand-alone sniffs WordPress_Sniffs_Functions_DontExtractSniff and + * WordPress_Sniffs_PHP_POSIXFunctionsSniff respectively. */ class WordPress_Sniffs_VIP_RestrictedFunctionsSniff extends WordPress_AbstractFunctionRestrictionsSniff { @@ -31,13 +34,14 @@ class WordPress_Sniffs_VIP_RestrictedFunctionsSniff extends WordPress_AbstractFu */ public function getGroups() { return array( - + // @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#switch_to_blog 'switch_to_blog' => array( 'type' => 'error', 'message' => '%s is not something you should ever need to do in a VIP theme context. Instead use an API (XML-RPC, REST) to interact with other sites if needed.', 'functions' => array( 'switch_to_blog' ), ), + // @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#eval-and-create_function 'create_function' => array( 'type' => 'warning', 'message' => '%s is discouraged, please use Anonymous functions instead.', @@ -46,6 +50,7 @@ public function getGroups() { ), ), + // @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#eval-and-create_function 'eval' => array( 'type' => 'error', 'message' => '%s is prohibited, please use Anonymous functions instead.', @@ -123,6 +128,7 @@ public function getGroups() { ), ), + // @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#remote-calls 'wp_remote_get' => array( 'type' => 'warning', 'message' => '%s is highly discouraged, please use vip_safe_wp_remote_get() instead.', @@ -131,6 +137,7 @@ public function getGroups() { ), ), + // @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#remote-calls 'curl' => array( 'type' => 'warning', 'message' => 'Using cURL functions is highly discouraged within VIP context. Check (Fetching Remote Data) on VIP Documentation.', @@ -139,6 +146,7 @@ public function getGroups() { ), ), + // @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#custom-roles 'custom_role' => array( 'type' => 'error', 'message' => 'Use wpcom_vip_add_role() instead of add_role()', @@ -147,6 +155,7 @@ public function getGroups() { ), ), + // @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#caching-constraints 'cookies' => array( 'type' => 'warning', 'message' => 'Due to using Batcache, server side based client related logic will not work, use JS instead.', @@ -155,6 +164,7 @@ public function getGroups() { ), ), + // @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#working-with-wp_users-and-user_meta 'user_meta' => array( 'type' => 'error', 'message' => '%s() usage is highly discouraged, check VIP documentation on "Working with wp_users"', @@ -224,6 +234,7 @@ public function getGroups() { ), ), + // @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#use-wp_parse_url-instead-of-parse_url 'parse_url' => array( 'type' => 'warning', 'message' => '%s is discouraged due to a lack for backwards-compatibility in PHP versions; please use wp_parse_url() instead.', @@ -240,6 +251,7 @@ public function getGroups() { ), ), + // @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#serializing-data 'serialize' => array( 'type' => 'warning', 'message' => '%s Serialized data has known vulnerability problems with Object Injection. JSON is generally a better approach for serializing data.', @@ -249,6 +261,7 @@ public function getGroups() { ), ), + // @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#commented-out-code-debug-code-or-output 'error_log' => array( 'type' => 'error', 'message' => '%s Debug code is not allowed on VIP Production', @@ -261,6 +274,7 @@ public function getGroups() { ), ), + // @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#use-wp_safe_redirect-instead-of-wp_redirect 'wp_redirect' => array( 'type' => 'warning', 'message' => '%s Using wp_safe_redirect(), along with the allowed_redirect_hosts filter, can help avoid any chances of malicious redirects within code. It’s also important to remember to call exit() after a redirect so that no other unwanted code is executed.', @@ -269,6 +283,7 @@ public function getGroups() { ), ), + // @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#mobile-detection 'wp_is_mobile' => array( 'type' => 'error', 'message' => '%s When targeting mobile visitors, jetpack_is_mobile() should be used instead of wp_is_mobile. It is more robust and works better with full page caching.', @@ -277,14 +292,16 @@ public function getGroups() { ), ), + // @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#encoding-values-used-when-creating-a-url-or-passed-to-add_query_arg 'urlencode' => array( 'type' => 'warning', - 'message' => '%s urlencode should only be used when dealing with legacy applications rawurlencode should now de used instead. See http://php.net/manual/en/function.rawurlencode.php and http://www.faqs.org/rfcs/rfc3986.html', + 'message' => '%s urlencode should only be used when dealing with legacy applications rawurlencode should now be used instead. See http://php.net/manual/en/function.rawurlencode.php and http://www.faqs.org/rfcs/rfc3986.html', 'functions' => array( 'rawurlencode', ), ), + // @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#settings-alteration 'runtime_configuration' => array( 'type' => 'error', 'message' => '%s is prohibited, changing configuration at runtime is not allowed on VIP Production.', @@ -315,4 +332,4 @@ public function getGroups() { ); } // end getGroups() -} // end class +} // End class. diff --git a/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php b/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php index cd3a48c059..51822b4d17 100644 --- a/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php +++ b/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php @@ -2,17 +2,19 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Restricts usage of some variables in VIP context. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/ + * + * @package WPCS\WordPressCodingStandards + * + * @since 0.3.0 */ class WordPress_Sniffs_VIP_RestrictedVariablesSniff extends WordPress_AbstractVariableRestrictionsSniff { @@ -33,6 +35,7 @@ class WordPress_Sniffs_VIP_RestrictedVariablesSniff extends WordPress_AbstractVa */ public function getGroups() { return array( + // @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#working-with-wp_users-and-user_meta 'user_meta' => array( 'type' => 'error', 'message' => 'Usage of users/usermeta tables is highly discouraged in VIP context, For storing user additional user metadata, you should look at User Attributes.', @@ -41,6 +44,8 @@ public function getGroups() { '$wpdb->usermeta', ), ), + + // @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#caching-constraints 'cache_constraints' => array( 'type' => 'warning', 'message' => 'Due to using Batcache, server side based client related logic will not work, use JS instead.', @@ -53,6 +58,6 @@ public function getGroups() { ), ), ); - } // end getGroups() + } -} // end class +} // End class. diff --git a/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php b/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php index 7901677144..b3d9510aaf 100644 --- a/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php +++ b/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php @@ -2,9 +2,9 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ if ( ! class_exists( 'Generic_Sniffs_PHP_ForbiddenFunctionsSniff', true ) ) { @@ -12,15 +12,13 @@ } /** - * WordPress_Sniffs_VIP_SessionFunctionsUsageSniff. - * * Discourages the use of session functions. * - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/75 + * @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#session_start-and-other-session-related-functions + * + * @package WPCS\WordPressCodingStandards * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @since 0.3.0 */ class WordPress_Sniffs_VIP_SessionFunctionsUsageSniff extends Generic_Sniffs_PHP_ForbiddenFunctionsSniff { @@ -57,12 +55,24 @@ class WordPress_Sniffs_VIP_SessionFunctionsUsageSniff extends Generic_Sniffs_PHP 'session_write_close' => null, ); + /** + * Generates the error or warning for this sniff. + * + * Overloads parent addError method. + * + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the forbidden function + * in the token array. + * @param string $function The name of the forbidden function. + * @param string $pattern The pattern used for the match. + * + * @return void + */ protected function addError( $phpcsFile, $stackPtr, $function, $pattern = null ) { $data = array( $function ); $error = 'The use of PHP session function %s() is prohibited.'; $phpcsFile->addError( $error, $stackPtr, $function, $data ); + } - } // end addError() - -} // end class +} // End class. diff --git a/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php b/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php index 30e968d2b8..1db40d9d69 100644 --- a/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php +++ b/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php @@ -2,22 +2,22 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * WordPress_Sniffs_VIP_SessionVariableUsageSniff - * * Discourages the use of the session variable. * Creating a session writes a file to the server and is unreliable in a multi-server environment. * - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/75 + * @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#session_start-and-other-session-related-functions + * + * @package WPCS\WordPressCodingStandards * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @since 0.3.0 + * @since 0.10.0 The sniff no longer needlessly extends the Generic_Sniffs_PHP_ForbiddenFunctionsSniff + * which it didn't use. */ class WordPress_Sniffs_VIP_SessionVariableUsageSniff implements PHP_CodeSniffer_Sniff { @@ -31,7 +31,7 @@ public function register() { T_VARIABLE, ); - } // end register() + } /** * Processes this test, when one of its tokens is encountered. @@ -51,6 +51,6 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { $phpcsFile->addError( 'Usage of $_SESSION variable is prohibited.', $stackPtr, 'SessionVarsProhibited' ); } - } // end process() + } -} // end class +} // End class. diff --git a/WordPress/Sniffs/VIP/SlowDBQuerySniff.php b/WordPress/Sniffs/VIP/SlowDBQuerySniff.php index 1d7dd024d8..843b2891a2 100644 --- a/WordPress/Sniffs/VIP/SlowDBQuerySniff.php +++ b/WordPress/Sniffs/VIP/SlowDBQuerySniff.php @@ -2,17 +2,19 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * Flag slow queries. + * Flag potentially slow queries. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @link https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#uncached-pageload + * + * @package WPCS\WordPressCodingStandards + * + * @since 0.3.0 */ class WordPress_Sniffs_VIP_SlowDBQuerySniff extends WordPress_AbstractArrayAssignmentRestrictionsSniff { @@ -50,6 +52,8 @@ public function getGroups() { /** * Processes this test, when one of its tokens is encountered. * + * @since 0.10.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. @@ -65,7 +69,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } parent::process( $phpcsFile, $stackPtr ); - } // end process() + } /** * Callback to process each confirmed key, to check value. @@ -80,6 +84,6 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { */ public function callback( $key, $val, $line, $group ) { return true; - } // end callback() + } -} // end class +} // End class. diff --git a/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php b/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php index d7b8c76798..b0c75fb045 100644 --- a/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php +++ b/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php @@ -2,19 +2,20 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * Flag any usage of super global input var ( _GET / _POST / etc. ) + * Flag any usage of super global input var ( _GET / _POST / etc. ). * - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/79 + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/79 * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @package WPCS\WordPressCodingStandards + * + * @since 0.3.0 + * @since 0.4.0 This class now extends WordPress_Sniff. */ class WordPress_Sniffs_VIP_SuperGlobalInputUsageSniff extends WordPress_Sniff { @@ -28,7 +29,7 @@ public function register() { T_VARIABLE, ); - } // end register() + } /** * Processes this test, when one of its tokens is encountered. @@ -59,6 +60,6 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { $phpcsFile->addWarning( 'Detected access of super global var %s, probably needs manual inspection.', $stackPtr, 'AccessDetected', array( $varName ) ); } - } // end process() + } -} // end class +} // End class. diff --git a/WordPress/Sniffs/VIP/TimezoneChangeSniff.php b/WordPress/Sniffs/VIP/TimezoneChangeSniff.php index 6e650b52ca..76e486a0e3 100644 --- a/WordPress/Sniffs/VIP/TimezoneChangeSniff.php +++ b/WordPress/Sniffs/VIP/TimezoneChangeSniff.php @@ -2,9 +2,9 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ if ( ! class_exists( 'Generic_Sniffs_PHP_ForbiddenFunctionsSniff', true ) ) { @@ -12,15 +12,13 @@ } /** - * WordPress_Sniffs_VIP_TimezoneChangeSniff. + * Disallow the changing of timezone. * - * Disallow the changing of timezone + * @link http://vip.wordpress.com/documentation/use-current_time-not-date_default_timezone_set/ * - * @link http://vip.wordpress.com/documentation/use-current_time-not-date_default_timezone_set/ + * @package WPCS\WordPressCodingStandards * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @since 0.3.0 */ class WordPress_Sniffs_VIP_TimezoneChangeSniff extends Generic_Sniffs_PHP_ForbiddenFunctionsSniff { @@ -36,10 +34,23 @@ class WordPress_Sniffs_VIP_TimezoneChangeSniff extends Generic_Sniffs_PHP_Forbid 'date_default_timezone_set' => null, ); + /** + * Generates the error or warning for this sniff. + * + * Overloads parent addError method. + * + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the forbidden function + * in the token array. + * @param string $function The name of the forbidden function. + * @param string $pattern The pattern used for the match. + * + * @return void + */ protected function addError( $phpcsFile, $stackPtr, $function, $pattern = null ) { - $error = 'Using date_default_timezone_set() and similar isn’t allowed, instead use WP internal timezone support.'; + $error = 'Using date_default_timezone_set() and similar isn\'t allowed, instead use WP internal timezone support.'; $phpcsFile->addError( $error, $stackPtr, $function ); - } // end addError() + } -} // end class +} // End class. diff --git a/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php b/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php index bc62c72459..f6c0853475 100644 --- a/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php +++ b/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php @@ -2,19 +2,21 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * Flag any non-validated/sanitized input ( _GET / _POST / etc. ) + * Flag any non-validated/sanitized input ( _GET / _POST / etc. ). * - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/69 + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/69 * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @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. */ class WordPress_Sniffs_VIP_ValidatedSanitizedInputSniff extends WordPress_Sniff { @@ -150,8 +152,6 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { $phpcsFile->addError( 'Detected usage of a non-sanitized input variable: %s', $stackPtr, 'InputNotSanitized', $error_data ); } - return; - } // end process() -} // end class +} // End class. diff --git a/WordPress/Sniffs/Variables/GlobalVariablesSniff.php b/WordPress/Sniffs/Variables/GlobalVariablesSniff.php index 16f8a51e2a..c243b7e0d8 100644 --- a/WordPress/Sniffs/Variables/GlobalVariablesSniff.php +++ b/WordPress/Sniffs/Variables/GlobalVariablesSniff.php @@ -2,9 +2,9 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** @@ -12,12 +12,18 @@ * * Warns about usage of global variables used by WordPress * - * @category PHP - * @package WordPress_Coding_Standards - * @author Shady Sharaf + * @package WPCS\WordPressCodingStandards + * + * @since 0.3.0 + * @since 0.4.0 This class now extends WordPress_Sniff. */ class WordPress_Sniffs_Variables_GlobalVariablesSniff extends WordPress_Sniff { + /** + * List of global WP variables. + * + * @var array + */ public $globals = array( 'comment', 'comment_alt', @@ -345,4 +351,4 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } } // end process() -} // end class +} // End class. diff --git a/WordPress/Sniffs/Variables/VariableRestrictionsSniff.php b/WordPress/Sniffs/Variables/VariableRestrictionsSniff.php index 6a2e86950e..7e6b96262b 100644 --- a/WordPress/Sniffs/Variables/VariableRestrictionsSniff.php +++ b/WordPress/Sniffs/Variables/VariableRestrictionsSniff.php @@ -2,24 +2,24 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Restricts usage of some variables. * - * @deprecated 0.1.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. + * @package WPCS\WordPressCodingStandards * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @since 0.3.0 + * @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 */ class WordPress_Sniffs_Variables_VariableRestrictionsSniff extends WordPress_AbstractVariableRestrictionsSniff { @@ -42,4 +42,4 @@ public function getGroups() { return parent::$groups; } -} // end class +} // End class. diff --git a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php index 849693c557..65d5db07fb 100644 --- a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php +++ b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php @@ -2,19 +2,19 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * WordPress_Sniffs_WP_Enqueued_Resources_Sniff - * * Makes sure scripts and styles are enqueued and not explicitly echo'd. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @link https://vip.wordpress.com/documentation/vip-go/code-review-blockers-warnings-notices/#inline-resources + * + * @package WPCS\WordPressCodingStandards + * + * @since 0.3.0 */ class WordPress_Sniffs_WP_EnqueuedResourcesSniff implements PHP_CodeSniffer_Sniff { @@ -30,7 +30,7 @@ public function register() { T_INLINE_HTML, ); - } // end register() + } /** * Processes this test, when one of its tokens is encountered. @@ -55,4 +55,4 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } // end process() -} // end class +} // End class. diff --git a/WordPress/Sniffs/WP/I18nSniff.php b/WordPress/Sniffs/WP/I18nSniff.php index 1b7ea37c4e..815edb95cd 100644 --- a/WordPress/Sniffs/WP/I18nSniff.php +++ b/WordPress/Sniffs/WP/I18nSniff.php @@ -2,19 +2,20 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * WordPress_Sniffs_WP_I18nSniff + * Makes sure WP internationalization functions are used properly. * - * Makes sure internationalization functions are used properly. + * @link https://make.wordpress.org/core/handbook/best-practices/internationalization/ + * @link https://developer.wordpress.org/plugins/internationalization/ * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @package WPCS\WordPressCodingStandards + * + * @since 0.10.0 */ class WordPress_Sniffs_WP_I18nSniff extends WordPress_Sniff { @@ -37,6 +38,11 @@ class WordPress_Sniffs_WP_I18nSniff extends WordPress_Sniff { */ static $text_domain_override; + /** + * The I18N functions in use in WP. + * + * @var array => + */ public $i18n_functions = array( 'translate' => 'simple', '__' => 'simple', @@ -58,13 +64,17 @@ class WordPress_Sniffs_WP_I18nSniff extends WordPress_Sniff { /** * These Regexes copied from http://php.net/manual/en/function.sprintf.php#93552 + * + * @var string */ - static $sprintf_placeholder_regex = '/(?:%%|(%(?:[0-9]+\$)?[+-]?(?:[ 0]|\'.)?-?[0-9]*(?:\.[0-9]+)?[bcdeufFos]))/'; + public static $sprintf_placeholder_regex = '/(?:%%|(%(?:[0-9]+\$)?[+-]?(?:[ 0]|\'.)?-?[0-9]*(?:\.[0-9]+)?[bcdeufFos]))/'; /** * "Unordered" means there's no position specifier: '%s', not '%2$s'. + * + * @var string */ - static $unordered_sprintf_placeholder_regex = '/(?:%%|(?:%[+-]?(?:[ 0]|\'.)?-?[0-9]*(?:\.[0-9]+)?[bcdeufFosxX]))/'; + public static $unordered_sprintf_placeholder_regex = '/(?:%%|(?:%[+-]?(?:[ 0]|\'.)?-?[0-9]*(?:\.[0-9]+)?[bcdeufFosxX]))/'; /** * Returns an array of tokens this test wants to listen for. @@ -82,7 +92,7 @@ public function register() { * * @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. + * in the stack passed in $tokens. * * @return void */ @@ -211,7 +221,7 @@ public function process( PHP_CodeSniffer_File $phpcs_file, $stack_ptr ) { * Check if supplied tokens represent a translation text string literal. * * @param PHP_CodeSniffer_File $phpcs_file The file being scanned. - * @param array $context + * @param array $context Context (@todo needs better description). * @return bool */ protected function check_argument_tokens( PHP_CodeSniffer_File $phpcs_file, $context ) { @@ -274,8 +284,10 @@ protected function check_argument_tokens( PHP_CodeSniffer_File $phpcs_file, $con * Check for inconsistencies between single and plural arguments. * * @param PHP_CodeSniffer_File $phpcs_file The file being scanned. - * @param array $single_context - * @param array $plural_context + * @param int $stack_ptr The position of the current token + * in the stack passed in $tokens. + * @param array $single_context Single context (@todo needs better description). + * @param array $plural_context Plural context (@todo needs better description). * @return void */ protected function compare_single_and_plural_arguments( PHP_CodeSniffer_File $phpcs_file, $stack_ptr, $single_context, $plural_context ) { @@ -289,7 +301,7 @@ protected function compare_single_and_plural_arguments( PHP_CodeSniffer_File $ph $plural_placeholders = $plural_placeholders[0]; // English conflates "singular" with "only one", described in the codex: - // https://codex.wordpress.org/I18n_for_WordPress_Developers#Plurals + // https://codex.wordpress.org/I18n_for_WordPress_Developers#Plurals . if ( count( $single_placeholders ) < count( $plural_placeholders ) ) { $error_string = 'Missing singular placeholder, needed for some languages. See https://codex.wordpress.org/I18n_for_WordPress_Developers#Plurals'; $single_index = $single_context['tokens'][0]['token_index']; @@ -310,7 +322,7 @@ protected function compare_single_and_plural_arguments( PHP_CodeSniffer_File $ph * Check the string itself for problems. * * @param PHP_CodeSniffer_File $phpcs_file The file being scanned. - * @param array $context + * @param array $context Context (@todo needs better description). * @return void */ protected function check_text( PHP_CodeSniffer_File $phpcs_file, $context ) { @@ -348,9 +360,11 @@ protected function check_text( PHP_CodeSniffer_File $phpcs_file, $context ) { } } - // NoEmptyStrings. - - // Strip placeholders and surrounding quotes. + /* + * NoEmptyStrings. + * + * Strip placeholders and surrounding quotes. + */ $non_placeholder_content = trim( $content, "'" ); $non_placeholder_content = preg_replace( self::$sprintf_placeholder_regex, '', $non_placeholder_content ); diff --git a/WordPress/Sniffs/WP/PreparedSQLSniff.php b/WordPress/Sniffs/WP/PreparedSQLSniff.php index 1bfcf9793a..3759a93b48 100644 --- a/WordPress/Sniffs/WP/PreparedSQLSniff.php +++ b/WordPress/Sniffs/WP/PreparedSQLSniff.php @@ -2,9 +2,9 @@ /** * WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** @@ -12,8 +12,11 @@ * * Makes sure that variables aren't directly interpolated into SQL statements. * - * @package WordPress-Coding-Standards - * @since 0.8.0 + * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#formatting-sql-statements + * + * @package WPCS\WordPressCodingStandards + * + * @since 0.8.0 */ class WordPress_Sniffs_WP_PreparedSQLSniff extends WordPress_Sniff { @@ -91,12 +94,12 @@ public function register() { /** * Processes this test, when one of its tokens is encountered. * - * @since 0.8.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. * + * @since 0.8.0 + * * @return int|void */ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { @@ -240,4 +243,4 @@ protected function is_wpdb_method_call( $stackPtr ) { return true; } // is_wpdb_method_call() -} // end class. +} // End class. diff --git a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php index 5d623a971c..ab2f91cae9 100755 --- a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php @@ -1,29 +1,23 @@ - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * Squiz_Sniffs_WhiteSpace_CastSpacingSniff. + * Ensure cast statements don't contain whitespace, but *are* surrounded by whitespace, based upon Squiz code. * - * Ensure cast statements don't contain whitespace. + * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#space-usage * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * + * @since 0.3.0 + * + * Last synced with base class ?[unknown date]? at commit ?[unknown commit]?. + * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/CastSpacingSniff.php */ class WordPress_Sniffs_WhiteSpace_CastStructureSpacingSniff implements PHP_CodeSniffer_Sniff { @@ -35,7 +29,7 @@ class WordPress_Sniffs_WhiteSpace_CastStructureSpacingSniff implements PHP_CodeS public function register() { return PHP_CodeSniffer_Tokens::$castTokens; - } // end register() + } /** * Processes this test, when one of its tokens is encountered. @@ -80,4 +74,4 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { */ public $error = false; -} // end class +} // End class. diff --git a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php index 078c30a380..af6cbc56f2 100644 --- a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php @@ -1,24 +1,24 @@ - * @author Greg Sherwood - * @author Marc McIntyre + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * Squiz_Sniffs_WhiteSpace_ControlStructureSpacingSniff. + * Enforces spacing around logical operators and assignments, based upon Squiz code. + * + * @package WPCS\WordPressCodingStandards * - * Checks that any array declarations are lower case. + * @since 0.1.0 + * @since 2013-06-11 This sniff no longer supports JS. + * @since 0.3.0 This sniff now has the ability to fix most errors it flags. + * @since 0.7.0 This class now extends WordPress_Sniff. * - * @category PHP - * @package PHP_CodeSniffer - * @author John Godley - * @author Greg Sherwood - * @author Marc McIntyre + * Last synced with base class ?[unknown date]? at commit ?[unknown commit]?. + * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php */ class WordPress_Sniffs_WhiteSpace_ControlStructureSpacingSniff extends WordPress_Sniff { @@ -53,7 +53,7 @@ class WordPress_Sniffs_WhiteSpace_ControlStructureSpacingSniff extends WordPress /** * How many spaces should be between a T_CLOSURE and T_OPEN_PARENTHESIS. * - * function[*]() {...} + * `function[*]() {...}` * * @since 0.7.0 * @@ -81,7 +81,7 @@ public function register() { T_USE, ); - } // end register() + } /** * Processes this test, when one of its tokens is encountered. @@ -526,4 +526,4 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } // end process() -} // end class +} // End class. diff --git a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php index 89941a5c76..18e3abe038 100644 --- a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php @@ -1,20 +1,26 @@ - * @author Marc McIntyre + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * Modified version of Squiz operator white spacing. + * Verify operator spacing, based upon Squiz code. * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre + * "Always put spaces after commas, and on both sides of logical, comparison, string and assignment operators." + * + * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#space-usage + * + * @package WPCS\WordPressCodingStandards + * + * @since 0.1.0 + * @since 0.3.0 This sniff now has the ability to fix the issues it flags. + * + * Last synced with base class December 2008 at commit f01746fd1c89e98174b16c76efd325825eb58bf1. + * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php */ class WordPress_Sniffs_WhiteSpace_OperatorSpacingSniff implements PHP_CodeSniffer_Sniff { @@ -43,7 +49,7 @@ public function register() { return $tokens; - } // end register() + } /** * Processes this sniff, when one of its tokens is encountered. @@ -76,13 +82,13 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } if ( T_BITWISE_AND === $tokens[ $stackPtr ]['code'] ) { - // If its not a reference, then we expect one space either side of the + /* + // If it's not a reference, then we expect one space either side of the // bitwise operator. - // if ( false === $phpcsFile->isReference( $stackPtr ) ) { - // @todo Implement or remove ? - - // } // end if - + if ( false === $phpcsFile->isReference( $stackPtr ) ) { + // @todo Implement or remove ? + } + */ return; } else { @@ -205,4 +211,4 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } // end process() -} // end class +} // End class. diff --git a/WordPress/Sniffs/XSS/EscapeOutputSniff.php b/WordPress/Sniffs/XSS/EscapeOutputSniff.php index 41c749a8d0..237a9291a8 100644 --- a/WordPress/Sniffs/XSS/EscapeOutputSniff.php +++ b/WordPress/Sniffs/XSS/EscapeOutputSniff.php @@ -1,20 +1,23 @@ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Verifies that all outputted strings are escaped. * - * @link http://codex.wordpress.org/Data_Validation Data Validation on WordPress Codex + * @link http://codex.wordpress.org/Data_Validation Data Validation on WordPress Codex * - * @category PHP - * @package PHP_CodeSniffer - * @author Weston Ruter + * @package WPCS\WordPressCodingStandards + * + * @since 2013-06-11 + * @since 0.4.0 This class now extends WordPress_Sniff. + * @since 0.5.0 The various function list properties which used to be contained in this class + * have been moved to the WordPress_Sniff parent class. */ class WordPress_Sniffs_XSS_EscapeOutputSniff extends WordPress_Sniff { @@ -39,8 +42,9 @@ class WordPress_Sniffs_XSS_EscapeOutputSniff extends WordPress_Sniff { /** * Custom list of functions which escape values for output. * - * @since 0.3.0 + * @since 0.3.0 * @deprecated 0.5.0 Use $customEscapingFunctions instead. + * @see WordPress_Sniffs_XSS_EscapeOutputSniff::$customEscapingFunctions * * @var string[] */ @@ -102,7 +106,7 @@ public function register() { T_STRING, ); - } // end register() + } /** * Processes this test, when one of its tokens is encountered. @@ -347,4 +351,4 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } // end process() -} // end class +} // End class. diff --git a/WordPress/Tests/Arrays/ArrayAssignmentRestrictionsUnitTest.inc b/WordPress/Tests/Arrays/ArrayAssignmentRestrictionsUnitTest.inc index e592293211..7f5d00841e 100644 --- a/WordPress/Tests/Arrays/ArrayAssignmentRestrictionsUnitTest.inc +++ b/WordPress/Tests/Arrays/ArrayAssignmentRestrictionsUnitTest.inc @@ -1,7 +1,7 @@ 1 ); // Bad +$foo = array( 'bar' => 1 ); // Bad. -$foo['bar'] = 1; // Bad +$foo['bar'] = 1; // Bad. -$foo = 'test' . 'bar=1&taz=5&bar=2'; // Bad +$foo = 'test' . 'bar=1&taz=5&bar=2'; // Bad. diff --git a/WordPress/Tests/Arrays/ArrayAssignmentRestrictionsUnitTest.php b/WordPress/Tests/Arrays/ArrayAssignmentRestrictionsUnitTest.php index bdebed3728..952516ac0f 100644 --- a/WordPress/Tests/Arrays/ArrayAssignmentRestrictionsUnitTest.php +++ b/WordPress/Tests/Arrays/ArrayAssignmentRestrictionsUnitTest.php @@ -2,21 +2,22 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. + * Unit test class for the ArrayAssignmentRestrictions sniff. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @package WPCS\WordPressCodingStandards + * @since 0.3.0 */ class WordPress_Tests_Arrays_ArrayAssignmentRestrictionsUnitTest extends AbstractSniffUnitTest { + /** + * Fill in the $groups property to test the abstract class. + */ protected function setUp() { parent::setUp(); @@ -35,10 +36,7 @@ protected function setUp() { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -47,19 +45,16 @@ public function getErrorList() { 7 => 2, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/Arrays/ArrayDeclarationUnitTest.inc b/WordPress/Tests/Arrays/ArrayDeclarationUnitTest.inc index b8357583f3..12831f7841 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationUnitTest.inc +++ b/WordPress/Tests/Arrays/ArrayDeclarationUnitTest.inc @@ -1,48 +1,48 @@ 'food'), // Bad, no spaces after opening and befoer closing paranthesis + array('post_type' => 'food'), // Bad, no spaces after opening and before closing paranthesis. // ... array( 'post_status' => 'private', - 'orderby' => 'title' // Bad, no comma at the ending + 'orderby' => 'title' // Bad, no comma at the ending. ) ); $query = new WP_Query( $query_vars ); $query_vars = array_merge( - array( 'post_type' => 'food' ), // Good + array( 'post_type' => 'food' ), // Good. // ... array( 'post_status' => 'private', - 'orderby' => 'title', // Good + 'orderby' => 'title', // Good. ), array( - 'closure' => function () { // Good, Closures allowed + 'closure' => function () { // Good, closures allowed. return array(); }, ), - bar( // Good, Functions allowed + bar( // Good, functions allowed. 1, 2 ) ); $query = new WP_Query( $query_vars ); -$defaults = array( 'type'=>'post' ); // Bad, no spaces before and after double arrow +$defaults = array( 'type'=>'post' ); // Bad, no spaces before and after double arrow. wp_parse_args( $args, $defaults ); class Foo { function to_markdown( $params = array() ) { - // Parse sections + // Parse sections. $section_formatters = array( 'Description' => function ( $body ) use ( $params ) { if ( isset( $params['travis_ci_url'] ) ) { @@ -69,15 +69,15 @@ class Foo { } $primary_order = array( - 'n', // null - 'b', // boolean - 'i', // integer - 'f', // float - 's', // string - 'a', // array - 'o', // object - 'r', // resource - 'p', // SPL_Types object + 'n', // Null. + 'b', // Boolean. + 'i', // Integer. + 'f', // Float. + 's', // String. + 'a', // Array. + 'o', // Object. + 'r', // Resource. + 'p', // SPL_Types object. ); $var = array( @@ -89,7 +89,7 @@ $var = array( ', ); -// This should all be good: +// This should all be good. $section_args = array( 'title' => sprintf( __( 'Sidebar: %s', 'widget-customizer' ), @@ -125,67 +125,67 @@ $actions = array( ); $custom_fields = array( - 'videoembed', // Press75 Simple Video Embedder - '_videoembed_manual', // Press75 Simple Video Embedder - '_videoembed', // Press75 Simple Video Embedder - '_premise_settings', // Premise + 'videoembed', // Press75 Simple Video Embedder. + '_videoembed_manual', // Press75 Simple Video Embedder. + '_videoembed', // Press75 Simple Video Embedder. + '_premise_settings', // Premise. ); $item_block_comment = array( 'item', - /* Some comment */ + /* Some comment. */ ); $item_multiple_line_block_comment = array( 'item', /* Some comment - over multiple lines */ + over multiple lines. */ ); $block_comment = array( - /* Just a comment */ + /* Just a comment. */ ); $comment = array( - // Just a single comment + // Just a single comment. ); $multidimensional_comments = array( 'item_block_comment' => array( 'item', - /* comment */ + /* Comment. */ ), 'block_comment' => array( - /* comment */ + /* Comment. */ ), 'item_comment' => array( 'item', - // comment + // Comment. ), 'comment' => array( - // comment + // Comment. ), - // comment + // Comment. array( 'item', - /* comment */ + /* Comment. */ ), array( - /* comment */ + /* Comment. */ ), array( 'item', - // comment + // Comment. ), array( - // comment + // Comment. ), - // comment + // Comment. ); $q = new WP_Query( array( 'meta_query' => array( - 'relation' => 'and', // OK + 'relation' => 'and', // Ok. array( 'key' => 'asdsa', 'value' => 'asds', @@ -198,7 +198,7 @@ array( /** * Doc comment. */ -// 'core' +// 'core'. ); // Multiple values in an array on a single line is allowed. diff --git a/WordPress/Tests/Arrays/ArrayDeclarationUnitTest.inc.fixed b/WordPress/Tests/Arrays/ArrayDeclarationUnitTest.inc.fixed index 23b2a7d8e7..cbe7ae78a6 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationUnitTest.inc.fixed +++ b/WordPress/Tests/Arrays/ArrayDeclarationUnitTest.inc.fixed @@ -1,48 +1,48 @@ 'food' ), // Bad, no spaces after opening and befoer closing paranthesis + array( 'post_type' => 'food' ), // Bad, no spaces after opening and before closing paranthesis. // ... array( 'post_status' => 'private', - 'orderby' => 'title',// Bad, no comma at the ending + 'orderby' => 'title',// Bad, no comma at the ending. ) ); $query = new WP_Query( $query_vars ); $query_vars = array_merge( - array( 'post_type' => 'food' ), // Good + array( 'post_type' => 'food' ), // Good. // ... array( 'post_status' => 'private', - 'orderby' => 'title', // Good + 'orderby' => 'title', // Good. ), array( - 'closure' => function () { // Good, Closures allowed + 'closure' => function () { // Good, closures allowed. return array(); }, ), - bar( // Good, Functions allowed + bar( // Good, functions allowed. 1, 2 ) ); $query = new WP_Query( $query_vars ); -$defaults = array( 'type' => 'post' ); // Bad, no spaces before and after double arrow +$defaults = array( 'type' => 'post' ); // Bad, no spaces before and after double arrow. wp_parse_args( $args, $defaults ); class Foo { function to_markdown( $params = array() ) { - // Parse sections + // Parse sections. $section_formatters = array( 'Description' => function ( $body ) use ( $params ) { if ( isset( $params['travis_ci_url'] ) ) { @@ -69,15 +69,15 @@ class Foo { } $primary_order = array( - 'n', // null - 'b', // boolean - 'i', // integer - 'f', // float - 's', // string - 'a', // array - 'o', // object - 'r', // resource - 'p', // SPL_Types object + 'n', // Null. + 'b', // Boolean. + 'i', // Integer. + 'f', // Float. + 's', // String. + 'a', // Array. + 'o', // Object. + 'r', // Resource. + 'p', // SPL_Types object. ); $var = array( @@ -89,7 +89,7 @@ $var = array( ', ); -// This should all be good: +// This should all be good. $section_args = array( 'title' => sprintf( __( 'Sidebar: %s', 'widget-customizer' ), @@ -125,67 +125,67 @@ $actions = array( ); $custom_fields = array( - 'videoembed', // Press75 Simple Video Embedder - '_videoembed_manual', // Press75 Simple Video Embedder - '_videoembed', // Press75 Simple Video Embedder - '_premise_settings', // Premise + 'videoembed', // Press75 Simple Video Embedder. + '_videoembed_manual', // Press75 Simple Video Embedder. + '_videoembed', // Press75 Simple Video Embedder. + '_premise_settings', // Premise. ); $item_block_comment = array( 'item', - /* Some comment */ + /* Some comment. */ ); $item_multiple_line_block_comment = array( 'item', /* Some comment - over multiple lines */ + over multiple lines. */ ); $block_comment = array( - /* Just a comment */ + /* Just a comment. */ ); $comment = array( - // Just a single comment + // Just a single comment. ); $multidimensional_comments = array( 'item_block_comment' => array( 'item', - /* comment */ + /* Comment. */ ), 'block_comment' => array( - /* comment */ + /* Comment. */ ), 'item_comment' => array( 'item', - // comment + // Comment. ), 'comment' => array( - // comment + // Comment. ), - // comment + // Comment. array( 'item', - /* comment */ + /* Comment. */ ), array( - /* comment */ + /* Comment. */ ), array( 'item', - // comment + // Comment. ), array( - // comment + // Comment. ), - // comment + // Comment. ); $q = new WP_Query( array( 'meta_query' => array( - 'relation' => 'and', // OK + 'relation' => 'and', // Ok. array( 'key' => 'asdsa', 'value' => 'asds', @@ -198,7 +198,7 @@ array( /** * Doc comment. */ -// 'core' +// 'core'. ); // Multiple values in an array on a single line is allowed. diff --git a/WordPress/Tests/Arrays/ArrayDeclarationUnitTest.php b/WordPress/Tests/Arrays/ArrayDeclarationUnitTest.php index 0beec37b9f..c206bab99e 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationUnitTest.php +++ b/WordPress/Tests/Arrays/ArrayDeclarationUnitTest.php @@ -2,35 +2,23 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Unit test class for the ArrayDeclaration sniff. * - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Akeda Bagus - * @author Greg Sherwood - * @author Marc McIntyre - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 2013-06-11 */ class WordPress_Tests_Arrays_ArrayDeclarationUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -43,19 +31,16 @@ public function getErrorList() { 208 => 2, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/Arrays/ArrayKeySpacingRestrictionsUnitTest.inc b/WordPress/Tests/Arrays/ArrayKeySpacingRestrictionsUnitTest.inc index a149f21b77..ab7fae7162 100644 --- a/WordPress/Tests/Arrays/ArrayKeySpacingRestrictionsUnitTest.inc +++ b/WordPress/Tests/Arrays/ArrayKeySpacingRestrictionsUnitTest.inc @@ -1,31 +1,31 @@ + * @package WPCS\WordPressCodingStandards + * @since 0.3.0 */ class WordPress_Tests_Arrays_ArrayKeySpacingRestrictionsUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -41,19 +36,16 @@ public function getErrorList() { 29 => 1, 31 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/CSRF/NonceVerificationUnitTest.inc b/WordPress/Tests/CSRF/NonceVerificationUnitTest.inc index e6b612f5c8..c6eb4e9c9c 100644 --- a/WordPress/Tests/CSRF/NonceVerificationUnitTest.inc +++ b/WordPress/Tests/CSRF/NonceVerificationUnitTest.inc @@ -2,11 +2,11 @@ // Bad, needs nonce check. function bar() { - if ( ! isset( $_POST['test'] ) ) { // Bad + if ( ! isset( $_POST['test'] ) ) { // Bad. return; } - do_something( $_POST['test'] ); // Bad + do_something( $_POST['test'] ); // Bad. } // Good, has an nonce check. @@ -28,7 +28,7 @@ function foo() { // Doing other things with the request params before the nonce check is prohibited. function process() { - do_something( $_POST['foo'] ); // Bad + do_something( $_POST['foo'] ); // Bad. if ( ! isset( $_POST['test'] ) || ! wp_verify_nonce( 'some_action' ) ) { exit; @@ -41,11 +41,11 @@ class Some_Class { // Bad, needs nonce check. function bar() { - if ( ! isset( $_POST['test'] ) ) { // Bad + if ( ! isset( $_POST['test'] ) ) { // Bad. return; } - do_something( $_POST['test'] ); // Bad + do_something( $_POST['test'] ); // Bad. } // Good, has an nonce check. @@ -66,7 +66,7 @@ class Some_Class { // Doing other things with the request params before the nonce check is prohibited. function process() { - do_something( $_POST['foo'] ); // Bad + do_something( $_POST['foo'] ); // Bad. if ( ! isset( $_POST['test'] ) || ! wp_verify_nonce( 'some_action' ) ) { exit; @@ -78,20 +78,20 @@ class Some_Class { // Assignments are allowed. function foo_2() { - $_POST = array( 'a' => 'b' ); // OK - $_POST['test'] = somethin(); // OK - $_POST['settings'][ $setting ] = 'bb'; // OK + $_POST = array( 'a' => 'b' ); // OK. + $_POST['test'] = somethin(); // OK. + $_POST['settings'][ $setting ] = 'bb'; // OK. } // Particular cases can be whitelisted with a comment. function foo_3() { - bar( $_POST['var'] ); // WPCS: CSRF OK - bar( $_POST['var'] ); // Bad + bar( $_POST['var'] ); // WPCS: CSRF OK. + bar( $_POST['var'] ); // Bad. } // We need to account for when there are multiple vars in a single isset(). function foo_4() { - if ( ! isset( $_POST['foo'], $_POST['bar'], $_POST['_wpnonce'] ) ) { // OK + if ( ! isset( $_POST['foo'], $_POST['bar'], $_POST['_wpnonce'] ) ) { // OK. return; } @@ -101,8 +101,8 @@ function foo_4() { // Sanitization before the nonce check is permitted. function sanitization_allowed() { - $foo = (int) $_POST['foo']; // OK - $bar = sanitize_key( $_POST['bar'] ); // OK + $foo = (int) $_POST['foo']; // OK. + $bar = sanitize_key( $_POST['bar'] ); // OK. check_ajax_referer( "something-{$foo}-{$bar}" ); } @@ -110,8 +110,8 @@ function sanitization_allowed() { // The value must only be sanitized though. function foo_5() { - do_something( (int) $_POST['foo'] ); // Bad - do_something( sanitize_key( $_POST['bar'] ) ); // Bad + do_something( (int) $_POST['foo'] ); // Bad. + do_something( sanitize_key( $_POST['bar'] ) ); // Bad. check_ajax_referer( 'something' ); } diff --git a/WordPress/Tests/CSRF/NonceVerificationUnitTest.php b/WordPress/Tests/CSRF/NonceVerificationUnitTest.php index fbc366048f..66979da9f9 100644 --- a/WordPress/Tests/CSRF/NonceVerificationUnitTest.php +++ b/WordPress/Tests/CSRF/NonceVerificationUnitTest.php @@ -2,28 +2,23 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * Unit test class for the NonceVerification Sniff. + * Unit test class for the NonceVerification sniff. * - * @category PHP - * @package PHP_CodeSniffer - * @author J.D. Grimes - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 0.5.0 */ class WordPress_Tests_CSRF_NonceVerificationUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { @@ -38,19 +33,16 @@ public function getErrorList() { 113 => 1, 114 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/Classes/ClassOpeningStatementUnitTest.php b/WordPress/Tests/Classes/ClassOpeningStatementUnitTest.php index 7bbbd9ebf5..0de7389e44 100644 --- a/WordPress/Tests/Classes/ClassOpeningStatementUnitTest.php +++ b/WordPress/Tests/Classes/ClassOpeningStatementUnitTest.php @@ -2,30 +2,23 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Unit test class for the ClassOpeningStatement sniff. * - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Juliette Reinders Folmer + * @package WPCS\WordPressCodingStandards + * @since 0.10.0 */ class WordPress_Tests_Classes_ClassOpeningStatementUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array + * @return array => */ public function getErrorList() { @@ -43,21 +36,18 @@ public function getErrorList() { 79 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array + * @return array => */ public function getWarningList() { return array( 51 => 1, ); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/Classes/ValidClassNameUnitTest.inc b/WordPress/Tests/Classes/ValidClassNameUnitTest.inc index 485ad2705f..f4914ededd 100644 --- a/WordPress/Tests/Classes/ValidClassNameUnitTest.inc +++ b/WordPress/Tests/Classes/ValidClassNameUnitTest.inc @@ -1,7 +1,7 @@ - * @author Greg Sherwood - * @author Marc McIntyre - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 2013-06-11 */ class WordPress_Tests_Classes_ValidClassNameUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( 7 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/DB/RestrictedClassesUnitTest.1.inc b/WordPress/Tests/DB/RestrictedClassesUnitTest.1.inc index 03af35213e..594c0ae8b7 100644 --- a/WordPress/Tests/DB/RestrictedClassesUnitTest.1.inc +++ b/WordPress/Tests/DB/RestrictedClassesUnitTest.1.inc @@ -34,7 +34,7 @@ class TheirMysqli implements \mysqli {} $db5 = new PDO(); $db6 - new PDO->exec(); -PDO::getAvailableDrivers() +PDO::getAvailableDrivers(); $db7 = new PDOStatement; $db8 = new \PDOStatement(); diff --git a/WordPress/Tests/DB/RestrictedClassesUnitTest.2.inc b/WordPress/Tests/DB/RestrictedClassesUnitTest.2.inc index b4fad2d8e1..9536046e7a 100644 --- a/WordPress/Tests/DB/RestrictedClassesUnitTest.2.inc +++ b/WordPress/Tests/DB/RestrictedClassesUnitTest.2.inc @@ -13,35 +13,35 @@ class DBlayer { } } -class DBextended extends DBlayer { // Bad +class DBextended extends DBlayer { // Bad. } -class DBextender implements PDO { // Ok -> resolves to \My\PDO +class DBextender implements PDO { // Ok -> resolves to \My\PDO. } -class DBextendes implements \PDO { // Bad -> fully qualified as \PDO +class DBextendes implements \PDO { // Bad -> fully qualified as \PDO. } -$db0 = new \DBlayer; // Ok - fully qualified as \DBlayer -$db1 = new DBlayer; // Bad - resolves to \My\DBlayer -$db2 = new DBlayer(); // Bad - resolves to \My\DBlayer +$db0 = new \DBlayer; // Ok - fully qualified as \DBlayer. +$db1 = new DBlayer; // Bad - resolves to \My\DBlayer. +$db2 = new DBlayer(); // Bad - resolves to \My\DBlayer. -echo DBlayer::VERSION; // Bad - resolves to \My\DBlayer -echo DBlayer::$property; // Bad - resolves to \My\DBlayer -echo DBlayer::connect(); // Bad - resolves to \My\DBlayer +echo DBlayer::VERSION; // Bad - resolves to \My\DBlayer. +echo DBlayer::$property; // Bad - resolves to \My\DBlayer. +echo DBlayer::connect(); // Bad - resolves to \My\DBlayer. -$db3 = new Yours\DBlayer; // Ok - resolves to \My\Yours\DBlayer +$db3 = new Yours\DBlayer; // Ok - resolves to \My\Yours\DBlayer. -echo Yours\DBlayer::VERSION; // Ok - resolves to \My\Yours\DBlayer -echo Yours\DBlayer::$property; // Ok - resolves to \My\Yours\DBlayer -echo Yours\DBlayer::connect(); // Ok - resolves to \My\Yours\DBlayer +echo Yours\DBlayer::VERSION; // Ok - resolves to \My\Yours\DBlayer. +echo Yours\DBlayer::$property; // Ok - resolves to \My\Yours\DBlayer. +echo Yours\DBlayer::connect(); // Ok - resolves to \My\Yours\DBlayer. -$db4 = new \My\DBlayer; // Bad - fully qualified as \My\DBlayer +$db4 = new \My\DBlayer; // Bad - fully qualified as \My\DBlayer. -echo \My\DBlayer::VERSION; // Bad - fully qualified as \My\DBlayer -echo \My\DBlayer::$property; // Bad - fully qualified as \My\DBlayer -echo \My\DBlayer::connect(); // Bad - fully qualified as \My\DBlayer +echo \My\DBlayer::VERSION; // Bad - fully qualified as \My\DBlayer. +echo \My\DBlayer::$property; // Bad - fully qualified as \My\DBlayer. +echo \My\DBlayer::connect(); // Bad - fully qualified as \My\DBlayer. -echo namespace\DBlayer::VERSION; // Bad - resolves to \My\DBlayer -echo namespace\DBlayer::$property; // Bad - resolves to \My\DBlayer -echo namespace\DBlayer::connect(); // Bad - resolves to \My\DBlayer +echo namespace\DBlayer::VERSION; // Bad - resolves to \My\DBlayer. +echo namespace\DBlayer::$property; // Bad - resolves to \My\DBlayer. +echo namespace\DBlayer::connect(); // Bad - resolves to \My\DBlayer. diff --git a/WordPress/Tests/DB/RestrictedClassesUnitTest.3.inc b/WordPress/Tests/DB/RestrictedClassesUnitTest.3.inc index fd1ddf14a8..3100d1c2f7 100644 --- a/WordPress/Tests/DB/RestrictedClassesUnitTest.3.inc +++ b/WordPress/Tests/DB/RestrictedClassesUnitTest.3.inc @@ -13,42 +13,42 @@ namespace My { } } - class DBextended extends DBlayer { // Bad + class DBextended extends DBlayer { // Bad. } - class DBextender implements PDO { // Ok -> resolves to \My\PDO + class DBextender implements PDO { // Ok -> resolves to \My\PDO. } - class DBextendes implements \PDO { // Bad -> fully qualified as \PDO + class DBextendes implements \PDO { // Bad -> fully qualified as \PDO. } - $db0 = new \DBlayer; // Ok - fully qualified as \DBlayer - $db1 = new DBlayer; // Bad - resolves to \My\DBlayer - $db2 = new DBlayer(); // Bad - resolves to \My\DBlayer + $db0 = new \DBlayer; // Ok - fully qualified as \DBlayer. + $db1 = new DBlayer; // Bad - resolves to \My\DBlayer. + $db2 = new DBlayer(); // Bad - resolves to \My\DBlayer. - echo DBlayer::VERSION; // Bad - resolves to \My\DBlayer - echo DBlayer::$property; // Bad - resolves to \My\DBlayer - echo DBlayer::connect(); // Bad - resolves to \My\DBlayer + echo DBlayer::VERSION; // Bad - resolves to \My\DBlayer. + echo DBlayer::$property; // Bad - resolves to \My\DBlayer. + echo DBlayer::connect(); // Bad - resolves to \My\DBlayer. - $db3 = new Yours\DBlayer; // Ok - resolves to \My\Yours\DBlayer + $db3 = new Yours\DBlayer; // Ok - resolves to \My\Yours\DBlayer. - echo Yours\DBlayer::VERSION; // Ok - resolves to \My\Yours\DBlayer - echo Yours\DBlayer::$property; // Ok - resolves to \My\Yours\DBlayer - echo Yours\DBlayer::connect(); // Ok - resolves to \My\Yours\DBlayer + echo Yours\DBlayer::VERSION; // Ok - resolves to \My\Yours\DBlayer. + echo Yours\DBlayer::$property; // Ok - resolves to \My\Yours\DBlayer. + echo Yours\DBlayer::connect(); // Ok - resolves to \My\Yours\DBlayer. - $db4 = new \My\DBlayer; // Bad - fully qualified as \My\DBlayer + $db4 = new \My\DBlayer; // Bad - fully qualified as \My\DBlayer. - echo \My\DBlayer::VERSION; // Bad - fully qualified as \My\DBlayer - echo \My\DBlayer::$property; // Bad - fully qualified as \My\DBlayer - echo \My\DBlayer::connect(); // Bad - fully qualified as \My\DBlayer + echo \My\DBlayer::VERSION; // Bad - fully qualified as \My\DBlayer. + echo \My\DBlayer::$property; // Bad - fully qualified as \My\DBlayer. + echo \My\DBlayer::connect(); // Bad - fully qualified as \My\DBlayer. - echo namespace\DBlayer::VERSION; // Bad - resolves to \My\DBlayer - echo namespace\DBlayer::$property; // Bad - resolves to \My\DBlayer - echo namespace\DBlayer::connect(); // Bad - resolves to \My\DBlayer + echo namespace\DBlayer::VERSION; // Bad - resolves to \My\DBlayer. + echo namespace\DBlayer::$property; // Bad - resolves to \My\DBlayer. + echo namespace\DBlayer::connect(); // Bad - resolves to \My\DBlayer. } -// Now we're outside the namespace, so things should work differently +// Now we're outside the namespace, so things should work differently. $db0 = new \DBlayer; // Ok. $db1 = new DBlayer; // Ok. $db2 = new DBlayer(); // Ok. @@ -57,17 +57,17 @@ echo DBlayer::VERSION; // Ok. echo DBlayer::$property; // Ok. echo DBlayer::connect(); // Ok. -$db3 = new Yours\DBlayer; // Ok - resolves to \Yours\DBlayer +$db3 = new Yours\DBlayer; // Ok - resolves to \Yours\DBlayer. -echo Yours\DBlayer::VERSION; // Ok - resolves to \Yours\DBlayer -echo Yours\DBlayer::$property; // Ok - resolves to \Yours\DBlayer -echo Yours\DBlayer::connect(); // Ok - resolves to \Yours\DBlayer +echo Yours\DBlayer::VERSION; // Ok - resolves to \Yours\DBlayer. +echo Yours\DBlayer::$property; // Ok - resolves to \Yours\DBlayer. +echo Yours\DBlayer::connect(); // Ok - resolves to \Yours\DBlayer. -$db4 = new \My\DBlayer; // Bad - fully qualified as \My\DBlayer +$db4 = new \My\DBlayer; // Bad - fully qualified as \My\DBlayer. -echo \My\DBlayer::VERSION; // Bad - fully qualified as \My\DBlayer -echo \My\DBlayer::$property; // Bad - fully qualified as \My\DBlayer -echo \My\DBlayer::connect(); // Bad - fully qualified as \My\DBlayer +echo \My\DBlayer::VERSION; // Bad - fully qualified as \My\DBlayer. +echo \My\DBlayer::$property; // Bad - fully qualified as \My\DBlayer. +echo \My\DBlayer::connect(); // Bad - fully qualified as \My\DBlayer. echo namespace\DBlayer::VERSION; // Ok. echo namespace\DBlayer::$property; // Ok. @@ -85,8 +85,8 @@ namespace AdoDb { class TestYetAgain extends Tester {} // Bad. - $db5 = new Test; // Bad - $db6 = new Tester(); // Bad + $db5 = new Test; // Bad. + $db6 = new Tester(); // Bad. } -$db7 = new Test; // Ok +$db7 = new Test; // Ok. diff --git a/WordPress/Tests/DB/RestrictedClassesUnitTest.php b/WordPress/Tests/DB/RestrictedClassesUnitTest.php index 2c8eef383f..c174c84fc4 100644 --- a/WordPress/Tests/DB/RestrictedClassesUnitTest.php +++ b/WordPress/Tests/DB/RestrictedClassesUnitTest.php @@ -2,25 +2,16 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * WordPress_Tests_DB_RestrictedFunctionsUnitTest + * Unit test class for the DB_RestrictedClasses sniff. * - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Akeda Bagus - * @author Greg Sherwood - * @author Marc McIntyre - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 0.10.0 */ class WordPress_Tests_DB_RestrictedClassesUnitTest extends AbstractSniffUnitTest { @@ -58,12 +49,8 @@ protected function shouldSkipTest() { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * * @param string $testFile The name of the file being tested. - * - * @return array(int => int) + * @return array => */ public function getErrorList( $testFile = '' ) { switch ( $testFile ) { @@ -144,14 +131,11 @@ public function getErrorList( $testFile = '' ) { /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); } -} // end class +} // End class. diff --git a/WordPress/Tests/DB/RestrictedFunctionsUnitTest.inc b/WordPress/Tests/DB/RestrictedFunctionsUnitTest.inc index 821abf7c38..ab973dcf17 100644 --- a/WordPress/Tests/DB/RestrictedFunctionsUnitTest.inc +++ b/WordPress/Tests/DB/RestrictedFunctionsUnitTest.inc @@ -1,20 +1,20 @@ mysql_info(); // ok -$y = Bar::mysql_info(); // ok -prefix_mysql_info(); // ok +$x->mysql_info(); // Ok. +$y = Bar::mysql_info(); // Ok. +prefix_mysql_info(); // Ok. /** @@ -68,11 +68,11 @@ maxdb_close(); maxdb_connect(); maxdb_errno(); maxdb_escape_string(); -maxdb_fetch_assoc +maxdb_fetch_assoc(); maxdb_init(); maxdb_num_fields(); maxdb_prepare(); -maxdb_real_query +maxdb_real_query(); maxdb_stat(); diff --git a/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php b/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php index 1e70d1a433..335e2bdce2 100644 --- a/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php +++ b/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php @@ -2,35 +2,23 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * WordPress_Tests_DB_RestrictedFunctionsUnitTest + * Unit test class for the DB_RestrictedFunctions sniff. * - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Akeda Bagus - * @author Greg Sherwood - * @author Marc McIntyre - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 0.10.0 */ class WordPress_Tests_DB_RestrictedFunctionsUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -87,14 +75,11 @@ public function getErrorList() { /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/Files/FileNameUnitTest.php b/WordPress/Tests/Files/FileNameUnitTest.php index 7770770826..20b7e51110 100644 --- a/WordPress/Tests/Files/FileNameUnitTest.php +++ b/WordPress/Tests/Files/FileNameUnitTest.php @@ -2,52 +2,37 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Unit test class for the FileName sniff. * - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Akeda Bagus - * @author Greg Sherwood - * @author Marc McIntyre - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 2013-06-11 */ class WordPress_Tests_Files_FileNameUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array(); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/Functions/DontExtractUnitTest.inc b/WordPress/Tests/Functions/DontExtractUnitTest.inc index f6a12ec66f..9ed5c3d2b2 100644 --- a/WordPress/Tests/Functions/DontExtractUnitTest.inc +++ b/WordPress/Tests/Functions/DontExtractUnitTest.inc @@ -1,6 +1,6 @@ 1 ) ); // bad +extract( array( 'a' => 1 ) ); // Bad. // Similarly named functions or methods however are fine. my_extract(); // Ok. diff --git a/WordPress/Tests/Functions/DontExtractUnitTest.php b/WordPress/Tests/Functions/DontExtractUnitTest.php index de482870a2..fa06e359d8 100644 --- a/WordPress/Tests/Functions/DontExtractUnitTest.php +++ b/WordPress/Tests/Functions/DontExtractUnitTest.php @@ -2,52 +2,39 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. + * Unit test class for the DontExtract sniff. * - * @category PHP - * @package PHP_CodeSniffer - * @author Akeda Bagus - * @author Greg Sherwood - * @author Marc McIntyre - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 0.10.0 */ class WordPress_Tests_Functions_DontExtractUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( 3 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc index 176bcaeea3..82aaef04e5 100644 --- a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc +++ b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc @@ -1,24 +1,24 @@ - * @author Greg Sherwood - * @author Marc McIntyre - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 2013-06-11 */ class WordPress_Tests_NamingConventions_ValidFunctionNameUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -51,19 +39,16 @@ public function getErrorList() { 89 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php index 4afc403505..f571579194 100644 --- a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php +++ b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php @@ -2,32 +2,24 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Unit test class for the ValidHookName sniff. * - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Juliette Reinders Folmer + * @package WPCS\WordPressCodingStandards + * @since 0.10.0 */ class WordPress_Tests_NamingConventions_ValidHookNameUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * * @param string $testFile The name of the file being tested. - * - * @return array + * @return array => */ public function getErrorList( $testFile = 'ValidHookNameUnitTest.inc' ) { @@ -84,12 +76,8 @@ public function getErrorList( $testFile = 'ValidHookNameUnitTest.inc' ) { /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * * @param string $testFile The name of the file being tested. - * - * @return array + * @return array => */ public function getWarningList( $testFile = 'ValidHookNameUnitTest.inc' ) { @@ -117,8 +105,8 @@ public function getWarningList( $testFile = 'ValidHookNameUnitTest.inc' ) { default: return array(); - } // end switch + } - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.inc b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.inc index 3dc603c39c..80a2477d51 100644 --- a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.inc +++ b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.inc @@ -1,46 +1,46 @@ varName2; // Bad +echo $this->varName2; // Bad. echo $this->var_name2; echo $this->varname2; -echo $this->_varName2; // Bad -echo $object->varName2; // Bad +echo $this->_varName2; // Bad. +echo $object->varName2; // Bad. echo $object->var_name2; echo $object_name->varname2; -echo $object_name->_varName2; // Bad -echo $object_name->VAR_name; // Bad +echo $object_name->_varName2; // Bad. +echo $object_name->VAR_name; // Bad. echo $this->myFunction($one, $two); echo $object->myFunction($one_two); -$error = "format is \$GLOBALS['$varName']"; // Bad +$error = "format is \$GLOBALS['$varName']"; // Bad. echo $_SESSION['var_name']; echo $_FILES['var_name']; echo $_ENV['var_name']; echo $_COOKIE['var_name']; -$XML = 'hello'; // Bad -$myXML = 'hello'; // Bad -$XMLParser = 'hello'; // Bad -$xmlParser = 'hello'; // Bad +$XML = 'hello'; // Bad. +$myXML = 'hello'; // Bad. +$XMLParser = 'hello'; // Bad. +$xmlParser = 'hello'; // Bad. -$ID = 1; // Bad +$ID = 1; // Bad. $post = get_post( $x ); echo $post->ID; -echo $comment_ID; // Bad -echo $comment_post_ID; // Bad -echo $comment_author_IP; // Bad +echo $comment_ID; // Bad. +echo $comment_post_ID; // Bad. +echo $comment_author_IP; // Bad. $comment = get_comment( 1 ); echo $comment->comment_ID; @@ -96,22 +96,22 @@ class Foo { public $_public_leading_underscore; private $private_no_underscore_loading; - function Bar( $VARname ) { // Bad - $localVariable = false; // Bad - echo Some_Class::$VarName; // Bad - echo $this->VAR_name; // Bad - $_localVariable = false; // Bad - echo Some_Class::$_VarName; // Bad - echo $this->_VAR_name; // Bad + function Bar( $VARname ) { // Bad. + $localVariable = false; // Bad. + echo Some_Class::$VarName; // Bad. + echo $this->VAR_name; // Bad. + $_localVariable = false; // Bad. + echo Some_Class::$_VarName; // Bad. + echo $this->_VAR_name; // Bad. } - function Baz( $var_name ) { // Ok - $local_variable = false; // Ok - echo Some_Class::$var_name; // Ok - echo $this->var_name; // Ok - $_local_variable = false; // Ok - echo Some_Class::$_var_name; // Ok - echo $this->_var_name; // Ok + function Baz( $var_name ) { // Ok. + $local_variable = false; // Ok. + echo Some_Class::$var_name; // Ok. + echo $this->var_name; // Ok. + $_local_variable = false; // Ok. + echo Some_Class::$_var_name; // Ok. + echo $this->_var_name; // Ok. } } diff --git a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php index fbbb92876c..33cf777902 100644 --- a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php +++ b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php @@ -2,36 +2,23 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * Unit test class for WordPress_Sniffs_NamingConventions_ValidVariableNameSniff. + * Unit test class for the ValidVariableName sniff. * - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @author Weston Ruter - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 0.9.0 */ class WordPress_Tests_NamingConventions_ValidVariableNameUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array + * @return array => */ public function getErrorList() { $errors = array( @@ -85,14 +72,11 @@ public function getErrorList() { /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/PHP/DisallowAlternativePHPTagsUnitTest.php b/WordPress/Tests/PHP/DisallowAlternativePHPTagsUnitTest.php index f68c4a94de..e661908ef9 100644 --- a/WordPress/Tests/PHP/DisallowAlternativePHPTagsUnitTest.php +++ b/WordPress/Tests/PHP/DisallowAlternativePHPTagsUnitTest.php @@ -2,20 +2,16 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP\CodeSniffer\WordPress-Coding-Standards - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Unit test class for the DisallowAlternativePHPTags sniff. * - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. - * - * @category PHP - * @package PHP\CodeSniffer\WordPress-Coding-Standards - * @author Juliette Reinders Folmer + * @package WPCS\WordPressCodingStandards + * @since 0.10.0 */ class WordPress_Tests_PHP_DisallowAlternativePHPTagsUnitTest extends AbstractSniffUnitTest { @@ -49,10 +45,7 @@ protected function shouldSkipTest() { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array + * @return array => */ public function getErrorList() { $errors = array( @@ -75,10 +68,7 @@ public function getErrorList() { /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array + * @return array => */ public function getWarningList() { $warnings = array(); diff --git a/WordPress/Tests/PHP/DiscouragedFunctionsUnitTest.inc b/WordPress/Tests/PHP/DiscouragedFunctionsUnitTest.inc index 0c1733e3b7..b86c3f0377 100644 --- a/WordPress/Tests/PHP/DiscouragedFunctionsUnitTest.inc +++ b/WordPress/Tests/PHP/DiscouragedFunctionsUnitTest.inc @@ -1,15 +1,15 @@ - * @author Greg Sherwood - * @author Marc McIntyre - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 2013-06-11 */ class WordPress_Tests_PHP_DiscouragedFunctionsUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array(); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array( @@ -68,6 +53,6 @@ public function getWarningList() { 54 => 1, ); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc b/WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc index bad1dd5372..785779e02b 100644 --- a/WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc +++ b/WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc @@ -1,12 +1,12 @@ - * @author Greg Sherwood - * @author Marc McIntyre - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 0.10.0 */ class WordPress_Tests_PHP_POSIXFunctionsUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -43,19 +31,16 @@ public function getErrorList() { 26 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/PHP/StrictComparisonsUnitTest.inc b/WordPress/Tests/PHP/StrictComparisonsUnitTest.inc index 73030baf36..1cb1fe41b7 100644 --- a/WordPress/Tests/PHP/StrictComparisonsUnitTest.inc +++ b/WordPress/Tests/PHP/StrictComparisonsUnitTest.inc @@ -1,21 +1,21 @@ $true ) { // Bad +} elseif ( true <> $true ) { // Bad. echo 'False'; -} elseif ( false !== $true ) { // OK +} elseif ( false !== $true ) { // Ok. echo 'False'; } -// test for whitelisting -if ( true == $true ) { // loose comparison, OK +// Test for whitelisting. +if ( true == $true ) { // Loose comparison, OK. echo 'True'; } \ No newline at end of file diff --git a/WordPress/Tests/PHP/StrictComparisonsUnitTest.php b/WordPress/Tests/PHP/StrictComparisonsUnitTest.php index 0c2e6c1888..1de1ad161e 100644 --- a/WordPress/Tests/PHP/StrictComparisonsUnitTest.php +++ b/WordPress/Tests/PHP/StrictComparisonsUnitTest.php @@ -2,46 +2,33 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Unit test class for the StrictComparisons sniff. * - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Matt Robinson - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 0.4.0 */ class WordPress_Tests_PHP_StrictComparisonsUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array(); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array( @@ -50,6 +37,6 @@ public function getWarningList() { 12 => 1, ); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/PHP/StrictInArrayUnitTest.inc b/WordPress/Tests/PHP/StrictInArrayUnitTest.inc index a23ab1f3fb..4832b9d50c 100644 --- a/WordPress/Tests/PHP/StrictInArrayUnitTest.inc +++ b/WordPress/Tests/PHP/StrictInArrayUnitTest.inc @@ -1,23 +1,23 @@ in_array( 1, array( '1', 1, true ) ); // OK +$bar->in_array( 1, array( '1', 1, true ) ); // Ok. $bar-> - in_array( 1, array( '1', 1, true ) ); // OK + in_array( 1, array( '1', 1, true ) ); // Ok. -in_array(); // Error +in_array(); // Error. array_search( 1, $array, true ); // Ok. diff --git a/WordPress/Tests/PHP/StrictInArrayUnitTest.php b/WordPress/Tests/PHP/StrictInArrayUnitTest.php index 9966470356..25738ba2b8 100644 --- a/WordPress/Tests/PHP/StrictInArrayUnitTest.php +++ b/WordPress/Tests/PHP/StrictInArrayUnitTest.php @@ -2,44 +2,35 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Unit test class for the StrictInArray sniff. * - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. - * - * @category PHP - * @package PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 0.9.0 */ class WordPress_Tests_PHP_StrictInArrayUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( 7 => 1, 20 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array( @@ -55,6 +46,6 @@ public function getWarningList() { 39 => 1, 40 => 1, ); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/PHP/YodaConditionsUnitTest.inc b/WordPress/Tests/PHP/YodaConditionsUnitTest.inc index 308649e663..5b2cf5e43a 100644 --- a/WordPress/Tests/PHP/YodaConditionsUnitTest.inc +++ b/WordPress/Tests/PHP/YodaConditionsUnitTest.inc @@ -1,92 +1,92 @@ num_rows === 0 ) {} // Bad +if ( $GLOBALS['wpdb']->num_rows === 0 ) {} // Bad. -if ( $true == strtolower( $check ) ) {} // Bad +if ( $true == strtolower( $check ) ) {} // Bad. -$update = 'yes' === strtolower( $this->from_post( 'update' ) ); // OK +$update = 'yes' === strtolower( $this->from_post( 'update' ) ); // Ok. diff --git a/WordPress/Tests/PHP/YodaConditionsUnitTest.php b/WordPress/Tests/PHP/YodaConditionsUnitTest.php index f63b3a535e..bdf509621c 100644 --- a/WordPress/Tests/PHP/YodaConditionsUnitTest.php +++ b/WordPress/Tests/PHP/YodaConditionsUnitTest.php @@ -2,33 +2,23 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * Unit test class for the YodeConditions sniff. + * Unit test class for the YodaConditions sniff. * - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Matt Robinson - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 0.3.0 */ class WordPress_Tests_PHP_YodaConditionsUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -47,19 +37,16 @@ public function getErrorList() { 90 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php b/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php index f894ac7fa4..0634f529bf 100644 --- a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php +++ b/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php @@ -2,28 +2,23 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. + * Unit test class for the AdminBarRemoval sniff. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @package WPCS\WordPressCodingStandards + * @since 0.3.0 */ class WordPress_Tests_VIP_AdminBarRemovalUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -31,19 +26,16 @@ public function getErrorList() { 5 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/VIP/CronIntervalUnitTest.inc b/WordPress/Tests/VIP/CronIntervalUnitTest.inc index 183c4eaea4..d4bc9dbd37 100644 --- a/WordPress/Tests/VIP/CronIntervalUnitTest.inc +++ b/WordPress/Tests/VIP/CronIntervalUnitTest.inc @@ -25,7 +25,7 @@ class Foo { static function my_add_quicklier( $schedules ) { $schedules['every_5_mins'] = array( - 'interval' => 20 * 60 - 15 * 60, // sneaky 5 minute interval + 'interval' => 20 * 60 - 15 * 60, // Sneaky 5 minute interval. 'display' => __( 'Once every 5 minutes' ) ); return $schedules; diff --git a/WordPress/Tests/VIP/CronIntervalUnitTest.php b/WordPress/Tests/VIP/CronIntervalUnitTest.php index f4253e37c8..bbeca06dff 100644 --- a/WordPress/Tests/VIP/CronIntervalUnitTest.php +++ b/WordPress/Tests/VIP/CronIntervalUnitTest.php @@ -2,28 +2,23 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. + * Unit test class for the CronInterval sniff. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @package WPCS\WordPressCodingStandards + * @since 0.3.0 */ class WordPress_Tests_VIP_CronIntervalUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -33,21 +28,18 @@ public function getErrorList() { 39 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array( 37 => 1, ); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/VIP/DirectDatabaseQueryUnitTest.inc b/WordPress/Tests/VIP/DirectDatabaseQueryUnitTest.inc index 1cfe139e86..e44b14358c 100644 --- a/WordPress/Tests/VIP/DirectDatabaseQueryUnitTest.inc +++ b/WordPress/Tests/VIP/DirectDatabaseQueryUnitTest.inc @@ -3,9 +3,9 @@ function foo() { global $wpdb; - $listofthings = $wpdb->get_col( 'SELECT something FROM somewhere WHERE someotherthing = 1' ); // Error + Warning + $listofthings = $wpdb->get_col( 'SELECT something FROM somewhere WHERE someotherthing = 1' ); // Error + Warning. - $listofthings = $wpdb->get_col( 'SELECT something FROM somewhere WHERE someotherthing = 1' ); //db call okay ( No Warning, but Error for not caching! ) + $listofthings = $wpdb->get_col( 'SELECT something FROM somewhere WHERE someotherthing = 1' ); // DB call okay ( No Warning, but Error for not caching! ). return $listofthings; } @@ -14,7 +14,7 @@ function bar() { global $wpdb; if ( ! ( $listofthings = wp_cache_get( $foo ) ) ) { - $listofthings = $wpdb->get_col( 'SELECT something FROM somewhere WHERE someotherthing = 1' ); // Warning + $listofthings = $wpdb->get_col( 'SELECT something FROM somewhere WHERE someotherthing = 1' ); // Warning. wp_cache_set( 'foo', $listofthings ); } @@ -29,11 +29,11 @@ function baz() { $baz = wp_cache_get( 'baz' ); if ( false !== $baz ) { - $wpdb->query( 'ALTER TABLE TO ADD SOME FIELDS' ); // db call okay (but not really because ALTER TABLE!) + $wpdb->query( 'ALTER TABLE TO ADD SOME FIELDS' ); // DB call okay (but not really because ALTER TABLE!). - $wpdb->query( $wpdb->prepare( 'CREATE TABLE ' ) ); // db call okay (but not really because CREATE TABLE!) + $wpdb->query( $wpdb->prepare( 'CREATE TABLE ' ) ); // DB call okay (but not really because CREATE TABLE!). - $wpdb->query( 'SELECT QUERY' ); // db call okay + $wpdb->query( 'SELECT QUERY' ); // DB call okay. $baz = $wpdb->get_results( $wpdb->prepare( 'SELECT X FROM Y ' ) ); @@ -47,20 +47,20 @@ function quux() { global $wpdb; $quux = wp_cache_get( 'quux' ); if ( false !== $quux ) { - $quux = $wpdb->get_results( $wpdb->prepare( 'SELECT X FROM Y ' ) ); // Bad, no wp_cache_set, results in Error + Warning + $quux = $wpdb->get_results( $wpdb->prepare( 'SELECT X FROM Y ' ) ); // Bad, no wp_cache_set, results in Error + Warning. } } function barzd() { global $wpdb; - $autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option_name ) ); // db call ok; no-cache ok + $autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option_name ) ); // DB call ok; no-cache ok. } function taz() { /* @var wpdb $wpdb */ global $wpdb; - echo $wpdb->insert_id; // Good, no actual call, and doesn't need any caching + echo $wpdb->insert_id; // Good, no actual call, and doesn't need any caching. } // Some $wpdb methods can pass with only deleting the cache. @@ -70,14 +70,14 @@ function cache_delete_only() { $data = $where = array(); // These methods are allowed to be used with just wp_cache_delete(). - $wpdb->update( $wpdb->users, $data, $where ); // db call ok; OK - $wpdb->replace( $wpdb->users, $data, $where ); // db call ok; OK - $wpdb->delete( $wpdb->users, $data, $where ); // db call ok; OK - $wpdb->query( 'SELECT X FROM Y' ); // db call ok; OK + $wpdb->update( $wpdb->users, $data, $where ); // DB call ok; OK. + $wpdb->replace( $wpdb->users, $data, $where ); // DB call ok; OK. + $wpdb->delete( $wpdb->users, $data, $where ); // DB call ok; OK. + $wpdb->query( 'SELECT X FROM Y' ); // DB call ok; OK. - $wpdb->get_results( 'SELECT X FROM Y' ); // db call ok; Bad - $wpdb->get_row( 'SELECT X FROM Y' ); // db call ok; Bad - $wpdb->get_col( 'SELECT X FROM Y' ); // db call ok; Bad + $wpdb->get_results( 'SELECT X FROM Y' ); // DB call ok; Bad. + $wpdb->get_row( 'SELECT X FROM Y' ); // DB call ok; Bad. + $wpdb->get_col( 'SELECT X FROM Y' ); // DB call ok; Bad. wp_cache_delete( 'key', 'group' ); } @@ -92,13 +92,13 @@ function cache_add_instead_of_set() { $data = $where = array(); - $wpdb->update( $wpdb->users, $data, $where ); // db call ok; OK - $wpdb->replace( $wpdb->users, $data, $where ); // db call ok; OK - $wpdb->delete( $wpdb->users, $data, $where ); // db call ok; OK - $wpdb->query( 'SELECT X FROM Y' ); // db call ok; OK - $wpdb->get_row( 'SELECT X FROM Y' ); // db call ok; OK - $wpdb->get_col( 'SELECT X FROM Y' ); // db call ok; OK - $baz = $wpdb->get_results( $wpdb->prepare( 'SELECT X FROM Y ' ) ); // db call ok; OK + $wpdb->update( $wpdb->users, $data, $where ); // DB call ok; OK. + $wpdb->replace( $wpdb->users, $data, $where ); // DB call ok; OK. + $wpdb->delete( $wpdb->users, $data, $where ); // DB call ok; OK. + $wpdb->query( 'SELECT X FROM Y' ); // DB call ok; OK. + $wpdb->get_row( 'SELECT X FROM Y' ); // DB call ok; OK. + $wpdb->get_col( 'SELECT X FROM Y' ); // DB call ok; OK. + $baz = $wpdb->get_results( $wpdb->prepare( 'SELECT X FROM Y ' ) ); // DB call ok; OK. wp_cache_add( 'baz', $baz ); } diff --git a/WordPress/Tests/VIP/DirectDatabaseQueryUnitTest.php b/WordPress/Tests/VIP/DirectDatabaseQueryUnitTest.php index aaee817c9e..4b8da25df5 100644 --- a/WordPress/Tests/VIP/DirectDatabaseQueryUnitTest.php +++ b/WordPress/Tests/VIP/DirectDatabaseQueryUnitTest.php @@ -2,28 +2,23 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * Unit test class for the Direct Database Query. + * Unit test class for the DirectDatabaseQuery sniff. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 0.3.0 */ class WordPress_Tests_VIP_DirectDatabaseQueryUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -37,15 +32,12 @@ public function getErrorList() { 80 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array( @@ -55,6 +47,6 @@ public function getWarningList() { 50 => 1, ); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php b/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php index 575fc68a3b..0b13aa5da7 100644 --- a/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php +++ b/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php @@ -2,28 +2,23 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * Unit test class for the Filesystem writes sniff. + * Unit test class for the FileSystemWritesDisallow sniff. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 0.3.0 */ class WordPress_Tests_VIP_FileSystemWritesDisallowUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -33,19 +28,16 @@ public function getErrorList() { 12 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/VIP/OrderByRandUnitTest.inc b/WordPress/Tests/VIP/OrderByRandUnitTest.inc index 289228d057..c680a98a8b 100644 --- a/WordPress/Tests/VIP/OrderByRandUnitTest.inc +++ b/WordPress/Tests/VIP/OrderByRandUnitTest.inc @@ -1,13 +1,13 @@ 'rand', // Bad - "orderby" => "rand", // Bad - "orderby" => "RAND", // Bad + 'orderby' => 'rand', // Bad. + "orderby" => "rand", // Bad. + "orderby" => "RAND", // Bad. ); -_query_posts( 'orderby=rand' ); // Bad +_query_posts( 'orderby=rand' ); // Bad. -$query_args['orderby'] = 'rand'; // Bad +$query_args['orderby'] = 'rand'; // Bad. -$query_args['orderby'] = 'date'; // OK +$query_args['orderby'] = 'date'; // Ok. diff --git a/WordPress/Tests/VIP/OrderByRandUnitTest.php b/WordPress/Tests/VIP/OrderByRandUnitTest.php index 3faadd2216..5074d859c1 100644 --- a/WordPress/Tests/VIP/OrderByRandUnitTest.php +++ b/WordPress/Tests/VIP/OrderByRandUnitTest.php @@ -2,27 +2,23 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. + * Unit test class for the OrderByRand sniff. * - * @category PHP - * @package PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 0.9.0 */ class WordPress_Tests_VIP_OrderByRandUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -33,19 +29,16 @@ public function getErrorList() { 11 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/VIP/PluginMenuSlugUnitTest.inc b/WordPress/Tests/VIP/PluginMenuSlugUnitTest.inc index e6669fe953..e4414e80e9 100644 --- a/WordPress/Tests/VIP/PluginMenuSlugUnitTest.inc +++ b/WordPress/Tests/VIP/PluginMenuSlugUnitTest.inc @@ -1,7 +1,7 @@ + * @package WPCS\WordPressCodingStandards + * @since 0.3.0 */ class WordPress_Tests_VIP_PluginMenuSlugUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -31,19 +26,16 @@ public function getErrorList() { 5 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/VIP/PostsPerPageUnitTest.inc b/WordPress/Tests/VIP/PostsPerPageUnitTest.inc index 7be7fc8a39..9fd7d8aa7f 100644 --- a/WordPress/Tests/VIP/PostsPerPageUnitTest.inc +++ b/WordPress/Tests/VIP/PostsPerPageUnitTest.inc @@ -1,18 +1,18 @@ true, // Bad - 'posts_per_page' => 999, // Bad - 'posts_per_page' => -1, // Bad - 'posts_per_page' => 1, // OK - 'posts_per_page' => '1', // OK + 'nopaging' => true, // Bad. + 'posts_per_page' => 999, // Bad. + 'posts_per_page' => -1, // Bad. + 'posts_per_page' => 1, // Ok. + 'posts_per_page' => '1', // Ok. ); -_query_posts( 'nopaging=true&posts_per_page=999' ); // Bad +_query_posts( 'nopaging=true&posts_per_page=999' ); // Bad. -$query_args['posts_per_page'] = -1; // Bad -$query_args['posts_per_page'] = 1; // OK -$query_args['posts_per_page'] = '1'; // OK -$query_args['posts_per_page'] = '-1'; // Bad +$query_args['posts_per_page'] = -1; // Bad. +$query_args['posts_per_page'] = 1; // Ok. +$query_args['posts_per_page'] = '1'; // Ok. +$query_args['posts_per_page'] = '-1'; // Bad. -$query_args['my_posts_per_page'] = -1; // OK +$query_args['my_posts_per_page'] = -1; // Ok. diff --git a/WordPress/Tests/VIP/PostsPerPageUnitTest.php b/WordPress/Tests/VIP/PostsPerPageUnitTest.php index 6e991e78a8..5dfb472a00 100644 --- a/WordPress/Tests/VIP/PostsPerPageUnitTest.php +++ b/WordPress/Tests/VIP/PostsPerPageUnitTest.php @@ -2,28 +2,23 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. + * Unit test class for the PostsPerPage sniff. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @package WPCS\WordPressCodingStandards + * @since 0.3.0 */ class WordPress_Tests_VIP_PostsPerPageUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -35,19 +30,16 @@ public function getErrorList() { 16 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.inc b/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.inc index 58926e4fa0..3cf6d6a47c 100644 --- a/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.inc +++ b/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.inc @@ -1,90 +1,90 @@ add_role(); // ok -$y = Bar::add_role(); // ok -\SomeNamespace\add_role(); // ok - -\add_role(); // bad - -get_term_link( $term ); // bad - -get_page_by_path( $path ); // bad - -get_page_by_title( $page_title ); // bad - -get_term_by( $field, $value, $taxonomy ); // bad - -get_category_by_slug( $slug ); // bad - -url_to_postid( $url ); // bad - -attachment_url_to_postid( $url ); // bad -wpcom_vip_attachment_url_to_postid( $url ); // ok - -get_tag_link(); // error -get_category_link(); // error -get_cat_ID(); // error -url_to_post_id(); // error -attachment_url_to_postid(); // error -get_posts(); // warning -wp_get_recent_posts(); // warning - -get_children(); // warning -wp_get_post_terms(); // error -wp_get_post_categories(); // error -wp_get_post_tags(); // error -wp_get_object_terms(); // error -term_exists(); // error -count_user_posts(); // error -wp_old_slug_redirect(); // error -get_adjacent_post(); // error -get_previous_post(); // error -get_next_post(); // error -parse_url( 'http://example.com/' ); // warning - -dl(); // error -error_reporting(); // error -ini_alter(); // error -ini_restore(); // error -ini_set(); // error -magic_quotes_runtime(); // error -set_magic_quotes_runtime(); // error -apache_setenv(); // error -putenv(); // error -set_include_path(); // error -restore_include_path(); // error -phpinfo(); // error - -PHPINFO(); // error -CURL_getinfo(); // error - -curlyhair(); // ok +$x->add_role(); // Ok. +$y = Bar::add_role(); // Ok. +\SomeNamespace\add_role(); // Ok. + +\add_role(); // Bad. + +get_term_link( $term ); // Bad. + +get_page_by_path( $path ); // Bad. + +get_page_by_title( $page_title ); // Bad. + +get_term_by( $field, $value, $taxonomy ); // Bad. + +get_category_by_slug( $slug ); // Bad. + +url_to_postid( $url ); // Bad. + +attachment_url_to_postid( $url ); // Bad. +wpcom_vip_attachment_url_to_postid( $url ); // Ok. + +get_tag_link(); // Error. +get_category_link(); // Error. +get_cat_ID(); // Error. +url_to_post_id(); // Error. +attachment_url_to_postid(); // Error. +get_posts(); // Warning. +wp_get_recent_posts(); // Warning. + +get_children(); // Warning. +wp_get_post_terms(); // Error. +wp_get_post_categories(); // Error. +wp_get_post_tags(); // Error. +wp_get_object_terms(); // Error. +term_exists(); // Error. +count_user_posts(); // Error. +wp_old_slug_redirect(); // Error. +get_adjacent_post(); // Error. +get_previous_post(); // Error. +get_next_post(); // Error. +parse_url( 'http://example.com/' ); // Warning. + +dl(); // Error. +error_reporting(); // Error. +ini_alter(); // Error. +ini_restore(); // Error. +ini_set(); // Error. +magic_quotes_runtime(); // Error. +set_magic_quotes_runtime(); // Error. +apache_setenv(); // Error. +putenv(); // Error. +set_include_path(); // Error. +restore_include_path(); // Error. +phpinfo(); // Error. + +PHPINFO(); // Error. +CURL_getinfo(); // Error. + +curlyhair(); // Ok. diff --git a/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php b/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php index 88791f35b9..9adb6c76c4 100644 --- a/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php +++ b/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php @@ -2,33 +2,23 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. + * Unit test class for the VIP_RestrictedFunctions sniff. * - * @category PHP - * @package PHP_CodeSniffer - * @author Akeda Bagus - * @author Greg Sherwood - * @author Marc McIntyre - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 0.3.0 */ class WordPress_Tests_VIP_RestrictedFunctionsUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -79,10 +69,7 @@ public function getErrorList() { /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array( @@ -99,6 +86,6 @@ public function getWarningList() { 88 => 1, ); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/VIP/RestrictedVariablesUnitTest.inc b/WordPress/Tests/VIP/RestrictedVariablesUnitTest.inc index 4c6d513f2a..61e919117e 100644 --- a/WordPress/Tests/VIP/RestrictedVariablesUnitTest.inc +++ b/WordPress/Tests/VIP/RestrictedVariablesUnitTest.inc @@ -1,19 +1,19 @@ users"; // bad +$query = "SELECT * FROM $wpdb->users"; // Bad. -$wp_db->update( $wpdb->users, array( 'displayname' => 'Kanobe!' ), array( 'ID' => 1 ) ); // bad +$wp_db->update( $wpdb->users, array( 'displayname' => 'Kanobe!' ), array( 'ID' => 1 ) ); // Bad. -$query = "SELECT * FROM $wpdb->usermeta"; // bad +$query = "SELECT * FROM $wpdb->usermeta"; // Bad. -$wp_db->update( $wpdb->usermeta, array( 'meta_value' => 'bar!' ), array( 'user_id' => 1, 'meta_key' => 'foo' ) ); // bad +$wp_db->update( $wpdb->usermeta, array( 'meta_value' => 'bar!' ), array( 'user_id' => 1, 'meta_key' => 'foo' ) ); // Bad. -$query = "SELECT * FROM $wpdb->posts"; // ok +$query = "SELECT * FROM $wpdb->posts"; // Ok. -if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { // bad - foo( $_SERVER['HTTP_USER_AGENT'] ); // bad +if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { // Bad. + foo( $_SERVER['HTTP_USER_AGENT'] ); // Bad. } -$x = $_COOKIE['bar']; // bad +$x = $_COOKIE['bar']; // Bad. -$y = $_SERVER['REQUEST_URI']; // ok +$y = $_SERVER['REQUEST_URI']; // Ok. diff --git a/WordPress/Tests/VIP/RestrictedVariablesUnitTest.php b/WordPress/Tests/VIP/RestrictedVariablesUnitTest.php index 20b8fb0143..b7d0e0b6b2 100644 --- a/WordPress/Tests/VIP/RestrictedVariablesUnitTest.php +++ b/WordPress/Tests/VIP/RestrictedVariablesUnitTest.php @@ -2,33 +2,23 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. + * Unit test class for the VIP_RestrictedVariables sniff. * - * @category PHP - * @package PHP_CodeSniffer - * @author Akeda Bagus - * @author Greg Sherwood - * @author Marc McIntyre - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 0.3.0 */ class WordPress_Tests_VIP_RestrictedVariablesUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -38,15 +28,12 @@ public function getErrorList() { 9 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array( @@ -55,6 +42,6 @@ public function getWarningList() { 17 => 1, ); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.php b/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.php index 8516abd709..0f2c70fd07 100644 --- a/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.php +++ b/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.php @@ -2,47 +2,39 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * Unit test class for the PHP Session functions usage + * Unit test class for the SessionFunctionsUsage sniff. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 0.3.0 */ class WordPress_Tests_VIP_SessionFunctionsUsageUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( 3 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/VIP/SessionVariableUsageUnitTest.php b/WordPress/Tests/VIP/SessionVariableUsageUnitTest.php index c6cc975887..102afe5a54 100644 --- a/WordPress/Tests/VIP/SessionVariableUsageUnitTest.php +++ b/WordPress/Tests/VIP/SessionVariableUsageUnitTest.php @@ -2,28 +2,23 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * WordPress_Tests_VIP_SessionVariableUsageUnitTest + * Unit test class for the SessionVariableUsage sniff. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 0.3.0 */ class WordPress_Tests_VIP_SessionVariableUsageUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -31,19 +26,16 @@ public function getErrorList() { 4 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/VIP/SlowDBQueryUnitTest.php b/WordPress/Tests/VIP/SlowDBQueryUnitTest.php index 07b3b00a9b..57a0c4b5e8 100644 --- a/WordPress/Tests/VIP/SlowDBQueryUnitTest.php +++ b/WordPress/Tests/VIP/SlowDBQueryUnitTest.php @@ -2,41 +2,33 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. + * Unit test class for the SlowDBQuery sniff. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @package WPCS\WordPressCodingStandards + * @since 0.3.0 */ class WordPress_Tests_VIP_SlowDBQueryUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array(); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array( @@ -48,6 +40,6 @@ public function getWarningList() { 30 => 1, ); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/VIP/SuperGlobalInputUsageUnitTest.inc b/WordPress/Tests/VIP/SuperGlobalInputUsageUnitTest.inc index 19150dd26c..ecb1315625 100644 --- a/WordPress/Tests/VIP/SuperGlobalInputUsageUnitTest.inc +++ b/WordPress/Tests/VIP/SuperGlobalInputUsageUnitTest.inc @@ -2,7 +2,7 @@ foo( $_GET['bar'] ); -foo( $_GET['whitelisted'] ); // input var okay +foo( $_GET['whitelisted'] ); // Input var okay. foo( $_POST['whitelisted_with_prefix'] ); // WPCS: input var okay. @@ -10,13 +10,11 @@ if ( $_GET['test'] && foo() && $bar ) { // input var okay taz(); } -bar( $_POST['foo'] ); // warning +bar( $_POST['foo'] ); // Warning. -quux( $_REQUEST['quux'] ); // warning +quux( $_REQUEST['quux'] ); // Warning. -$_REQUEST['wp_customize'] = 'on'; // ok +$_REQUEST['wp_customize'] = 'on'; // Ok. // Issue: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/542 if ( isset( $_GET['updated'] ) ) { // input var okay ?> - - - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 0.3.0 */ class WordPress_Tests_VIP_SuperGlobalInputUsageUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array(); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array( @@ -44,6 +36,6 @@ public function getWarningList() { 13 => 1, 15 => 1, ); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/VIP/TimezoneChangeUnitTest.inc b/WordPress/Tests/VIP/TimezoneChangeUnitTest.inc index f0de5d8c4f..4e38791f9b 100644 --- a/WordPress/Tests/VIP/TimezoneChangeUnitTest.inc +++ b/WordPress/Tests/VIP/TimezoneChangeUnitTest.inc @@ -1,6 +1,6 @@ setTimezone( new DateTimeZone( 'America/Toronto' ) ); // Yay! diff --git a/WordPress/Tests/VIP/TimezoneChangeUnitTest.php b/WordPress/Tests/VIP/TimezoneChangeUnitTest.php index 48247224a6..a88b4923b4 100644 --- a/WordPress/Tests/VIP/TimezoneChangeUnitTest.php +++ b/WordPress/Tests/VIP/TimezoneChangeUnitTest.php @@ -2,47 +2,39 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * WordPress_Tests_VIP_TimezoneChangeUnitTest + * Unit test class for the TimezoneChange sniff. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 0.3.0 */ class WordPress_Tests_VIP_TimezoneChangeUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( 3 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.inc b/WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.inc index 4659c0e39c..0249040471 100644 --- a/WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.inc +++ b/WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.inc @@ -1,13 +1,13 @@ $value ) { // .. } -unset( $_GET['test'] ); // ok +unset( $_GET['test'] ); // Ok. -output( "some string {$_POST['some_var']}" ); // Bad +output( "some string {$_POST['some_var']}" ); // Bad. -echo (int) $_GET['test']; // ok -some_func( $some_arg, (int) $_GET['test'] ); // ok +echo (int) $_GET['test']; // Ok. +some_func( $some_arg, (int) $_GET['test'] ); // Ok. function zebra() { if ( isset( $_GET['foo'], $_POST['bar'] ) ) { - echo sanitize_text_field( wp_unslash( $_POST['bar'] ) ); // ok + echo sanitize_text_field( wp_unslash( $_POST['bar'] ) ); // Ok. } } echo $_GET['test']; // WPCS: sanitization OK. -echo array_map( 'sanitize_text_field', wp_unslash( $_GET['test'] ) ); // OK -echo array_map( 'foo', wp_unslash( $_GET['test'] ) ); // Bad -echo array_map( $something, wp_unslash( $_GET['test'] ) ); // Bad -echo array_map( array( $obj, 'func' ), wp_unslash( $_GET['test'] ) ); // Bad -echo array_map( array( $obj, 'sanitize_text_field' ), wp_unslash( $_GET['test'] ) ); // Bad +echo array_map( 'sanitize_text_field', wp_unslash( $_GET['test'] ) ); // Ok. +echo array_map( 'foo', wp_unslash( $_GET['test'] ) ); // Bad. +echo array_map( $something, wp_unslash( $_GET['test'] ) ); // Bad. +echo array_map( array( $obj, 'func' ), wp_unslash( $_GET['test'] ) ); // Bad. +echo array_map( array( $obj, 'sanitize_text_field' ), wp_unslash( $_GET['test'] ) ); // Bad. // Sanitized but not validated. -$foo = (int) $_POST['foo6']; // Bad +$foo = (int) $_POST['foo6']; // Bad. // Non-assignment checks are OK. -if ( 'bar' === $_POST['foo'] ) {} // OK -if ( $_GET['test'] != 'a' ) {} // OK -if ( 'bar' === do_something( wp_unslash( $_POST['foo'] ) ) ) {} // Bad +if ( 'bar' === $_POST['foo'] ) {} // Ok. +if ( $_GET['test'] != 'a' ) {} // Ok. +if ( 'bar' === do_something( wp_unslash( $_POST['foo'] ) ) ) {} // Bad. -switch ( $_POST['foo'] ) {} // OK -switch ( do_something( wp_unslash( $_POST['foo'] ) ) ) {} // Bad +switch ( $_POST['foo'] ) {} // Ok. +switch ( do_something( wp_unslash( $_POST['foo'] ) ) ) {} // Bad. // Sanitization is required even when the value is being escaped. -echo esc_html( wp_unslash( $_POST['foo'] ) ); // Bad -echo esc_html( sanitize_text_field( wp_unslash( $_POST['foo'] ) ) ); // OK +echo esc_html( wp_unslash( $_POST['foo'] ) ); // Bad. +echo esc_html( sanitize_text_field( wp_unslash( $_POST['foo'] ) ) ); // Ok. -$current_tax_slug = isset( $_GET['a'] ) ? sanitize_key( $_GET['a'] ) : false; // OK +$current_tax_slug = isset( $_GET['a'] ) ? sanitize_key( $_GET['a'] ) : false; // Ok. $current_tax_slug = isset( $_GET['a'] ) ? $_GET['a'] : false; // Bad x 2 -$current_tax_slug = isset( $_GET['a'] ) ? wp_unslash( $_GET['a'] ) : false; // Bad -$current_tax_slug = isset( $_GET['a'] ) ? sanitize_text_field( wp_unslash( $_GET['a'] ) ) : false; // OK +$current_tax_slug = isset( $_GET['a'] ) ? wp_unslash( $_GET['a'] ) : false; // Bad. +$current_tax_slug = isset( $_GET['a'] ) ? sanitize_text_field( wp_unslash( $_GET['a'] ) ) : false; // Ok. -echo sanitize_text_field( $_POST['foo545'] ); // Error for no validation, unslashing -echo array_map( 'sanitize_text_field', $_GET['test'] ); // Bad, no unslashing -echo array_map( 'sanitize_key', $_GET['test'] ); // OK +echo sanitize_text_field( $_POST['foo545'] ); // Error for no validation, unslashing. +echo array_map( 'sanitize_text_field', $_GET['test'] ); // Bad, no unslashing. +echo array_map( 'sanitize_key', $_GET['test'] ); // Ok. -foo( absint( $_GET['foo'] ) ); // OK -$ids = array_map( 'absint', $_GET['test'] ); // OK +foo( absint( $_GET['foo'] ) ); // Ok. +$ids = array_map( 'absint', $_GET['test'] ); // Ok. -if ( is_array( $_GET['test'] ) ) {} // OK +if ( is_array( $_GET['test'] ) ) {} // Ok. -output( "some string \$_POST[some_var]" ); // Ok -output( "some string \\$_POST[some_var] $_GET[evil]" ); // Bad 2 +output( "some string \$_POST[some_var]" ); // Ok. +output( "some string \\$_POST[some_var] $_GET[evil]" ); // Bad x2. diff --git a/WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.php b/WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.php index 1313dcd1f9..9b9cc8f113 100644 --- a/WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.php +++ b/WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.php @@ -2,28 +2,23 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * Unit test class for the ValidatedSanitizedInputSniff + * Unit test class for the ValidatedSanitizedInput sniff. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 0.3.0 */ class WordPress_Tests_VIP_ValidatedSanitizedInputUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -48,19 +43,16 @@ public function getErrorList() { 114 => 2, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/Variables/GlobalVariablesUnitTest.inc b/WordPress/Tests/Variables/GlobalVariablesUnitTest.inc index 30e3cd8310..4535a7bcc1 100644 --- a/WordPress/Tests/Variables/GlobalVariablesUnitTest.inc +++ b/WordPress/Tests/Variables/GlobalVariablesUnitTest.inc @@ -6,4 +6,4 @@ global $wpdb; $wpdb = 'test'; global $post; -$post = get_post( 1 ); // override ok \ No newline at end of file +$post = get_post( 1 ); // Override ok. \ No newline at end of file diff --git a/WordPress/Tests/Variables/GlobalVariablesUnitTest.php b/WordPress/Tests/Variables/GlobalVariablesUnitTest.php index 2881082b4a..dee8ca0fcf 100644 --- a/WordPress/Tests/Variables/GlobalVariablesUnitTest.php +++ b/WordPress/Tests/Variables/GlobalVariablesUnitTest.php @@ -2,28 +2,23 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. + * Unit test class for the GlobalVariables sniff. * - * @category PHP - * @package WordPress_Coding_Standards - * @author Shady Sharaf + * @package WPCS\WordPressCodingStandards + * @since 0.3.0 */ class WordPress_Tests_Variables_GlobalVariablesUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -31,19 +26,16 @@ public function getErrorList() { 6 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/Variables/VariableRestrictionsUnitTest.inc b/WordPress/Tests/Variables/VariableRestrictionsUnitTest.inc index 1e171ec302..0038124db3 100644 --- a/WordPress/Tests/Variables/VariableRestrictionsUnitTest.inc +++ b/WordPress/Tests/Variables/VariableRestrictionsUnitTest.inc @@ -1,25 +1,25 @@ bar ); // Matches: '$foo->bar' +test( $foo->bar ); // Matches: '$foo->bar'. -$foo->bar(); // Ignored, this is a function not a variable +$foo->bar(); // Ignored, this is a function not a variable. -$foo->bar_method(); // Ignored +$foo->bar_method(); // Ignored. -FOO::var; // Matches: 'FOO::var' +FOO::var; // Matches: 'FOO::var'. FOO::var_test; -FOO::reg; // Matches: 'FOO::reg*' +FOO::reg; // Matches: 'FOO::reg*'. -FOO::regex; // Matches: 'FOO::reg*' +FOO::regex; // Matches: 'FOO::reg*'. -FOO::var(); // Ignored +FOO::var(); // Ignored. -FOO::$static; // Matches: 'FOO::$static' +FOO::$static; // Matches: 'FOO::$static'. -$foo['test']; // Matches: '$foo['test']' +$foo['test']; // Matches: '$foo['test']'. -$foo["test"]; // Matches: '$foo['test']' AND $foo['test'] +$foo["test"]; // Matches: '$foo['test']' AND $foo['test']. diff --git a/WordPress/Tests/Variables/VariableRestrictionsUnitTest.php b/WordPress/Tests/Variables/VariableRestrictionsUnitTest.php index 930a003bdb..9684a9a819 100644 --- a/WordPress/Tests/Variables/VariableRestrictionsUnitTest.php +++ b/WordPress/Tests/Variables/VariableRestrictionsUnitTest.php @@ -2,21 +2,22 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. + * Unit test class for the VariableRestrictions sniff. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @package WPCS\WordPressCodingStandards + * @since 0.3.0 */ class WordPress_Tests_Variables_VariableRestrictionsUnitTest extends AbstractSniffUnitTest { + /** + * Fill in the $groups property to test the abstract class. + */ protected function setUp() { parent::setUp(); @@ -43,10 +44,7 @@ protected function setUp() { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -59,19 +57,16 @@ public function getErrorList() { 23 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/WP/EnqueuedResourcesUnitTest.php b/WordPress/Tests/WP/EnqueuedResourcesUnitTest.php index 24dfec7f35..31255edea5 100644 --- a/WordPress/Tests/WP/EnqueuedResourcesUnitTest.php +++ b/WordPress/Tests/WP/EnqueuedResourcesUnitTest.php @@ -2,17 +2,16 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Unit test class for the EnqueuedResources sniff. * - * @category PHP - * @package PHP_CodeSniffer - * @author Shady Sharaf + * @package WPCS\WordPressCodingStandards + * @since 0.3.0 */ class WordPress_Tests_WP_EnqueuedResourcesUnitTest extends AbstractSniffUnitTest { @@ -30,10 +29,7 @@ protected function shouldSkipTest() { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -45,19 +41,16 @@ public function getErrorList() { 11 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/WP/I18nUnitTest.inc b/WordPress/Tests/WP/I18nUnitTest.inc index 2a881d88f6..9743060a06 100644 --- a/WordPress/Tests/WP/I18nUnitTest.inc +++ b/WordPress/Tests/WP/I18nUnitTest.inc @@ -1,46 +1,46 @@ + * @package WPCS\WordPressCodingStandards + * @since 0.10.0 */ class WordPress_Tests_WP_I18nUnitTest extends AbstractSniffUnitTest { + /** + * Fill in the $text_domain_override property to test domain check functionality. + */ protected function setUp() { // @todo Should be possible via self::$phpcs->setSniffProperty( 'WordPress_Sniffs_WP_I18nSniff', 'text_domain', 'my-slug' ); WordPress_Sniffs_WP_I18nSniff::$text_domain_override = 'my-slug'; @@ -25,10 +27,7 @@ protected function setUp() { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -87,10 +86,7 @@ public function getErrorList() { /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array( @@ -101,6 +97,6 @@ public function getWarningList() { 102 => 1, 103 => 1, ); - } // end getWarningList() + } -} // end class. +} // End class. diff --git a/WordPress/Tests/WP/PreparedSQLUnitTest.inc b/WordPress/Tests/WP/PreparedSQLUnitTest.inc index db3d5289ea..ff20f58be8 100644 --- a/WordPress/Tests/WP/PreparedSQLUnitTest.inc +++ b/WordPress/Tests/WP/PreparedSQLUnitTest.inc @@ -1,26 +1,26 @@ query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '" . $_GET['title'] . "';" ); // Bad -$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '{$_GET['title']}';" ); // Bad -$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '$var';" ); // Bad -$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE 'Hello World!';" ); // OK -$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '{$_GET['title']}';" ) ); // Bad -$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '$var';" ) ); // Bad -$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title LIKE %s;", $_GET['title'] ) ); // OK +$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '" . $_GET['title'] . "';" ); // Bad. +$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '{$_GET['title']}';" ); // Bad. +$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '$var';" ); // Bad. +$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE 'Hello World!';" ); // Ok. +$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '{$_GET['title']}';" ) ); // Bad. +$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '$var';" ) ); // Bad. +$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title LIKE %s;", $_GET['title'] ) ); // Ok. $wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '" . $escaped_var . "';" ); // WPCS: unprepared SQL OK. $wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '{$escaped_var}';" ); // WPCS: unprepared SQL OK. -$wpdb->query( $wpdb->prepare( "SELECT SUBSTRING( post_name, %d + 1 ) REGEXP '^[0-9]+$'", array( 123 ) ) ); // OK -$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title = 'The \$_GET var can be evil.' AND ID = %s", array( 123 ) ) ); // OK -$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title = 'The $_GET[foo] var is evil.' AND ID = %s", array( 123 ) ) ); // Bad -$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title = 'The \\$_GET[foo]// var is evil again.' AND ID = %s", array( 123 ) ) ); // Bad -$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title = 'The \$_GET var can be evil, but $_GET[foo] var is evil.' AND ID = %s", array( 123 ) ) ); // Bad +$wpdb->query( $wpdb->prepare( "SELECT SUBSTRING( post_name, %d + 1 ) REGEXP '^[0-9]+$'", array( 123 ) ) ); // Ok. +$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title = 'The \$_GET var can be evil.' AND ID = %s", array( 123 ) ) ); // Ok. +$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title = 'The $_GET[foo] var is evil.' AND ID = %s", array( 123 ) ) ); // Bad. +$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title = 'The \\$_GET[foo]// var is evil again.' AND ID = %s", array( 123 ) ) ); // Bad. +$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title = 'The \$_GET var can be evil, but $_GET[foo] var is evil.' AND ID = %s", array( 123 ) ) ); // Bad. -$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '" . foo() . "';" ); // Bad -$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '" . foo() . "';" ) ); // Bad +$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '" . foo() . "';" ); // Bad. +$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '" . foo() . "';" ) ); // Bad. -$wpdb->query( "SELECT * FROM " . $wpdb->posts . " WHERE post_title LIKE 'foo';" ); // OK +$wpdb->query( "SELECT * FROM " . $wpdb->posts . " WHERE post_title LIKE 'foo';" ); // Ok. // All OK. $all_post_meta = $wpdb->get_results( $wpdb->prepare( sprintf( @@ -29,5 +29,5 @@ $all_post_meta = $wpdb->get_results( $wpdb->prepare( sprintf( implode( ',', array_fill( 0, count( $post_ids ), '%d' ) ) ), $post_ids ) ); -$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '" . esc_sql( $foo ) . "';" ); // OK -$wpdb->query( "SELECT * FROM $wpdb->posts WHERE ID = " . absint( $foo ) . ";" ); // OK +$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '" . esc_sql( $foo ) . "';" ); // Ok. +$wpdb->query( "SELECT * FROM $wpdb->posts WHERE ID = " . absint( $foo ) . ";" ); // Ok. diff --git a/WordPress/Tests/WP/PreparedSQLUnitTest.php b/WordPress/Tests/WP/PreparedSQLUnitTest.php index 74aa6e6eb8..6058ae70d0 100644 --- a/WordPress/Tests/WP/PreparedSQLUnitTest.php +++ b/WordPress/Tests/WP/PreparedSQLUnitTest.php @@ -2,20 +2,25 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Unit test class for the PreparedSQL sniff. * - * @since 0.8.0 + * @package WPCS\WordPressCodingStandards + * @since 0.8.0 */ class WordPress_Tests_WP_PreparedSQLUnitTest extends AbstractSniffUnitTest { /** + * Returns the lines where errors should occur. + * * @since 0.8.0 + * + * @return array => */ public function getErrorList() { return array( @@ -30,13 +35,18 @@ public function getErrorList() { 20 => 1, 21 => 1, ); - } // end getErrorList() + } /** + * Returns the lines where warnings should occur. + * * @since 0.8.0 + * + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() -} // end class. + } + +} // End class. diff --git a/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.inc b/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.inc index 2601356fa2..f718db10e5 100644 --- a/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.inc +++ b/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.inc @@ -7,7 +7,7 @@ $bool1 = (bool)$bool; $bool2 = (bool) $bool; $int1 = (int)$int; -$int2 = (int) $int +$int2 = (int) $int; $obj1 = ( object )$object; $obj2 = (object) $object; diff --git a/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.php index a78556f889..28bf974b43 100644 --- a/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.php +++ b/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.php @@ -2,46 +2,33 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Unit test class for the CastStructureSpacing sniff. * - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Matt Robinson - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 0.3.0 */ class WordPress_Tests_WhiteSpace_CastStructureSpacingUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array(); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array( @@ -54,6 +41,6 @@ public function getWarningList() { 21 => 1, ); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc index 076a4d744b..e5216cb8c8 100644 --- a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc +++ b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc @@ -1,31 +1,31 @@ - * @author Greg Sherwood - * @author Marc McIntyre - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 2013-06-11 */ class WordPress_Tests_WhiteSpace_ControlStructureSpacingUnitTest extends AbstractSniffUnitTest { @@ -38,10 +29,7 @@ protected function shouldSkipTest() { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { $ret = array( @@ -69,8 +57,9 @@ public function getErrorList() { 98 => 1, ); - // Uncomment when "$blank_line_check" parameter will be "true" by default. /* + Uncomment when "$blank_line_check" parameter will be "true" by default. + $ret[29] += 1; $ret[33] = 1; $ret[36] = 1; @@ -84,14 +73,11 @@ public function getErrorList() { /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc b/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc index 82162e874c..bee440f694 100644 --- a/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc +++ b/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc @@ -1,20 +1,20 @@ - * @author Greg Sherwood - * @author Marc McIntyre - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 2013-06-11 */ class WordPress_Tests_WhiteSpace_OperatorSpacingUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -40,19 +28,16 @@ public function getErrorList() { 49 => 1, ); - } // end getErrorList() + } /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/WordPress/Tests/XSS/EscapeOutputUnitTest.inc b/WordPress/Tests/XSS/EscapeOutputUnitTest.inc index 0adf1ebf8b..c009fe2349 100644 --- a/WordPress/Tests/XSS/EscapeOutputUnitTest.inc +++ b/WordPress/Tests/XSS/EscapeOutputUnitTest.inc @@ -1,25 +1,25 @@ -

-

-

+

+

+

'; -echo ent2ncr( $text ); // Bad +echo ent2ncr( $text ); // Bad. echo number_format( 1024 ); echo ent2ncr( esc_html( $_data ) ); -echo $foo ? $foo : 'no foo'; // Bad -echo empty( $foo ) ? 'no foo' : $foo; // Bad -echo $foo ? esc_html( $foo ) : 'no foo'; // OK +echo $foo ? $foo : 'no foo'; // Bad. +echo empty( $foo ) ? 'no foo' : $foo; // Bad. +echo $foo ? esc_html( $foo ) : 'no foo'; // Ok. -echo 4; // OK +echo 4; // Ok. -exit( $foo ); // Bad -exit( esc_html( $foo ) ); // OK +exit( $foo ); // Bad. +exit( esc_html( $foo ) ); // Ok. -die( $foo ); // Bad -die( esc_html( $foo ) ); // OK +die( $foo ); // Bad. +die( esc_html( $foo ) ); // Ok. -printf( 'Hello %s', $foo ); // Bad -printf( 'Hello %s', esc_html( $foo ) ); // OK -printf( 'Hello %s! Hi %s!', esc_html( $foo ), $bar ); // Bad +printf( 'Hello %s', $foo ); // Bad. +printf( 'Hello %s', esc_html( $foo ) ); // Ok. +printf( 'Hello %s! Hi %s!', esc_html( $foo ), $bar ); // Bad. -vprintf( 'Hello %s', array( $foo ) ); // Bad -vprintf( 'Hello %s', array( esc_html( $foo ) ) ); // OK +vprintf( 'Hello %s', array( $foo ) ); // Bad. +vprintf( 'Hello %s', array( esc_html( $foo ) ) ); // Ok. // The below checks that functions which are marked as needed further sanitization // don't spill over into later arguments when nested in a function call. There was @@ -81,12 +81,12 @@ vprintf( 'Hello %s', array( esc_html( $foo ) ) ); // OK // is marked as needing sanitization. do_something( _x( 'Some string', 'context', 'domain' ) - , array( $foo ) // OK + , array( $foo ) // Ok. ); // There was a bug where an empty exit followed by other code would give an error. if ( ! defined( 'ABSPATH' ) ) { - exit; // OK + exit; // Ok. } else { other(); } @@ -98,85 +98,85 @@ printf( // There were other long arguments down here "in real life", which is why this was multi-line. ); -wp_die( $message ); // Bad -wp_die( esc_html( $message ) ); // OK -wp_die( esc_html( $message ), $title ); // Bad -wp_die( esc_html( $message ), esc_html( $title ) ); // OK -wp_die( esc_html( $message ), '', array( 'back_link' => true ) ); // OK -wp_die( esc_html( $message ), '', array( 'back_link' => false ) ); // OK -wp_die( esc_html( $message ), '', array( 'response' => 200 ) ); // OK +wp_die( $message ); // Bad. +wp_die( esc_html( $message ) ); // Ok. +wp_die( esc_html( $message ), $title ); // Bad. +wp_die( esc_html( $message ), esc_html( $title ) ); // Ok. +wp_die( esc_html( $message ), '', array( 'back_link' => true ) ); // Ok. +wp_die( esc_html( $message ), '', array( 'back_link' => false ) ); // Ok. +wp_die( esc_html( $message ), '', array( 'response' => 200 ) ); // Ok. -echo '

', esc_html( $foo ), '

'; // OK -echo 'a', 'b'; // OK -echo 'Hello, ', $foo; // Bad -echo esc_html( $foo ), $bar; // Bad -echo (int) $foo, $bar; // Bad -echo (int) get_post_meta( $post_id, SOME_NUMBER, true ), do_something( $else ); // Bad +echo '

', esc_html( $foo ), '

'; // Ok. +echo 'a', 'b'; // Ok. +echo 'Hello, ', $foo; // Bad. +echo esc_html( $foo ), $bar; // Bad. +echo (int) $foo, $bar; // Bad. +echo (int) get_post_meta( $post_id, SOME_NUMBER, true ), do_something( $else ); // Bad. -wp_die( -1 ); // OK +wp_die( -1 ); // Ok. ?> -

- - +

+ + ' . sprintf( esc_html__( 'Some text -> %sLink text%s', 'textdomain' ), '', '' ). '

'; // OK +echo '

' . sprintf( esc_html__( 'Some text -> %sLink text%s', 'textdomain' ), '', '' ). '

'; // Ok. -echo '
' . sprintf( esc_html__( 'Found %d results', 'textdomain' ), (int) $result_count ) . '

'; // OK +echo '
' . sprintf( esc_html__( 'Found %d results', 'textdomain' ), (int) $result_count ) . '

'; // Ok. -echo sprintf( 'Hello %s', $foo ); // Bad -echo sprintf( 'Hello %s', esc_html( $foo ) ); // OK -echo sprintf( 'Hello %s! Hi %s!', esc_html( $foo ), $bar ); // Bad +echo sprintf( 'Hello %s', $foo ); // Bad. +echo sprintf( 'Hello %s', esc_html( $foo ) ); // Ok. +echo sprintf( 'Hello %s! Hi %s!', esc_html( $foo ), $bar ); // Bad. -echo vsprintf( 'Hello %s', array( $foo ) ); // Bad -echo vsprintf( 'Hello %s', array( esc_html( $foo ) ) ); // OK +echo vsprintf( 'Hello %s', array( $foo ) ); // Bad. +echo vsprintf( 'Hello %s', array( esc_html( $foo ) ) ); // Ok. -echo sprintf( __( 'Welcome to Genesis %s', 'genesis' ), PARENT_THEME_BRANCH ); // Bad x 2 -echo sprintf( esc_html__( 'Welcome to Genesis %s', 'genesis' ), esc_html( PARENT_THEME_BRANCH ) ); // OK +echo sprintf( __( 'Welcome to Genesis %s', 'genesis' ), PARENT_THEME_BRANCH ); // Bad x 2. +echo sprintf( esc_html__( 'Welcome to Genesis %s', 'genesis' ), esc_html( PARENT_THEME_BRANCH ) ); // Ok. -echo esc_html( strval( $_var ) ? $_var : gettype( $_var ) ); // OK -echo ( $is_hidden ) ? ' style="display:none;"' : ''; // OK -echo sprintf( 'Howdy, %s', esc_html( $name ? $name : __( 'Partner' ) ) ); // OK +echo esc_html( strval( $_var ) ? $_var : gettype( $_var ) ); // Ok. +echo ( $is_hidden ) ? ' style="display:none;"' : ''; // Ok. +echo sprintf( 'Howdy, %s', esc_html( $name ? $name : __( 'Partner' ) ) ); // Ok. -_e( 'Something' ); // Bad -esc_html_e( 'Something' ); // OK +_e( 'Something' ); // Bad. +esc_html_e( 'Something' ); // Ok. -echo $something // Bad - . esc_attr( 'baz-' // Rest is OK +echo $something // Bad. + . esc_attr( 'baz-' // Rest is OK. . $r . ( $r === $active_round ? ' foo' : '' ) . ( $r < $active_round ? ' bar' : '' ) ) . 'something'; -echo implode( '
', $items ); // Bad -echo implode( '
', urlencode_deep( $items ) ); // OK -echo implode( '
', array_map( 'esc_html', $items ) ); // OK -echo implode( '
', array_map( 'foo', $items ) ); // Bad -echo join( '
', $items ); // Bad -echo join( '
', array_map( 'esc_html', $items ) ); // OK +echo implode( '
', $items ); // Bad. +echo implode( '
', urlencode_deep( $items ) ); // Ok. +echo implode( '
', array_map( 'esc_html', $items ) ); // Ok. +echo implode( '
', array_map( 'foo', $items ) ); // Bad. +echo join( '
', $items ); // Bad. +echo join( '
', array_map( 'esc_html', $items ) ); // Ok. echo ''; -_deprecated_hook( 'some_filter', '1.3.0', esc_html__( 'The $arg is deprecated.' ), 'some_other_filter' ); // OK -_deprecated_hook( "filter_{$context}", '1.3.0', __( 'The $arg is deprecated.' ), sprintf( __( 'Some parsed message %s', $variable ) ) ); // Bad +_deprecated_hook( 'some_filter', '1.3.0', esc_html__( 'The $arg is deprecated.' ), 'some_other_filter' ); // Ok. +_deprecated_hook( "filter_{$context}", '1.3.0', __( 'The $arg is deprecated.' ), sprintf( __( 'Some parsed message %s', $variable ) ) ); // Bad. diff --git a/WordPress/Tests/XSS/EscapeOutputUnitTest.php b/WordPress/Tests/XSS/EscapeOutputUnitTest.php index 3d6bae14b8..31ddd3e57a 100644 --- a/WordPress/Tests/XSS/EscapeOutputUnitTest.php +++ b/WordPress/Tests/XSS/EscapeOutputUnitTest.php @@ -2,35 +2,23 @@ /** * Unit test class for WordPress Coding Standard. * - * @category PHP - * @package PHP_CodeSniffer - * @link https://make.wordpress.org/core/handbook/best-practices/coding-standards/ + * @package WPCS\WordPressCodingStandards + * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + * @license https://opensource.org/licenses/MIT MIT */ /** * Unit test class for the EscapeOutput sniff. * - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Akeda Bagus - * @author Greg Sherwood - * @author Marc McIntyre - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * @package WPCS\WordPressCodingStandards + * @since 2013-06-11 */ class WordPress_Tests_XSS_EscapeOutputUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getErrorList() { return array( @@ -77,14 +65,11 @@ public function getErrorList() { /** * Returns the lines where warnings should occur. * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) + * @return array => */ public function getWarningList() { return array(); - } // end getWarningList() + } -} // end class +} // End class. diff --git a/bin/phpcs.xml b/bin/phpcs.xml index aa8ec9d7fc..f6a7e6e234 100644 --- a/bin/phpcs.xml +++ b/bin/phpcs.xml @@ -2,11 +2,11 @@ The Coding standard for the WordPress Coding Standards itself. - + - +