@@ -374,7 +374,24 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
374374 case T_COMMA :
375375 // The end of an array line "[],".
376376 // 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 );
378395 $ indentStart = $ firstOnLine ;
379396 break ;
380397 default :
@@ -386,7 +403,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
386403 // If this is the first argument in a function ensure the bracket to be right after the parenthesis. eg "array_combine([".
387404 if ($ tokens [$ prevNonWhitespaceToken ]['code ' ] === T_OPEN_PARENTHESIS && $ tokens [$ stackPtr ]['code ' ] === T_OPEN_SHORT_ARRAY ) {
388405 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 "([" ' ;
390407 $ data = array ();
391408 $ fix = $ phpcsFile ->addFixableError ($ error , $ stackPtr , 'ShortArrayOpenWrongLine ' , $ data );
392409 if ($ fix === true ) {
@@ -400,11 +417,31 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
400417 }
401418 }
402419
403- // Check the closing bracket is on a new line .
420+ // Get content before closing array bracket/brace .
404421 $ 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.
405442 if ($ tokens [$ lastContent ]['line ' ] === $ tokens [$ arrayEnd ]['line ' ]) {
406443 $ 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 ' );
408445 if ($ fix === true ) {
409446 $ phpcsFile ->fixer ->addNewlineBefore ($ arrayEnd );
410447 }
@@ -425,7 +462,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
425462 ($ found / $ this ->tabWidth ),
426463 );
427464
428- $ fix = $ phpcsFile ->addFixableError ($ error , $ arrayEnd , 'CloseBraceNotAligned ' , $ data );
465+ $ fix = $ phpcsFile ->addFixableError ($ error , $ arrayEnd , 'CloseArrayBraceNotAligned ' , $ data );
429466 if ($ fix === true ) {
430467 if ($ found === 0 ) {
431468 $ phpcsFile ->fixer ->addContent (($ arrayEnd - 1 ), str_repeat (' ' , $ expected ));
@@ -592,6 +629,10 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
592629 true
593630 );
594631
632+ if ($ nextContent === false ) {
633+ break ;
634+ }
635+
595636 $ currentEntry ['value ' ] = $ nextContent ;
596637 $ indices [] = $ currentEntry ;
597638 $ lastToken = $ nextToken ;
0 commit comments