You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Array destructuring is a syntax in PHP where items of an array are assigned to single variables, using an array construct on the left of the assignment, e.g.
[$foo, $bar, $baz] = $source_array;
It's a common pattern to include a terminal comma to indicate that we know not all of the array's elements are being assigned.
I've been building up a (highly configurable) NormalizedArrays standard in PHPCSExtra to replace it, but that's not complete yet. Would be lovely if I could find some time to finish that at some point.
Having said that, you could consider excluding the Squiz.Arrays.ArrayDeclaration.CommaAfterLast error code and using the PHPCSExtra NormalizedArrays.Arrays.CommaAfterLast sniff to replace it. That sniff does ignore short lists correctly.
Describe the bug
Array destructuring is a syntax in PHP where items of an array are assigned to single variables, using an array construct on the left of the assignment, e.g.
It's a common pattern to include a terminal comma to indicate that we know not all of the array's elements are being assigned.
E.g. in Composer:
[$response, ] = $spec;
However, this fails the Squiz.Arrays.ArrayDeclaration.CommaAfterLast sniff:
Code sample
To reproduce
Steps to reproduce the behavior:
test.php
with the code sample above...phpcs --standard=Squiz --sniffs=Squiz.Arrays.ArrayDeclaration test.php
Expected behavior
A clear and concise description of what you expected to happen.
Versions (please complete the following information)
Additional context
Add any other context about the problem here.
Please confirm
master
branch of PHP_CodeSniffer.The text was updated successfully, but these errors were encountered: