Skip to content

Commit

Permalink
Merge pull request #826 from Automattic/feature/docs-improve-specificity
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryJones authored Nov 8, 2024
2 parents 6e53ed0 + 97d83d5 commit ff4acee
Show file tree
Hide file tree
Showing 42 changed files with 79 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ abstract class AbstractVariableRestrictionsSniff extends Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
* @return array<int|string>
*/
public function register() {
// Retrieve the groups only once and don't set up a listener if there are no groups.
Expand Down Expand Up @@ -91,7 +91,7 @@ public function register() {
* )
* )
*
* @return array
* @return array<string, array<string, string|array<string>>>
*/
abstract public function getGroups();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DeclarationCompatibilitySniff extends AbstractScopeSniff {
/**
* A list of classes and methods to check.
*
* @var array<string, array<string, array<string, mixed>>>
* @var array<string, array<string, array<int|string, string|array<string, bool|string>>>>
*/
public $checkClasses = [
'WP_Widget' => [
Expand Down Expand Up @@ -315,7 +315,7 @@ private function addError( $parentClassName, $methodName, $currentMethodSignatur
*
* @param array $methodSignature Signature of a method.
*
* @return array
* @return array<string>
*/
private function generateParamList( $methodSignature ) {
$paramList = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RestrictedExtendClassesSniff extends AbstractClassRestrictionsSniff {
/**
* Groups of classes to restrict.
*
* @return array
* @return array<string, array<string, string|array<string>>>
*/
public function getGroups() {
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ConstantStringSniff extends Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
* @return array<int|string>
*/
public function register() {
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RestrictedConstantsSniff extends Sniff {
/**
* List of restricted constant names.
*
* @var array
* @var array<string>
*/
public $restrictedConstantNames = [
'A8C_PROXIED_REQUEST',
Expand All @@ -28,7 +28,7 @@ class RestrictedConstantsSniff extends Sniff {
/**
* List of restricted constant declarations.
*
* @var array
* @var array<string>
*/
public $restrictedConstantDeclaration = [
'JETPACK_DEV_DEBUG',
Expand All @@ -38,7 +38,7 @@ class RestrictedConstantsSniff extends Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
* @return array<int|string>
*/
public function register() {
return [
Expand Down
12 changes: 6 additions & 6 deletions WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class IncludingFileSniff extends AbstractFunctionRestrictionsSniff {
/**
* List of function used for getting paths.
*
* @var array
* @var array<string>
*/
public $getPathFunctions = [
'dirname',
Expand Down Expand Up @@ -55,7 +55,7 @@ class IncludingFileSniff extends AbstractFunctionRestrictionsSniff {
/**
* List of restricted constants.
*
* @var array
* @var array<string, string>
*/
public $restrictedConstants = [
'TEMPLATEPATH' => 'get_template_directory',
Expand All @@ -65,7 +65,7 @@ class IncludingFileSniff extends AbstractFunctionRestrictionsSniff {
/**
* List of allowed constants.
*
* @var array
* @var array<string>
*/
public $allowedConstants = [
'ABSPATH',
Expand All @@ -77,7 +77,7 @@ class IncludingFileSniff extends AbstractFunctionRestrictionsSniff {
* List of keywords allowed for use in custom constants.
* Note: Customizing this property will overwrite current default values.
*
* @var array
* @var array<string>
*/
public $allowedKeywords = [
'PATH',
Expand All @@ -87,7 +87,7 @@ class IncludingFileSniff extends AbstractFunctionRestrictionsSniff {
/**
* Functions used for modify slashes.
*
* @var array
* @var array<string>
*/
public $slashingFunctions = [
'trailingslashit',
Expand All @@ -107,7 +107,7 @@ public function getGroups() {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
* @return array<int|string>
*/
public function register() {
return Tokens::$includeTokens;
Expand Down
6 changes: 3 additions & 3 deletions WordPressVIPMinimum/Sniffs/Files/IncludingNonPHPFileSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class IncludingNonPHPFileSniff extends Sniff {
*
* Files with these extensions are allowed to be `include`d.
*
* @var array Key is the extension, value is irrelevant.
* @var array<string, bool> Key is the extension, value is irrelevant.
*/
private $php_extensions = [
'php' => true,
Expand All @@ -34,7 +34,7 @@ class IncludingNonPHPFileSniff extends Sniff {
/**
* File extensions used for SVG and CSS files.
*
* @var array Key is the extension, value is irrelevant.
* @var array<string, bool> Key is the extension, value is irrelevant.
*/
private $svg_css_extensions = [
'css' => true,
Expand All @@ -44,7 +44,7 @@ class IncludingNonPHPFileSniff extends Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
* @return array<int|string>
*/
public function register() {
return Tokens::$includeTokens;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CheckReturnValueSniff extends Sniff {
/**
* Pairs we are about to check.
*
* @var array
* @var array<string, array<string>>
*/
public $catch = [
'esc_url' => [
Expand All @@ -48,7 +48,7 @@ class CheckReturnValueSniff extends Sniff {
/**
* Tokens we are about to examine, which are not functions.
*
* @var array
* @var array<string, int|string>
*/
public $notFunctions = [
'foreach' => T_FOREACH,
Expand All @@ -57,7 +57,7 @@ class CheckReturnValueSniff extends Sniff {
/**
* Returns the token types that this sniff is interested in.
*
* @return array(int)
* @return array<int|string>
*/
public function register() {
return [ T_STRING ];
Expand Down Expand Up @@ -293,7 +293,7 @@ public function findNonCheckedVariables( $stackPtr ) {
* Function used as as callback for the array_reduce call.
*
* @param string|null $carry The final string.
* @param mixed $item Processed item.
* @param array $item Processed item.
*
* @return string
*/
Expand Down
6 changes: 3 additions & 3 deletions WordPressVIPMinimum/Sniffs/Functions/DynamicCallsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DynamicCallsSniff extends Sniff {
/**
* Functions that should not be called dynamically.
*
* @var array
* @var array<string, bool>
*/
private $disallowed_functions = [
'assert' => true,
Expand All @@ -48,7 +48,7 @@ class DynamicCallsSniff extends Sniff {
*
* Populated at run-time.
*
* @var array The key is the name of the variable, the value, its assigned value.
* @var array<string, string> The key is the name of the variable, the value, its assigned value.
*/
private $variables_arr = [];

Expand All @@ -62,7 +62,7 @@ class DynamicCallsSniff extends Sniff {
/**
* Returns the token types that this sniff is interested in.
*
* @return array(int)
* @return array<int|string>
*/
public function register() {
return [ T_VARIABLE => T_VARIABLE ];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RestrictedFunctionsSniff extends AbstractFunctionRestrictionsSniff {
/**
* Groups of functions to restrict.
*
* @return array
* @return array<string, array<string, string|array<string>|array<string, bool>>>
*/
public function getGroups() {

Expand Down
5 changes: 1 addition & 4 deletions WordPressVIPMinimum/Sniffs/Functions/StripTagsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ class StripTagsSniff extends AbstractFunctionParameterSniff {
/**
* Functions this sniff is looking for.
*
* @var array The only requirement for this array is that the top level
* array keys are the names of the functions you're looking for.
* Other than that, the array can have arbitrary content
* depending on your needs.
* @var array<string, bool> Key is the function name, value irrelevant.
*/
protected $target_functions = [
'strip_tags' => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AlwaysReturnInFilterSniff extends Sniff {
/**
* Returns the token types that this sniff is interested in.
*
* @return array(int)
* @return array<int|string>
*/
public function register() {
return [ T_STRING ];
Expand Down
2 changes: 1 addition & 1 deletion WordPressVIPMinimum/Sniffs/Hooks/PreGetPostsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PreGetPostsSniff extends Sniff {
/**
* Returns the token types that this sniff is interested in.
*
* @return array(int)
* @return array<int|string>
*/
public function register() {
return [ T_STRING ];
Expand Down
7 changes: 2 additions & 5 deletions WordPressVIPMinimum/Sniffs/Hooks/RestrictedHooksSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ class RestrictedHooksSniff extends AbstractFunctionParameterSniff {
/**
* Functions this sniff is looking for.
*
* @var array The only requirement for this array is that the top level
* array keys are the names of the functions you're looking for.
* Other than that, the array can have arbitrary content
* depending on your needs.
* @var array<string, bool> Key is the function name, value irrelevant.
*/
protected $target_functions = [
'add_filter' => true,
Expand All @@ -39,7 +36,7 @@ class RestrictedHooksSniff extends AbstractFunctionParameterSniff {
/**
* List of restricted filters by groups.
*
* @var array
* @var array<string, array<string, string|array<string>>>
*/
private $restricted_hook_groups = [
'upload_mimes' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DangerouslySetInnerHTMLSniff extends Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
* @return array<int|string>
*/
public function register() {
return [
Expand Down
4 changes: 2 additions & 2 deletions WordPressVIPMinimum/Sniffs/JS/HTMLExecutingFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class HTMLExecutingFunctionsSniff extends Sniff {
* Value indicates whether the function's arg is the content to be inserted, or the target where the inserted
* content is to be inserted before/after/replaced. For the latter, the content is in the preceding method's arg.
*
* @var array
* @var array<string, string>
*/
public $HTMLExecutingFunctions = [
'after' => 'content', // jQuery.
Expand Down Expand Up @@ -52,7 +52,7 @@ class HTMLExecutingFunctionsSniff extends Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
* @return array<int|string>
*/
public function register() {
return [
Expand Down
2 changes: 1 addition & 1 deletion WordPressVIPMinimum/Sniffs/JS/InnerHTMLSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class InnerHTMLSniff extends Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
* @return array<int|string>
*/
public function register() {
return [
Expand Down
6 changes: 3 additions & 3 deletions WordPressVIPMinimum/Sniffs/JS/StringConcatSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class StringConcatSniff extends Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
* @return array<int|string>
*/
public function register() {
return [
Expand Down Expand Up @@ -63,8 +63,8 @@ public function process_token( $stackPtr ) {
/**
* Consolidated violation.
*
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
* @param array $data Replacements for the error message.
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
* @param array<string> $data Replacements for the error message.
*
* @return void
*/
Expand Down
2 changes: 1 addition & 1 deletion WordPressVIPMinimum/Sniffs/JS/StrippingTagsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class StrippingTagsSniff extends Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
* @return array<int|string>
*/
public function register() {
return [
Expand Down
4 changes: 2 additions & 2 deletions WordPressVIPMinimum/Sniffs/JS/WindowSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class WindowSniff extends Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
* @return array<int|string>
*/
public function register() {
return [
Expand All @@ -38,7 +38,7 @@ public function register() {
/**
* List of window properties that need to be flagged.
*
* @var array
* @var array<string, bool|array<string, bool>>
*/
private $windowProperties = [
'location' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CacheValueOverrideSniff extends Sniff {
/**
* Returns the token types that this sniff is interested in.
*
* @return array(int)
* @return array<int|string>
*/
public function register() {
return [ T_STRING ];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FetchingRemoteDataSniff extends Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
* @return array<int|string>
*/
public function register() {
return [ T_STRING ];
Expand Down
Loading

0 comments on commit ff4acee

Please sign in to comment.