Skip to content

Commit 9d70828

Browse files
rodrigoprimojrfnl
andauthored
Apply suggestions from code review
Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com>
1 parent f384fb0 commit 9d70828

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

WordPress/Docs/WP/OptionAutoloadStandard.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<![CDATA[
88
When using `add_option()`, `update_option()`, `wp_set_options_autoload()`,
99
`wp_set_option_autoload()`, or `wp_set_option_autoload_values()`, it is recommended to
10-
explicitly set the autoload value to ensure predictable behavior. This value determines whether
10+
explicitly set the autoload parameter to ensure predictable behavior. This paremeter determines whether
1111
the option is automatically loaded on every page load, which can impact site performance.
1212
1313
Check https://felix-arntz.me/blog/autoloading-wordpress-options-efficiently-and-responsibly/ for
@@ -49,7 +49,7 @@ add_option(
4949
]]>
5050
</standard>
5151
<code_comparison>
52-
<code title="Valid: Using boolean values.">
52+
<code title="Valid: Using a boolean value.">
5353
<![CDATA[
5454
update_option(
5555
'my_option',
@@ -58,7 +58,7 @@ update_option(
5858
);
5959
]]>
6060
</code>
61-
<code title="Invalid: Using deprecated values.">
61+
<code title="Invalid: Using a deprecated value.">
6262
<![CDATA[
6363
update_option(
6464
'my_option',
@@ -114,7 +114,7 @@ wp_set_options_autoload(
114114
115115
wp_set_option_autoload(
116116
'my_option',
117-
<em>false</em>
117+
<em>true</em>
118118
);
119119
]]>
120120
</code>

WordPress/Sniffs/WP/OptionAutoloadSniff.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ final class OptionAutoloadSniff extends AbstractFunctionParameterSniff {
8686
*
8787
* @since 3.2.0
8888
*
89-
* @var string[]
89+
* @var array<string, string>
9090
*/
9191
protected static $fixable_values = array(
9292
'yes' => 'true',
@@ -266,7 +266,8 @@ protected function handle_wp_set_option_autoload_values( array $options_param, $
266266
* @since 3.2.0
267267
*
268268
* @param int $stackPtr The position of the current token in the stack.
269-
* @param string $function_name The name of the function being checked.
269+
* @param string $function_name The token content (function name) which was matched
270+
* in lowercase.
270271
*
271272
* @return void
272273
*/
@@ -290,8 +291,9 @@ protected function maybe_display_missing_autoload_warning( $stackPtr, $function_
290291
* @since 3.2.0
291292
*
292293
* @param array $autoload_info Information about the autoload value (start and end tokens and
293-
* the clean and raw value).
294-
* @param string $function_name The name of the function being checked.
294+
* the clean value).
295+
* @param string $function_name The token content (function name) which was matched
296+
* in lowercase.
295297
*
296298
* @return void
297299
*/
@@ -312,7 +314,7 @@ protected function check_autoload_value( array $autoload_info, $function_name )
312314

313315
$normalized_value = strtolower( $autoload_info['clean'] );
314316

315-
if ( T_NS_SEPARATOR === $this->tokens[ $param_first_token ]['code']
317+
if ( \T_NS_SEPARATOR === $this->tokens[ $param_first_token ]['code']
316318
&& $param_second_token
317319
&& in_array( strtolower( $this->tokens[ $param_second_token ]['content'] ), self::$valid_values_add_and_update, true )
318320
) {
@@ -334,7 +336,7 @@ protected function check_autoload_value( array $autoload_info, $function_name )
334336
return;
335337
}
336338

337-
if ( in_array( $this->tokens[ $param_first_token ]['code'], array( T_VARIABLE, T_STRING ), true )
339+
if ( in_array( $this->tokens[ $param_first_token ]['code'], array( \T_VARIABLE, \T_STRING ), true )
338340
&& 'null' !== strtolower( $this->tokens[ $param_first_token ]['content'] )
339341
) {
340342
// Bail early if the first non-empty token in the parameter is T_VARIABLE or T_STRING as

WordPress/Tests/WP/OptionAutoloadUnitTest.inc.fixed

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ $ok = wp_set_option_autoload_values(
4545
);
4646

4747
/*
48-
* These should all be ignored by the sniff as the autoload value is undetermined or not easy to
49-
* determine.
48+
* These should all be ignored by the sniff as the autoload value can't be reliably determined.
5049
*/
5150
$ignored = add_option( 'my_option', 'my_value', '', $some_variable );
5251
$ignored = add_option( 'my_option', 'my_value', '', $obj->yes );
@@ -82,7 +81,7 @@ $ignored = wp_set_option_autoload_values(options: array());
8281
$ignored = wp_set_option_autoload_values(options: []);
8382

8483
/*
85-
* Invalid function calls that are ignored by the sniff as a mandatory parameter is missing
84+
* Invalid function calls that are ignored by the sniff as a mandatory parameter is missing.
8685
*/
8786
$ignored = wp_set_option_autoload_values();
8887
$ignored = wp_set_options_autoload();

0 commit comments

Comments
 (0)