@@ -650,12 +650,7 @@ public function processMultiLineArray(PHP_CodeSniffer_File $phpcsFile, $stackPtr
650650 $ found ,
651651 );
652652
653- if ($ found < 0 ) {
654- $ phpcsFile ->addError ($ error , $ index ['index ' ], 'KeyNotAligned ' , $ data );
655- $ fix = false ;
656- } else {
657- $ fix = $ phpcsFile ->addFixableError ($ error , $ index ['index ' ], 'KeyNotAligned ' , $ data );
658- }
653+ $ fix = $ phpcsFile ->addFixableError ($ error , $ index ['index ' ], 'KeyNotAligned ' , $ data );
659654
660655 if ($ fix === true ) {
661656 if ($ found === 0 ) {
@@ -671,18 +666,34 @@ public function processMultiLineArray(PHP_CodeSniffer_File $phpcsFile, $stackPtr
671666 if ($ tokens [$ index ['arrow ' ]]['column ' ] !== $ arrowStart ) {
672667 $ expected = ($ arrowStart - (strlen ($ index ['index_content ' ]) + $ tokens [$ index ['index ' ]]['column ' ]));
673668 $ found = ($ tokens [$ index ['arrow ' ]]['column ' ] - (strlen ($ index ['index_content ' ]) + $ tokens [$ index ['index ' ]]['column ' ]));
669+
670+ if ($ found < 0 ) {
671+ $ found = 'newline ' ;
672+ }
673+
674674 $ error = 'Array double arrow not aligned correctly; expected %s space(s) but found %s ' ;
675675 $ data = array (
676676 $ expected ,
677677 $ found ,
678678 );
679679
680- $ fix = $ phpcsFile ->addFixableError ($ error , $ index ['arrow ' ], 'DoubleArrowNotAligned ' , $ data );
681- if ($ fix === true ) {
682- if ($ found === 0 ) {
683- $ phpcsFile ->fixer ->addContent (($ index ['arrow ' ] - 1 ), str_repeat (' ' , $ expected ));
684- } else {
685- $ phpcsFile ->fixer ->replaceToken (($ index ['arrow ' ] - 1 ), str_repeat (' ' , $ expected ));
680+ if ($ found !== 'newline ' || $ this ->ignoreNewLine === false ) {
681+ $ fix = $ phpcsFile ->addFixableError ($ error , $ index ['arrow ' ], 'DoubleArrowNotAligned ' , $ data );
682+ if ($ fix === true ) {
683+ if ($ found === 'newline ' ) {
684+ $ prev = $ phpcsFile ->findPrevious (T_WHITESPACE , ($ index ['value ' ] - 1 ), null , true );
685+ $ phpcsFile ->fixer ->beginChangeset ();
686+ for ($ i = ($ prev + 1 ); $ i < $ index ['value ' ]; $ i ++) {
687+ $ phpcsFile ->fixer ->replaceToken ($ i , '' );
688+ }
689+
690+ $ phpcsFile ->fixer ->replaceToken (($ index ['value ' ] - 1 ), str_repeat (' ' , $ expected ));
691+ $ phpcsFile ->fixer ->endChangeset ();
692+ } elseif ($ found === 0 ) {
693+ $ phpcsFile ->fixer ->addContent (($ index ['arrow ' ] - 1 ), str_repeat (' ' , $ expected ));
694+ } else {
695+ $ phpcsFile ->fixer ->replaceToken (($ index ['arrow ' ] - 1 ), str_repeat (' ' , $ expected ));
696+ }
686697 }
687698 }
688699
0 commit comments