@@ -374,7 +374,24 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
374
374
case T_COMMA :
375
375
// The end of an array line "[],".
376
376
// Argument in a function "$item->save($data, [...], ...)".
377
- $ firstOnLine = $ phpcsFile ->findFirstOnLine (array (T_VARIABLE , T_CLOSE_SHORT_ARRAY ), $ prevNonWhitespaceToken );
377
+ $ starts = array (
378
+ T_VARIABLE ,
379
+ T_VAR ,
380
+ T_PUBLIC ,
381
+ T_PRIVATE ,
382
+ T_PROTECTED ,
383
+ T_ARRAY_CAST ,
384
+ T_UNSET_CAST ,
385
+ T_OBJECT_CAST ,
386
+ T_STATIC ,
387
+ T_CONST ,
388
+ T_RETURN ,
389
+ T_OBJECT_OPERATOR ,
390
+ T_CLOSE_SHORT_ARRAY ,
391
+ T_CONSTANT_ENCAPSED_STRING ,
392
+ );
393
+
394
+ $ firstOnLine = $ phpcsFile ->findFirstOnLine ($ starts , $ prevNonWhitespaceToken );
378
395
$ indentStart = $ firstOnLine ;
379
396
break ;
380
397
default :
@@ -386,7 +403,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
386
403
// If this is the first argument in a function ensure the bracket to be right after the parenthesis. eg "array_combine([".
387
404
if ($ tokens [$ prevNonWhitespaceToken ]['code ' ] === T_OPEN_PARENTHESIS && $ tokens [$ stackPtr ]['code ' ] === T_OPEN_SHORT_ARRAY ) {
388
405
if ($ tokens [$ stackPtr ]['line ' ] > $ tokens [$ prevNonWhitespaceToken ]['line ' ]) {
389
- $ error = 'Array open bracket should be after function open parenthesis "([" ' ;
406
+ $ error = 'Array openening bracket should be after function open parenthesis "([" ' ;
390
407
$ data = array ();
391
408
$ fix = $ phpcsFile ->addFixableError ($ error , $ stackPtr , 'ShortArrayOpenWrongLine ' , $ data );
392
409
if ($ fix === true ) {
@@ -400,11 +417,31 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
400
417
}
401
418
}
402
419
403
- // Check the closing bracket is on a new line .
420
+ // Get content before closing array bracket/brace .
404
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.
405
442
if ($ tokens [$ lastContent ]['line ' ] === $ tokens [$ arrayEnd ]['line ' ]) {
406
443
$ error = 'Closing parenthesis of array declaration must be on a new line ' ;
407
- $ fix = $ phpcsFile ->addFixableError ($ error , $ arrayEnd , 'CloseBraceNewLine ' );
444
+ $ fix = $ phpcsFile ->addFixableError ($ error , $ arrayEnd , 'CloseArrayBraceNewLine ' );
408
445
if ($ fix === true ) {
409
446
$ phpcsFile ->fixer ->addNewlineBefore ($ arrayEnd );
410
447
}
@@ -425,7 +462,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
425
462
($ found / $ this ->tabWidth ),
426
463
);
427
464
428
- $ fix = $ phpcsFile ->addFixableError ($ error , $ arrayEnd , 'CloseBraceNotAligned ' , $ data );
465
+ $ fix = $ phpcsFile ->addFixableError ($ error , $ arrayEnd , 'CloseArrayBraceNotAligned ' , $ data );
429
466
if ($ fix === true ) {
430
467
if ($ found === 0 ) {
431
468
$ phpcsFile ->fixer ->addContent (($ arrayEnd - 1 ), str_repeat ('' , $ expected ));
@@ -592,6 +629,10 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
592
629
true
593
630
);
594
631
632
+ if ($ nextContent === false ) {
633
+ break ;
634
+ }
635
+
595
636
$ currentEntry ['value ' ] = $ nextContent ;
596
637
$ indices [] = $ currentEntry ;
597
638
$ lastToken = $ nextToken ;
0 commit comments