@@ -403,7 +403,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
403403 // If this is the first argument in a function ensure the bracket to be right after the parenthesis. eg "array_combine([".
404404 if ($ tokens [$ prevNonWhitespaceToken ]['code ' ] === T_OPEN_PARENTHESIS && $ tokens [$ stackPtr ]['code ' ] === T_OPEN_SHORT_ARRAY ) {
405405 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 "([" ' ;
407407 $ data = array ();
408408 $ fix = $ phpcsFile ->addFixableError ($ error , $ stackPtr , 'ShortArrayOpenWrongLine ' , $ data );
409409 if ($ fix === true ) {
@@ -417,11 +417,31 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
417417 }
418418 }
419419
420- // Check the closing bracket is on a new line .
420+ // Get content before closing array bracket/brace .
421421 $ 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.
422442 if ($ tokens [$ lastContent ]['line ' ] === $ tokens [$ arrayEnd ]['line ' ]) {
423443 $ 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 ' );
425445 if ($ fix === true ) {
426446 $ phpcsFile ->fixer ->addNewlineBefore ($ arrayEnd );
427447 }
@@ -442,7 +462,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
442462 ($ found / $ this ->tabWidth ),
443463 );
444464
445- $ fix = $ phpcsFile ->addFixableError ($ error , $ arrayEnd , 'CloseBraceNotAligned ' , $ data );
465+ $ fix = $ phpcsFile ->addFixableError ($ error , $ arrayEnd , 'CloseArrayBraceNotAligned ' , $ data );
446466 if ($ fix === true ) {
447467 if ($ found === 0 ) {
448468 $ phpcsFile ->fixer ->addContent (($ arrayEnd - 1 ), str_repeat (' ' , $ expected ));
0 commit comments