-
-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Streamline WPCS in file documentation. (#651)
* Update the file and class @Package tag and remove the @category tag. Follow the standard as described in https://www.phpdoc.org/docs/latest/references/phpdoc/tags/package.html The @category tag is considered deprecated. A hierarchical @Package tag should be used instead. Ref: https://www.phpdoc.org/docs/latest/references/phpdoc/tags/category.html * Use correct version number for the newly deprecated classes. * Fix some - unintentional - parse errors in the test files. * Attempt to lead by example comment-wise in the unit tests. Capitalization, punctuation and some spelling. * Proper capitalization and punctuation for class end comments. * Remove `//end` comments for methods and conditionals < 35 lines. * Simplify the test file method doc blocks. * Various documentation fixes, largely based on PHPCS Docs output. * Make sure any function which will be passed the $phpcsFile has the right type hint. But only if it doesn't conflict with upstream function signatures. * Verify and update the docblocks for all files and classes. Based on Git file history: * Add @SInCE tags to all classes. * Add @SInCE tags to properties and methods if they weren't included from the start. * Verify/Fix a number of @author tags. * Remove old/copied over/incorrect PHPCS tags. * Where necessary improved/corrected the class description. Also: * Consistent tag order in class doc blocks. * Fix tag alignment. * Remove redundant explanation in unit test class doc blocks. * Sync the description line of the unit test class doc blocks. * Add handbook links to a number of sniffs. * Add reference to upstream sniff a sniff is based upon. Includes information on when the sniff was last synced with the upstream sniff if applicable and available. * Add @license tag and @link tag to the WPCS GH repo, to all file level doc blocks. License tag as per https://www.phpdoc.org/docs/latest/references/phpdoc/tags/license.html * Add the docs ruleset to the coding standard for WPCS itself. * Add @SInCE class changelogs for PR #647. * Fix minor grammar error. * Updated `@since` tags for `2014-12-11` release to `0.3.0`. * Re-instate previously removed @SInCE tags. * Updated based on feedback. * Adjusted the @Package tags as per discussion in the PR thread * Removed the @link tag to the handbook at the file level doc block * Removed the @author tags
- Loading branch information
1 parent
1939480
commit f60bfe5
Showing
133 changed files
with
1,950 additions
and
2,237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]> | ||
* @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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]> | ||
* @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,17 +248,17 @@ 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 ); | ||
|
||
return $namespace; | ||
} | ||
|
||
} // end class | ||
} // End class. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]> | ||
* @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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]> | ||
* @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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.