Skip to content

Commit

Permalink
Merge pull request #770 from Automattic/feature/more-docs-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryJones authored Aug 23, 2023
2 parents a5c9567 + 6af9e13 commit 332b8dd
Show file tree
Hide file tree
Showing 53 changed files with 161 additions and 100 deletions.
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 string[]
* @var array<string, array<string, array<string, mixed>>>
*/
public $checkClasses = [
'WP_Widget' => [
Expand Down Expand Up @@ -169,7 +169,7 @@ class DeclarationCompatibilitySniff extends AbstractScopeSniff {
/**
* List of grouped classes with same methods (as they extend the same parent class)
*
* @var string[]
* @var array<string, string[]>
*/
public $checkClassesGroups = [
'Walker' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ public function getGroups() {
* Process a matched token.
*
* @param int $stackPtr The position of the current token in the stack.
* @param array $group_name The name of the group which was matched.
* @param string $matched_content The token content (class name) which was matched.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (class name) which was matched
* in lowercase.
*
* @return void
*/
Expand Down
10 changes: 7 additions & 3 deletions WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private function isFunctionCall( $stackPtr ) {
*
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
*
* @return bool
* @return int|false
*/
private function isVariableAssignment( $stackPtr ) {

Expand Down Expand Up @@ -140,6 +140,8 @@ private function isVariableAssignment( $stackPtr ) {
* Find instances in which a function call is directly passed to another one w/o checking the return type
*
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
*
* @return void
*/
public function findDirectFunctionCalls( $stackPtr ) {

Expand Down Expand Up @@ -290,8 +292,8 @@ public function findNonCheckedVariables( $stackPtr ) {
/**
* Function used as as callback for the array_reduce call.
*
* @param string $carry The final string.
* @param array $item Processed item.
* @param string|null $carry The final string.
* @param mixed $item Processed item.
*
* @return string
*/
Expand All @@ -305,6 +307,8 @@ public function reduce_array( $carry, $item ) {
* @param int $stackPtr The position in the stack where the token was found.
* @param string $variableName Variable name.
* @param string $callee Function name.
*
* @return void
*/
private function addNonCheckedVariableError( $stackPtr, $variableName, $callee ) {
$message = 'Type of `%s` must be checked before calling `%s()` using that variable.';
Expand Down
6 changes: 4 additions & 2 deletions WordPressVIPMinimum/Sniffs/Functions/StripTagsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ class StripTagsSniff extends AbstractFunctionParameterSniff {
* Process the parameters of a matched function.
*
* @param int $stackPtr The position of the current token in the stack.
* @param array $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) which was matched.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) which was matched
* in lowercase.
* @param array $parameters Array with information about the parameters.
*
* @return int|void Integer stack pointer to skip forward or void to continue
* normal file processing.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public function process_token( $stackPtr ) {
* Process array.
*
* @param int $stackPtr The position in the stack where the token was found.
*
* @return void
*/
private function processArray( $stackPtr ) {

Expand Down Expand Up @@ -124,6 +126,8 @@ private function processArray( $stackPtr ) {
* @param int $stackPtr The position in the stack where the token was found.
* @param int $start The start of the token.
* @param int $end The end of the token.
*
* @return void
*/
private function processString( $stackPtr, $start = 0, $end = null ) {

Expand Down Expand Up @@ -151,6 +155,8 @@ private function processString( $stackPtr, $start = 0, $end = null ) {
* @param int $stackPtr The position in the stack where the token was found.
* @param int $start The start of the token.
* @param int $end The end of the token.
*
* @return void
*/
private function processFunction( $stackPtr, $start = 0, $end = null ) {

Expand All @@ -172,6 +178,8 @@ private function processFunction( $stackPtr, $start = 0, $end = null ) {
* Process function's body
*
* @param int $stackPtr The position in the stack where the token was found.
*
* @return void
*/
private function processFunctionBody( $stackPtr ) {

Expand Down
16 changes: 14 additions & 2 deletions WordPressVIPMinimum/Sniffs/Hooks/PreGetPostsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public function process_token( $stackPtr ) {
* Process array.
*
* @param int $stackPtr The position in the stack where the token was found.
*
* @return void
*/
private function processArray( $stackPtr ) {

Expand All @@ -114,6 +116,8 @@ private function processArray( $stackPtr ) {
* Process string.
*
* @param int $stackPtr The position in the stack where the token was found.
*
* @return void
*/
private function processString( $stackPtr ) {

Expand All @@ -139,6 +143,8 @@ private function processString( $stackPtr ) {
* Process function.
*
* @param int $stackPtr The position in the stack where the token was found.
*
* @return void
*/
private function processFunction( $stackPtr ) {

Expand Down Expand Up @@ -172,6 +178,8 @@ private function processFunction( $stackPtr ) {
* Process closure.
*
* @param int $stackPtr The position in the stack where the token was found.
*
* @return void
*/
private function processClosure( $stackPtr ) {

Expand All @@ -197,6 +205,8 @@ private function processClosure( $stackPtr ) {
*
* @param int $stackPtr The position in the stack where the token was found.
* @param string $variableName Variable name.
*
* @return void
*/
private function processFunctionBody( $stackPtr, $variableName ) {

Expand Down Expand Up @@ -236,6 +246,8 @@ private function processFunctionBody( $stackPtr, $variableName ) {
* Consolidated violation.
*
* @param int $stackPtr The position in the stack where the token was found.
*
* @return void
*/
private function addPreGetPostsWarning( $stackPtr ) {
$message = 'Main WP_Query is being modified without `$query->is_main_query()` check. Needs manual inspection.';
Expand Down Expand Up @@ -362,8 +374,8 @@ private function isEarlyMainQueryCheck( $stackPtr ) {
/**
* Is the current code a WP_Query call?
*
* @param int $stackPtr The position in the stack where the token was found.
* @param null $method Method.
* @param int $stackPtr The position in the stack where the token was found.
* @param string|null $method Method.
*
* @return bool
*/
Expand Down
7 changes: 5 additions & 2 deletions WordPressVIPMinimum/Sniffs/Hooks/RestrictedHooksSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ class RestrictedHooksSniff extends AbstractFunctionParameterSniff {
* Process the parameters of a matched function.
*
* @param int $stackPtr The position of the current token in the stack.
* @param array $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) which was matched.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) which was matched
* in lowercase.
* @param array $parameters Array with information about the parameters.
*
* @return int|void Integer stack pointer to skip forward or void to continue
* normal file processing.
*/
Expand All @@ -97,6 +99,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
* Normalize hook name parameter.
*
* @param array $parameter Array with information about a parameter.
*
* @return string Normalized hook name.
*/
private function normalize_hook_name_from_parameter( $parameter ) {
Expand Down
2 changes: 2 additions & 0 deletions WordPressVIPMinimum/Sniffs/JS/StringConcatSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public function process_token( $stackPtr ) {
*
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
* @param array $data Replacements for the error message.
*
* @return void
*/
private function addFoundError( $stackPtr, array $data ) {
$message = 'HTML string concatenation detected, this is a security risk, use DOM node construction or a templating language instead: %s.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private function isFunctionCall( $stackPtr ) {
*
* @param int $stackPtr The position of the current token in the stack.
*
* @return bool
* @return int|false
*/
private function isVariableAssignment( $stackPtr ) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ class LowExpiryCacheTimeSniff extends AbstractFunctionParameterSniff {
* Process the parameters of a matched function.
*
* @param int $stackPtr The position of the current token in the stack.
* @param array $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) which was matched.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) which was matched
* in lowercase.
* @param array $parameters Array with information about the parameters.
*
* @return int|void Integer stack pointer to skip forward or void to continue
* normal file processing.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ class PHPFilterFunctionsSniff extends AbstractFunctionParameterSniff {
* Process the parameters of a matched function.
*
* @param int $stackPtr The position of the current token in the stack.
* @param array $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) which was matched.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) which was matched
* in lowercase.
* @param array $parameters Array with information about the parameters.
*
* @return int|void Integer stack pointer to skip forward or void to continue
* normal file processing.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ public function process_token( $stackPtr ) {
* Process the parameters of a matched function.
*
* @param int $stackPtr The position of the current token in the stack.
* @param array $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) which was matched.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) which was matched
* in lowercase.
* @param array $parameters Array with information about the parameters.
*
* @return void
Expand Down Expand Up @@ -371,6 +372,8 @@ protected function process_css_style( $stackPtr ) {
* Consolidated violation.
*
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
*
* @return void
*/
private function addHidingDetectedError( $stackPtr ) {
$message = 'Hiding of the admin bar is not allowed.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DeclarationCompatibilityUnitTest extends AbstractSniffUnitTest {
/**
* Returns the lines where errors should occur.
*
* @return array <int line number> => <int number of errors>
* @return array<int, int> Key is the line number, value is the number of expected errors.
*/
public function getErrorList() {
return [
Expand Down Expand Up @@ -55,7 +55,7 @@ public function getErrorList() {
/**
* Returns the lines where warnings should occur.
*
* @return array <int line number> => <int number of warnings>
* @return array<int, int> Key is the line number, value is the number of expected warnings.
*/
public function getWarningList() {
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RestrictedExtendClassesUnitTest extends AbstractSniffUnitTest {
/**
* Returns the lines where errors should occur.
*
* @return array <int line number> => <int number of errors>
* @return array<int, int> Key is the line number, value is the number of expected errors.
*/
public function getErrorList() {
return [];
Expand All @@ -30,7 +30,7 @@ public function getErrorList() {
/**
* Returns the lines where warnings should occur.
*
* @return array <int line number> => <int number of warnings>
* @return array<int, int> Key is the line number, value is the number of expected warnings.
*/
public function getWarningList() {
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ConstantStringUnitTest extends AbstractSniffUnitTest {
/**
* Returns the lines where errors should occur.
*
* @return array <int line number> => <int number of errors>
* @return array<int, int> Key is the line number, value is the number of expected errors.
*/
public function getErrorList() {
return [
Expand All @@ -33,7 +33,7 @@ public function getErrorList() {
/**
* Returns the lines where warnings should occur.
*
* @return array <int line number> => <int number of warnings>
* @return array<int, int> Key is the line number, value is the number of expected warnings.
*/
public function getWarningList() {
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RestrictedConstantsUnitTest extends AbstractSniffUnitTest {
/**
* Returns the lines where errors should occur.
*
* @return array <int line number> => <int number of errors>
* @return array<int, int> Key is the line number, value is the number of expected errors.
*/
public function getErrorList() {
return [
Expand All @@ -34,7 +34,7 @@ public function getErrorList() {
/**
* Returns the lines where warnings should occur.
*
* @return array <int line number> => <int number of warnings>
* @return array<int, int> Key is the line number, value is the number of expected warnings.
*/
public function getWarningList() {
return [
Expand Down
4 changes: 2 additions & 2 deletions WordPressVIPMinimum/Tests/Files/IncludingFileUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class IncludingFileUnitTest extends AbstractSniffUnitTest {
/**
* Returns the lines where errors should occur.
*
* @return array <int line number> => <int number of errors>
* @return array<int, int> Key is the line number, value is the number of expected errors.
*/
public function getErrorList() {
return [
Expand All @@ -36,7 +36,7 @@ public function getErrorList() {
/**
* Returns the lines where warnings should occur.
*
* @return array <int line number> => <int number of warnings>
* @return array<int, int> Key is the line number, value is the number of expected warnings.
*/
public function getWarningList() {
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class IncludingNonPHPFileUnitTest extends AbstractSniffUnitTest {
/**
* Returns the lines where errors should occur.
*
* @return array <int line number> => <int number of errors>
* @return array<int, int> Key is the line number, value is the number of expected errors.
*/
public function getErrorList() {
return [
Expand Down Expand Up @@ -54,7 +54,7 @@ public function getErrorList() {
/**
* Returns the lines where warnings should occur.
*
* @return array <int line number> => <int number of warnings>
* @return array<int, int> Key is the line number, value is the number of expected warnings.
*/
public function getWarningList() {
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CheckReturnValueUnitTest extends AbstractSniffUnitTest {
/**
* Returns the lines where errors should occur.
*
* @return array <int line number> => <int number of errors>
* @return array<int, int> Key is the line number, value is the number of expected errors.
*/
public function getErrorList() {
return [
Expand All @@ -36,7 +36,7 @@ public function getErrorList() {
/**
* Returns the lines where warnings should occur.
*
* @return array <int line number> => <int number of warnings>
* @return array<int, int> Key is the line number, value is the number of expected warnings.
*/
public function getWarningList() {
return [];
Expand Down
Loading

0 comments on commit 332b8dd

Please sign in to comment.