@@ -378,29 +378,14 @@ public function processMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $
378
378
$ functionIndent = (int ) (floor ($ foundFunctionIndent / $ this ->indent ) * $ this ->indent );
379
379
$ adjustment = ($ functionIndent - $ foundFunctionIndent );
380
380
381
- // This rule doesn't apply to PSR2, but this sniff is used there. We can
382
- // silence the complaint in the PSR2 ruleset.xml, but the unit tests
383
- // don't seem to respect that. If there is a way to make the unit tests
384
- // respect ruleset.xml, then we can remove the `strpos()` call here.
385
- if ($ foundFunctionIndent !== $ functionIndent && strpos (get_class ($ this ), '\\PSR2 \\' ) === false ) {
386
- $ error = 'Opening statement of multi-line function call not indented correctly; expected %s spaces but found %s ' ;
387
- $ data = [
381
+ if ($ foundFunctionIndent !== $ functionIndent ) {
382
+ $ this ->complainOpenStatementWrongIndent (
383
+ $ phpcsFile ,
384
+ $ first ,
385
+ $ tokens ,
388
386
$ functionIndent ,
389
- $ foundFunctionIndent ,
390
- ];
391
-
392
- $ fix = $ phpcsFile ->addFixableError ($ error , $ first , 'OpeningIndent ' , $ data );
393
- if ($ fix === true ) {
394
- $ padding = str_repeat (' ' , $ functionIndent );
395
- if ($ foundFunctionIndent === 0 ) {
396
- $ phpcsFile ->fixer ->addContentBefore ($ first , $ padding );
397
- } else if ($ tokens [$ first ]['code ' ] === T_INLINE_HTML ) {
398
- $ newContent = $ padding .ltrim ($ tokens [$ first ]['content ' ]);
399
- $ phpcsFile ->fixer ->replaceToken ($ first , $ newContent );
400
- } else {
401
- $ phpcsFile ->fixer ->replaceToken (($ first - 1 ), $ padding );
402
- }
403
- }
387
+ $ foundFunctionIndent
388
+ );
404
389
}//end if
405
390
406
391
$ next = $ phpcsFile ->findNext (Tokens::$ emptyTokens , ($ openBracket + 1 ), null , true );
@@ -656,4 +641,51 @@ public function processMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $
656
641
}//end processMultiLineCall()
657
642
658
643
644
+ /**
645
+ * Add a complaint (and auto-fix) if the function indent is 'wrong'.
646
+ *
647
+ * @param File $phpcsFile The file being scanned.
648
+ * @param int $first Pointer to the first empty token on this line.
649
+ * @param array $tokens The stack of tokens that make up the file.
650
+ * @param int $functionIndent The expected indent for this function definition.
651
+ * @param int $foundFunctionIndent The actual indent for this function definition.
652
+ *
653
+ * @return void
654
+ */
655
+ protected function complainOpenStatementWrongIndent (
656
+ $ phpcsFile ,
657
+ $ first ,
658
+ $ tokens ,
659
+ $ functionIndent ,
660
+ $ foundFunctionIndent
661
+ ) {
662
+ if ($ foundFunctionIndent === $ functionIndent ) {
663
+ return ;
664
+ }
665
+
666
+ $ error = 'Opening statement of multi-line function call not indented correctly; expected %s spaces but found %s ' ;
667
+ $ data = [
668
+ $ functionIndent ,
669
+ $ foundFunctionIndent ,
670
+ ];
671
+
672
+ $ fix = $ phpcsFile ->addFixableError ($ error , $ first , 'OpeningIndent ' , $ data );
673
+ if ($ fix !== true ) {
674
+ return ;
675
+ }
676
+
677
+ $ padding = str_repeat (' ' , $ functionIndent );
678
+
679
+ if ($ foundFunctionIndent === 0 ) {
680
+ $ phpcsFile ->fixer ->addContentBefore ($ first , $ padding );
681
+ } else if ($ tokens [$ first ]['code ' ] === T_INLINE_HTML ) {
682
+ $ newContent = $ padding .ltrim ($ tokens [$ first ]['content ' ]);
683
+ $ phpcsFile ->fixer ->replaceToken ($ first , $ newContent );
684
+ } else {
685
+ $ phpcsFile ->fixer ->replaceToken (($ first - 1 ), $ padding );
686
+ }
687
+
688
+ }//end complainOpenStatementWrongIndent()
689
+
690
+
659
691
}//end class
0 commit comments