@@ -403,7 +403,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
403
403
// If this is the first argument in a function ensure the bracket to be right after the parenthesis. eg "array_combine([".
404
404
if ($ tokens [$ prevNonWhitespaceToken ]['code ' ] === T_OPEN_PARENTHESIS && $ tokens [$ stackPtr ]['code ' ] === T_OPEN_SHORT_ARRAY ) {
405
405
if ($ tokens [$ stackPtr ]['line ' ] > $ tokens [$ prevNonWhitespaceToken ]['line ' ]) {
406
- $ error = 'Array open bracket should be after function open parenthesis "([" ' ;
406
+ $ error = 'Array openening bracket should be after function open parenthesis "([" ' ;
407
407
$ data = array ();
408
408
$ fix = $ phpcsFile ->addFixableError ($ error , $ stackPtr , 'ShortArrayOpenWrongLine ' , $ data );
409
409
if ($ fix === true ) {
@@ -417,11 +417,31 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
417
417
}
418
418
}
419
419
420
- // Check the closing bracket is on a new line .
420
+ // Get content before closing array bracket/brace .
421
421
$ lastContent = $ phpcsFile ->findPrevious (T_WHITESPACE , ($ arrayEnd - 1 ), $ arrayStart , true );
422
+
423
+ // Check for ) after last Array end.
424
+ $ afterCloser = $ phpcsFile ->findNext (T_WHITESPACE , ($ arrayEnd + 1 ), null , true );
425
+ if ($ tokens [$ afterCloser ]['code ' ] === T_CLOSE_PARENTHESIS ) {
426
+ if ($ tokens [$ afterCloser ]['column ' ] !== ($ tokens [$ arrayEnd ]['column ' ] + 1 )) {
427
+ $ error = 'Closing parenthesis should be after array closing bracket "])" ' ;
428
+ $ data = array ();
429
+ $ fix = $ phpcsFile ->addFixableError ($ error , $ afterCloser , 'CloseBracketAfterArrayBracket ' );
430
+ if ($ fix === true ) {
431
+ $ phpcsFile ->fixer ->beginChangeset ();
432
+ for ($ i = ($ arrayEnd + 1 ); $ i < $ afterCloser ; $ i ++) {
433
+ $ phpcsFile ->fixer ->replaceToken ($ i , '' );
434
+ }
435
+
436
+ $ phpcsFile ->fixer ->endChangeset ();
437
+ }
438
+ }
439
+ }
440
+
441
+ // Check the closing bracket is on a new line.
422
442
if ($ tokens [$ lastContent ]['line ' ] === $ tokens [$ arrayEnd ]['line ' ]) {
423
443
$ error = 'Closing parenthesis of array declaration must be on a new line ' ;
424
- $ fix = $ phpcsFile ->addFixableError ($ error , $ arrayEnd , 'CloseBraceNewLine ' );
444
+ $ fix = $ phpcsFile ->addFixableError ($ error , $ arrayEnd , 'CloseArrayBraceNewLine ' );
425
445
if ($ fix === true ) {
426
446
$ phpcsFile ->fixer ->addNewlineBefore ($ arrayEnd );
427
447
}
@@ -442,7 +462,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
442
462
($ found / $ this ->tabWidth ),
443
463
);
444
464
445
- $ fix = $ phpcsFile ->addFixableError ($ error , $ arrayEnd , 'CloseBraceNotAligned ' , $ data );
465
+ $ fix = $ phpcsFile ->addFixableError ($ error , $ arrayEnd , 'CloseArrayBraceNotAligned ' , $ data );
446
466
if ($ fix === true ) {
447
467
if ($ found === 0 ) {
448
468
$ phpcsFile ->fixer ->addContent (($ arrayEnd - 1 ), str_repeat (' ' , $ expected ));
0 commit comments