Problem/Motivation
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;
(see https://www.php.net/manual/en/language.types.array.php)
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 Drupal\Core\DependencyInjection\YamlFileLoader
[$provider, ] = explode('.', $basename, 2);
This is used in code outside of Drupal too, e.g. in Composer:
[$response, ] = $spec;
[$defaultUsername, ] = explode(':', $authParts, 2);
However, Coder fails this with two sniffs:
124 | ERROR | [x] Comma not allowed after last value in single-line array
| | declaration (Squiz.Arrays.ArrayDeclaration.CommaAfterLast)
124 | ERROR | [x] There should be no white space before a closing "]"
| | (Drupal.WhiteSpace.CloseBracketSpacing.ClosingWhitespace)
I've created an upstream issue for Squiz.Arrays.ArrayDeclaration.NoCommaAfterLast: https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/528
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes