PHP_CodeSniffer icon indicating copy to clipboard operation
PHP_CodeSniffer copied to clipboard

Tokenizer/PHP: bug fix for short list tokens in control structures without braces

Open jrfnl opened this issue 3 years ago • 0 comments

Originally reported in sirbrillig/phpcs-variable-analysis#263.

When the short list syntax would be used as the first contents within a control structure without braces, the square brackets would be tokenized as plain square brackets, not as short array brackets.

if ( true )
    [ $a ] = [ 'hi' ]; // The first `[` in this line was tokenized incorrectly.

return $a ?? '';

Fixed now by checking whether the preceding parenthesis closer has an owner and if that owner could be a scope owner.

Includes unit tests. Includes updating the data providers to use named data sets to allow for easier debugging.

jrfnl avatar Jul 14 '22 13:07 jrfnl