Skip to content

Commit

Permalink
Merge pull request WordPress#2134 from WordPress/feature/core-no-rese…
Browse files Browse the repository at this point in the history
…rved-keyword-param-names
  • Loading branch information
GaryJones authored Dec 8, 2022
2 parents 2cb2547 + 511f4e5 commit 7057243
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
3 changes: 3 additions & 0 deletions WordPress-Core/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@
<rule ref="WordPress.NamingConventions.ValidHookName"/>
<rule ref="WordPress.NamingConventions.ValidVariableName"/>

<!-- Covers rule: It is _strongly recommended_ to avoid reserved keywords as function parameter names. -->
<rule ref="Universal.NamingConventions.NoReservedKeywordParameterNames"/>

<!-- Covers rule: Class names should use capitalized words separated by underscores. -->
<rule ref="PEAR.NamingConventions.ValidClassName"/>

Expand Down
12 changes: 6 additions & 6 deletions WordPress/AbstractFunctionRestrictionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,15 @@ public function process_matched_token( $stackPtr, $group_name, $matched_content
*
* @since 0.10.0
*
* @param string $function Function name.
* @param string $function_name Function name.
* @return string Regex escaped function name.
*/
protected function prepare_name_for_regex( $function ) {
$function = str_replace( array( '.*', '*' ), '@@', $function ); // Replace wildcards with placeholder.
$function = preg_quote( $function, '`' );
$function = str_replace( '@@', '.*', $function ); // Replace placeholder with regex wildcard.
protected function prepare_name_for_regex( $function_name ) {
$function_name = str_replace( array( '.*', '*' ), '@@', $function_name ); // Replace wildcards with placeholder.
$function_name = preg_quote( $function_name, '`' );
$function_name = str_replace( '@@', '.*', $function_name ); // Replace placeholder with regex wildcard.

return $function;
return $function_name;
}

}
6 changes: 3 additions & 3 deletions WordPress/Sniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ protected function is_token_namespaced( $stackPtr ) {
* @param array $valid_functions List of valid function names.
* Note: The keys to this array should be the function names
* in lowercase. Values are irrelevant.
* @param bool $global Optional. Whether to make sure that the function call is
* @param bool $global_function Optional. Whether to make sure that the function call is
* to a global function. If `false`, calls to methods, be it static
* `Class::method()` or via an object `$obj->method()`, and
* namespaced function calls, like `MyNS\function_name()` will
Expand All @@ -1271,7 +1271,7 @@ protected function is_token_namespaced( $stackPtr ) {
*
* @return int|bool Stack pointer to the function call T_STRING token or false otherwise.
*/
protected function is_in_function_call( $stackPtr, $valid_functions, $global = true, $allow_nested = false ) {
protected function is_in_function_call( $stackPtr, $valid_functions, $global_function = true, $allow_nested = false ) {
if ( ! isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) {
return false;
}
Expand All @@ -1297,7 +1297,7 @@ protected function is_in_function_call( $stackPtr, $valid_functions, $global = t
continue;
}

if ( false === $global ) {
if ( false === $global_function ) {
return $prev_non_empty;
}

Expand Down
16 changes: 8 additions & 8 deletions WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,38 +228,38 @@ protected function prepare_regex() {
/**
* Transform an arbitrary string to lowercase and replace punctuation and spaces with underscores.
*
* @param string $string The target string.
* @param string $text_string The target string.
* @param string $regex The punctuation regular expression to use.
* @param string $transform_type Whether to a partial or complete transform.
* Valid values are: 'full', 'case', 'punctuation'.
* @return string
*/
protected function transform( $string, $regex, $transform_type = 'full' ) {
protected function transform( $text_string, $regex, $transform_type = 'full' ) {

switch ( $transform_type ) {
case 'case':
return strtolower( $string );
return strtolower( $text_string );

case 'punctuation':
return preg_replace( $regex, '_', $string );
return preg_replace( $regex, '_', $text_string );

case 'full':
default:
return preg_replace( $regex, '_', strtolower( $string ) );
return preg_replace( $regex, '_', strtolower( $text_string ) );
}
}

/**
* Transform a complex string which may contain variable extrapolation.
*
* @param string $string The target string.
* @param string $text_string The target string.
* @param string $regex The punctuation regular expression to use.
* @param string $transform_type Whether to a partial or complete transform.
* Valid values are: 'full', 'case', 'punctuation'.
* @return string
*/
protected function transform_complex_string( $string, $regex, $transform_type = 'full' ) {
$output = preg_split( '`([\{\}\$\[\] ])`', $string, -1, \PREG_SPLIT_DELIM_CAPTURE );
protected function transform_complex_string( $text_string, $regex, $transform_type = 'full' ) {
$output = preg_split( '`([\{\}\$\[\] ])`', $text_string, -1, \PREG_SPLIT_DELIM_CAPTURE );

$is_variable = false;
$has_braces = false;
Expand Down

0 comments on commit 7057243

Please sign in to comment.