Skip to content

Commit 5ca8075

Browse files
rodrigoprimojrfnl
andcommitted
Apply suggestions from code review
Co-authored-by: Juliette <[email protected]>
1 parent d86b341 commit 5ca8075

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

WordPress/Docs/WP/OptionAutoloadStandard.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
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 parameter to ensure predictable behavior. This parameter determines
11-
whether the option is automatically loaded on every page load, which can impact site performance.
10+
explicitly set the autoload parameter to ensure predictable behavior.
11+
The autoload flag determines whether the option is automatically loaded on every page load,
12+
which can impact site performance.
1213
]]>
1314
</standard>
1415
<standard>
@@ -23,7 +24,7 @@
2324
'on', or 'off' in plugin/theme code is strongly discouraged as those values are meant for
2425
internal-use only.
2526
26-
Any other values, including `null` for functions other than `add_option()` and `update_option()`
27+
Any other values, including `null` for functions other than `add_option()` and `update_option()`,
2728
are invalid.
2829
]]>
2930
</standard>
@@ -75,7 +76,7 @@ wp_set_options_autoload(
7576
<standard>
7677
<![CDATA[
7778
Even though the autoload parameter is optional for `add_option()` and `update_option()`, it is
78-
recommended to always explicitly set it.
79+
strongly recommended to always explicitly set it.
7980
]]>
8081
</standard>
8182
<code_comparison>

WordPress/Sniffs/WP/OptionAutoloadSniff.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ private function handle_wp_set_option_autoload_values( array $options_param, $st
240240
$array_token = $this->phpcsFile->findNext(
241241
Tokens::$emptyTokens,
242242
$options_param['start'],
243-
$options_param['end'],
243+
( $options_param['end'] + 1 ),
244244
true
245245
);
246246

@@ -311,8 +311,8 @@ private function maybe_display_missing_autoload_warning( $stackPtr, $function_na
311311
*
312312
* @since 3.2.0
313313
*
314-
* @param array $autoload_info Information about the autoload value (start and end tokens and
315-
* the clean value).
314+
* @param array $autoload_info Information about the autoload value (start and end tokens,
315+
* the clean value and potentially the "raw" value - which isn't used).
316316
* @param string $function_name The token content (function name) which was matched
317317
* in lowercase.
318318
*
@@ -369,7 +369,7 @@ private function check_autoload_value( array $autoload_info, $function_name ) {
369369
if ( $param_second_token
370370
&& false === isset( Collections::arrayOpenTokensBC()[ $this->tokens[ $param_first_token ]['code'] ] )
371371
) {
372-
// Bail early if the parameter has two or more non-empty tokens and the second token is
372+
// Bail early if the parameter has two or more non-empty tokens and the first token is
373373
// not an array opener as this means an undetermined param value or a value that is not
374374
// easy to determine.
375375
$this->phpcsFile->recordMetric( $param_first_token, self::METRIC_NAME, 'undetermined value' );
@@ -401,13 +401,7 @@ private function check_autoload_value( array $autoload_info, $function_name ) {
401401
$error_code = 'InternalUseOnly';
402402
$data = array( $autoload_info['clean'] );
403403
} else {
404-
$valid_values = array_map(
405-
function ( $value ) {
406-
return '`' . $value . '`';
407-
},
408-
$valid_values
409-
);
410-
$valid_values_string = implode( ', ', $valid_values );
404+
$valid_values_string = '`' . implode( '`, `', $valid_values ) . '`';
411405
$valid_values_string = substr_replace( $valid_values_string, ' or', strrpos( $valid_values_string, ',' ), 1 );
412406
$message = 'The use of `%s` as the value of the `$autoload` parameter is invalid. Use %s instead.';
413407
$error_code = 'InvalidValue';
@@ -422,7 +416,7 @@ function ( $value ) {
422416
$data
423417
);
424418

425-
if ( $fix ) {
419+
if ( true === $fix ) {
426420
$this->phpcsFile->fixer->replaceToken( $param_first_token, $this->fixable_values[ $autoload_value ] );
427421
}
428422

0 commit comments

Comments
 (0)