@@ -330,11 +330,17 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
330330 }
331331 } else if ($ tokens [$ arrayEnd ]['column ' ] !== $ keywordStart ) {
332332 // Check the closing bracket is lined up under the "a" in array.
333- $ expected = ($ keywordStart - 1 );
334- $ found = ($ tokens [$ arrayEnd ]['column ' ] - 1 );
335- $ error = 'Closing parenthesis not aligned correctly; expected %s space(s) but found %s ' ;
336- $ data = [
333+ $ expected = ($ keywordStart - 1 );
334+ $ found = ($ tokens [$ arrayEnd ]['column ' ] - 1 );
335+ $ pluralizeSpace = 's ' ;
336+ if ($ expected === 1 ) {
337+ $ pluralizeSpace = '' ;
338+ }
339+
340+ $ error = 'Closing parenthesis not aligned correctly; expected %s space%s but found %s ' ;
341+ $ data = [
337342 $ expected ,
343+ $ pluralizeSpace ,
338344 $ found ,
339345 ];
340346
@@ -674,12 +680,18 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
674680 } else if ($ previousIsWhitespace === true ) {
675681 $ expected = $ keywordStart ;
676682
677- $ first = $ phpcsFile ->findFirstOnLine (T_WHITESPACE , $ valuePointer , true );
678- $ found = ($ tokens [$ first ]['column ' ] - 1 );
683+ $ first = $ phpcsFile ->findFirstOnLine (T_WHITESPACE , $ valuePointer , true );
684+ $ found = ($ tokens [$ first ]['column ' ] - 1 );
685+ $ pluralizeSpace = 's ' ;
686+ if ($ expected === 1 ) {
687+ $ pluralizeSpace = '' ;
688+ }
689+
679690 if ($ found !== $ expected ) {
680- $ error = 'Array value not aligned correctly; expected %s spaces but found %s ' ;
691+ $ error = 'Array value not aligned correctly; expected %s space%s but found %s ' ;
681692 $ data = [
682693 $ expected ,
694+ $ pluralizeSpace ,
683695 $ found ,
684696 ];
685697
@@ -763,11 +775,17 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
763775 }
764776
765777 if ($ tokens [$ indexPointer ]['column ' ] !== $ indicesStart && ($ indexPointer - 1 ) !== $ arrayStart ) {
766- $ expected = ($ indicesStart - 1 );
767- $ found = ($ tokens [$ indexPointer ]['column ' ] - 1 );
768- $ error = 'Array key not aligned correctly; expected %s spaces but found %s ' ;
769- $ data = [
778+ $ expected = ($ indicesStart - 1 );
779+ $ found = ($ tokens [$ indexPointer ]['column ' ] - 1 );
780+ $ pluralizeSpace = 's ' ;
781+ if ($ expected === 1 ) {
782+ $ pluralizeSpace = '' ;
783+ }
784+
785+ $ error = 'Array key not aligned correctly; expected %s space%s but found %s ' ;
786+ $ data = [
770787 $ expected ,
788+ $ pluralizeSpace ,
771789 $ found ,
772790 ];
773791
@@ -779,15 +797,21 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
779797 $ phpcsFile ->fixer ->replaceToken (($ indexPointer - 1 ), str_repeat (' ' , $ expected ));
780798 }
781799 }
782- }
800+ }//end if
783801
784802 $ arrowStart = ($ tokens [$ indexPointer ]['column ' ] + $ maxLength + 1 );
785803 if ($ tokens [$ index ['arrow ' ]]['column ' ] !== $ arrowStart ) {
786- $ expected = ($ arrowStart - ($ index ['index_length ' ] + $ tokens [$ indexPointer ]['column ' ]));
787- $ found = ($ tokens [$ index ['arrow ' ]]['column ' ] - ($ index ['index_length ' ] + $ tokens [$ indexPointer ]['column ' ]));
788- $ error = 'Array double arrow not aligned correctly; expected %s space(s) but found %s ' ;
789- $ data = [
804+ $ expected = ($ arrowStart - ($ index ['index_length ' ] + $ tokens [$ indexPointer ]['column ' ]));
805+ $ found = ($ tokens [$ index ['arrow ' ]]['column ' ] - ($ index ['index_length ' ] + $ tokens [$ indexPointer ]['column ' ]));
806+ $ pluralizeSpace = 's ' ;
807+ if ($ expected === 1 ) {
808+ $ pluralizeSpace = '' ;
809+ }
810+
811+ $ error = 'Array double arrow not aligned correctly; expected %s space%s but found %s ' ;
812+ $ data = [
790813 $ expected ,
814+ $ pluralizeSpace ,
791815 $ found ,
792816 ];
793817
@@ -801,7 +825,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
801825 }
802826
803827 continue ;
804- }
828+ }//end if
805829
806830 $ valueStart = ($ arrowStart + 3 );
807831 if ($ tokens [$ valuePointer ]['column ' ] !== $ valueStart ) {
@@ -811,9 +835,15 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
811835 $ found = 'newline ' ;
812836 }
813837
814- $ error = 'Array value not aligned correctly; expected %s space(s) but found %s ' ;
838+ $ pluralizeSpace = 's ' ;
839+ if ($ expected === 1 ) {
840+ $ pluralizeSpace = '' ;
841+ }
842+
843+ $ error = 'Array value not aligned correctly; expected %s space%s but found %s ' ;
815844 $ data = [
816845 $ expected ,
846+ $ pluralizeSpace ,
817847 $ found ,
818848 ];
819849
0 commit comments