Skip to content

Commit 6c930ea

Browse files
committed
Add a comment explaining why null needs special treatment on line 361
1 parent 2a5815a commit 6c930ea

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

WordPress/Sniffs/WP/OptionAutoloadSniff.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,17 @@ private function check_autoload_value( array $autoload_info, $function_name ) {
360360
if ( in_array( $this->tokens[ $param_first_token ]['code'], array( \T_VARIABLE, \T_STRING ), true )
361361
&& 'null' !== strtolower( $this->tokens[ $param_first_token ]['content'] )
362362
) {
363-
// Bail early if the first non-empty token in the parameter is T_VARIABLE or T_STRING as
364-
// this means it is not possible to determine the value.
363+
/*
364+
* Bail early if the first non-empty token in the parameter is T_VARIABLE or T_STRING as
365+
* this means it is not possible to determine the value.
366+
*
367+
* Exception for `null`: when FQN `\null` is used, PHPCS tokenizes it as T_STRING. Since
368+
* `null` is a known invalid value for the `$autoload` parameter in some functions (not
369+
* an undetermined value), we shouldn't bail in this case.
370+
*
371+
* Similar special treatment for FQN `\true` and `\false` is not needed as these values
372+
* are always valid and already handled in the condition above.
373+
*/
365374
$this->phpcsFile->recordMetric( $param_first_token, self::METRIC_NAME, 'undetermined value' );
366375
return;
367376
}

0 commit comments

Comments
 (0)