@@ -650,12 +650,7 @@ public function processMultiLineArray(PHP_CodeSniffer_File $phpcsFile, $stackPtr
650
650
$ found ,
651
651
);
652
652
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 );
659
654
660
655
if ($ fix === true ) {
661
656
if ($ found === 0 ) {
@@ -671,18 +666,34 @@ public function processMultiLineArray(PHP_CodeSniffer_File $phpcsFile, $stackPtr
671
666
if ($ tokens [$ index ['arrow ' ]]['column ' ] !== $ arrowStart ) {
672
667
$ expected = ($ arrowStart - (strlen ($ index ['index_content ' ]) + $ tokens [$ index ['index ' ]]['column ' ]));
673
668
$ found = ($ tokens [$ index ['arrow ' ]]['column ' ] - (strlen ($ index ['index_content ' ]) + $ tokens [$ index ['index ' ]]['column ' ]));
669
+
670
+ if ($ found < 0 ) {
671
+ $ found = 'newline ' ;
672
+ }
673
+
674
674
$ error = 'Array double arrow not aligned correctly; expected %s space(s) but found %s ' ;
675
675
$ data = array (
676
676
$ expected ,
677
677
$ found ,
678
678
);
679
679
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
+ }
686
697
}
687
698
}
688
699
0 commit comments