Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: clarify the $matched_content parameter #2280

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions WordPress/AbstractClassRestrictionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,26 @@ public function check_for_matches( $stackPtr ) {
return min( $skip_to );
}

/**
* Process a matched token.
*
* @since 0.11.0 Split out from the `process()` method.
*
* @param int $stackPtr The position of the current token in the stack.
* @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 it original case.
*
* @return int|void Integer stack pointer to skip forward or void to continue
* normal file processing.
*
* @phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod.Found
*/
public function process_matched_token( $stackPtr, $group_name, $matched_content ) {
parent::process_matched_token( $stackPtr, $group_name, $matched_content );
}
// phpcs:enable

/**
* Prepare the class name for use in a regular expression.
*
Expand Down
9 changes: 6 additions & 3 deletions WordPress/AbstractFunctionParameterSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public function getGroups() {
*
* @param int $stackPtr The position of the current token in the stack.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) which was matched.
* @param string $matched_content The token content (function name) which was matched
* in lowercase.
*
* @return int|void Integer stack pointer to skip forward or void to continue
* normal file processing.
Expand All @@ -85,7 +86,8 @@ public function process_matched_token( $stackPtr, $group_name, $matched_content
*
* @param int $stackPtr The position of the current token in the stack.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) 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
Expand All @@ -101,7 +103,8 @@ abstract public function process_parameters( $stackPtr, $group_name, $matched_co
*
* @param int $stackPtr The position of the current token in the stack.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) which was matched.
* @param string $matched_content The token content (function name) which was matched
* in lowercase.
*
* @return int|void Integer stack pointer to skip forward or void to continue
* normal file processing.
Expand Down
3 changes: 2 additions & 1 deletion WordPress/AbstractFunctionRestrictionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ public function check_for_matches( $stackPtr ) {
*
* @param int $stackPtr The position of the current token in the stack.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) which was matched.
* @param string $matched_content The token content (function name) which was matched
* in lowercase.
*
* @return int|void Integer stack pointer to skip forward or void to continue
* normal file processing.
Expand Down
3 changes: 2 additions & 1 deletion WordPress/Sniffs/CodeAnalysis/EscapedNotTranslatedSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ final class EscapedNotTranslatedSniff extends AbstractFunctionParameterSniff {
*
* @param int $stackPtr The position of the current token in the stack.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) 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
3 changes: 2 additions & 1 deletion WordPress/Sniffs/DateTime/CurrentTimeTimestampSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ final class CurrentTimeTimestampSniff extends AbstractFunctionParameterSniff {
*
* @param int $stackPtr The position of the current token in the stack.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) 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
3 changes: 2 additions & 1 deletion WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,8 @@ protected function process_list_assignment( $stackPtr ) {
*
* @param int $stackPtr The position of the current token in the stack.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) 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
3 changes: 2 additions & 1 deletion WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public function getGroups() {
*
* @param int $stackPtr The position of the current token in the stack.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) 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
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public function register() {
*
* @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 $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
3 changes: 2 additions & 1 deletion WordPress/Sniffs/PHP/IniSetSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ final class IniSetSniff extends AbstractFunctionParameterSniff {
*
* @param int $stackPtr The position of the current token in the stack.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) 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
3 changes: 2 additions & 1 deletion WordPress/Sniffs/PHP/PregQuoteDelimiterSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ final class PregQuoteDelimiterSniff extends AbstractFunctionParameterSniff {
*
* @param int $stackPtr The position of the current token in the stack.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) 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
3 changes: 2 additions & 1 deletion WordPress/Sniffs/PHP/StrictInArraySniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ final class StrictInArraySniff extends AbstractFunctionParameterSniff {
*
* @param int $stackPtr The position of the current token in the stack.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) 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
3 changes: 2 additions & 1 deletion WordPress/Sniffs/Security/PluginMenuSlugSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ final class PluginMenuSlugSniff extends AbstractFunctionParameterSniff {
*
* @param int $stackPtr The position of the current token in the stack.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) 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
6 changes: 4 additions & 2 deletions WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@ public function process_token( $stackPtr ) {
*
* @param int $stackPtr The position of the current token in the stack.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) 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 @@ -594,7 +595,8 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
*
* @param int $stackPtr The position of the current token in the stack.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) which was matched.
* @param string $matched_content The token content (function name) which was matched
* in lowercase.
*
* @return void
*/
Expand Down
3 changes: 2 additions & 1 deletion WordPress/Sniffs/WP/AlternativeFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ public function getGroups() {
*
* @param int $stackPtr The position of the current token in the stack.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) which was matched.
* @param string $matched_content The token content (function name) which was matched
* in lowercase.
*
* @return int|void Integer stack pointer to skip forward or void to continue
* normal file processing.
Expand Down
6 changes: 3 additions & 3 deletions WordPress/Sniffs/WP/CapabilitiesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,14 @@ final class CapabilitiesSniff extends AbstractFunctionParameterSniff {
*
* @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 $matched_content The token content (function name) which was matched
* in lowercase.
* @param array $parameters Array with information about the parameters.
*
* @return void
*/
public function process_parameters( $stackPtr, $group_name, $matched_content, $parameters ) {
$function_name_lc = strtolower( $matched_content );
$function_details = $this->target_functions[ $function_name_lc ];
$function_details = $this->target_functions[ $matched_content ];

$parameter = PassedParameters::getParameterFromStack(
$parameters,
Expand Down
1 change: 1 addition & 0 deletions WordPress/Sniffs/WP/ClassNameCaseSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ public function getGroups() {
* @param string $group_name The name of the group which was matched. Will
* always be 'wp_classes'.
* @param string $matched_content The token content (class name) which was matched.
* in its original case.
*
* @return void
*/
Expand Down
3 changes: 2 additions & 1 deletion WordPress/Sniffs/WP/DeprecatedClassesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public function getGroups() {
* @param int $stackPtr The position of the current token in the stack.
* @param string $group_name The name of the group which was matched. Will
* always be 'deprecated_classes'.
* @param string $matched_content The token content (class name) which was matched.
* @param string $matched_content The token content (class name) which was matched
* in its original case.
*
* @return void
*/
Expand Down
15 changes: 7 additions & 8 deletions WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -1520,32 +1520,31 @@ public function getGroups() {
* @param int $stackPtr The position of the current token in the stack.
* @param string $group_name The name of the group which was matched. Will
* always be 'deprecated_functions'.
* @param string $matched_content The token content (function name) which was matched.
* @param string $matched_content The token content (function name) which was matched
* in lowercase.
*
* @return void
*/
public function process_matched_token( $stackPtr, $group_name, $matched_content ) {

$this->set_minimum_wp_version();

$function_name = strtolower( $matched_content );

$message = '%s() has been deprecated since WordPress version %s.';
$data = array(
$matched_content,
$this->deprecated_functions[ $function_name ]['version'],
$this->tokens[ $stackPtr ]['content'],
$this->deprecated_functions[ $matched_content ]['version'],
);

if ( ! empty( $this->deprecated_functions[ $function_name ]['alt'] ) ) {
if ( ! empty( $this->deprecated_functions[ $matched_content ]['alt'] ) ) {
$message .= ' Use %s instead.';
$data[] = $this->deprecated_functions[ $function_name ]['alt'];
$data[] = $this->deprecated_functions[ $matched_content ]['alt'];
}

MessageHelper::addMessage(
$this->phpcsFile,
$message,
$stackPtr,
( $this->wp_version_compare( $this->deprecated_functions[ $function_name ]['version'], $this->minimum_wp_version, '<' ) ),
( $this->wp_version_compare( $this->deprecated_functions[ $matched_content ]['version'], $this->minimum_wp_version, '<' ) ),
MessageHelper::stringToErrorcode( $matched_content . 'Found' ),
$data
);
Expand Down
6 changes: 4 additions & 2 deletions WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ final class DeprecatedParameterValuesSniff extends AbstractFunctionParameterSnif
*
* @param int $stackPtr The position of the current token in the stack.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) 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 All @@ -243,7 +244,8 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
*
* @since 1.0.0
*
* @param string $matched_content The token content (function name) which was matched.
* @param string $matched_content The token content (function name) which was matched
* in lowercase.
* @param array $parameter Array with start and end token positon of the parameter.
* @param array $parameter_args Array with alternative and WordPress deprecation version of the parameter.
*
Expand Down
3 changes: 2 additions & 1 deletion WordPress/Sniffs/WP/DeprecatedParametersSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ final class DeprecatedParametersSniff extends AbstractFunctionParameterSniff {
*
* @param int $stackPtr The position of the current token in the stack.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) 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
6 changes: 3 additions & 3 deletions WordPress/Sniffs/WP/DiscouragedConstantsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@ public function process_arbitrary_tstring( $stackPtr ) {
*
* @param int $stackPtr The position of the current token in the stack.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) 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
*/
public function process_parameters( $stackPtr, $group_name, $matched_content, $parameters ) {
$function_name = strtolower( $matched_content );
$target_param = $this->target_functions[ $function_name ];
$target_param = $this->target_functions[ $matched_content ];

// Was the target parameter passed ?
$found_param = PassedParameters::getParameterFromStack( $parameters, $target_param['position'], $target_param['name'] );
Expand Down
3 changes: 2 additions & 1 deletion WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public function register() {
*
* @param int $stackPtr The position of the current token in the stack.
* @param string $group_name The name of the group which was matched.
* @param string $matched_content The token content (function name) 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
Loading
Loading