@@ -572,7 +572,7 @@ public function process(File $phpcsFile, $stackPtr)
572572 if ($ tokens [$ prev ]['line ' ] === $ tokens [$ i ]['line ' ]
573573 && ! ($ fp = $ this ->findPrevious ($ phpcsFile , $ i , [T_OBJECT_OPERATOR ]))
574574 ) {
575- $ endOfStatement = min ($ this ->findEndOfStatement ($ phpcsFile , $ i ), $ this ->findNext ($ phpcsFile , $ i ));
575+ $ endOfStatement = min ($ phpcsFile ->findEndOfStatement ($ i ), $ this ->findNext ($ phpcsFile , $ i ));
576576 $ newLine = $ this ->hasContainNewLine ($ phpcsFile , $ i , $ endOfStatement );
577577
578578 if ($ newLine ) {
@@ -618,7 +618,7 @@ public function process(File $phpcsFile, $stackPtr)
618618 ],
619619 true
620620 )) {
621- $ endOfStatement = $ this ->findEndOfStatement ($ phpcsFile , $ i );
621+ $ endOfStatement = $ phpcsFile ->findEndOfStatement ($ i );
622622 $ newLine = $ this ->hasContainNewLine ($ phpcsFile , $ i , $ endOfStatement );
623623
624624 if ($ newLine ) {
@@ -640,7 +640,7 @@ public function process(File $phpcsFile, $stackPtr)
640640 && isset ($ tokens [$ next ]['scope_closer ' ])
641641 && $ tokens [$ next ]['scope_closer ' ] === $ next
642642 ) {
643- $ endOfStatement = $ this ->findEndOfStatement ($ phpcsFile , $ next );
643+ $ endOfStatement = $ phpcsFile ->findEndOfStatement ($ next );
644644 $ this ->extras ($ endOfStatement , $ this ->indent );
645645
646646 $ extraIndent += $ this ->indent ;
@@ -946,70 +946,6 @@ private function findNext(File $phpcsFile, int $ptr, array $search = []) : ?int
946946 return null ;
947947 }
948948
949- /**
950- * Overrides File::findEndOfStatement as temporary solution until
951- * https://github.com/squizlabs/PHP_CodeSniffer/issues/2748
952- * is fixed.
953- */
954- private function findEndOfStatement (File $ phpcsFile , int $ ptr ) : int
955- {
956- $ closingBracket = [
957- T_CLOSE_PARENTHESIS ,
958- T_CLOSE_SQUARE_BRACKET ,
959- T_CLOSE_CURLY_BRACKET ,
960- T_CLOSE_SHORT_ARRAY ,
961- ];
962-
963- $ tokens = $ phpcsFile ->getTokens ();
964- $ lastToken = $ phpcsFile ->numTokens ;
965-
966- if ($ tokens [$ ptr ]['code ' ] === T_DOUBLE_ARROW && $ ptr < $ lastToken ) {
967- ++$ ptr ;
968- }
969-
970- while ($ ptr < $ lastToken ) {
971- if ($ tokens [$ ptr ]['code ' ] === T_OPEN_PARENTHESIS ) {
972- $ ptr = $ tokens [$ ptr ]['parenthesis_closer ' ] + 1 ;
973- continue ;
974- }
975-
976- if ($ tokens [$ ptr ]['code ' ] === T_OPEN_CURLY_BRACKET
977- || $ tokens [$ ptr ]['code ' ] === T_OPEN_SQUARE_BRACKET
978- || $ tokens [$ ptr ]['code ' ] === T_OPEN_SHORT_ARRAY
979- ) {
980- $ ptr = $ tokens [$ ptr ]['bracket_closer ' ] + 1 ;
981- continue ;
982- }
983-
984- if (isset ($ tokens [$ ptr ]['scope_closer ' ]) && $ ptr < $ tokens [$ ptr ]['scope_closer ' ]) {
985- $ ptr = $ tokens [$ ptr ]['scope_closer ' ];
986- if (in_array ($ tokens [$ ptr ]['code ' ], $ closingBracket , true )) {
987- ++$ ptr ;
988- }
989- } elseif (isset ($ tokens [$ ptr ]['parenthesis_closer ' ]) && $ ptr < $ tokens [$ ptr ]['parenthesis_closer ' ]) {
990- $ ptr = $ tokens [$ ptr ]['parenthesis_closer ' ];
991- if (in_array ($ tokens [$ ptr ]['code ' ], $ closingBracket , true )) {
992- ++$ ptr ;
993- }
994- }
995-
996- if ($ tokens [$ ptr ]['code ' ] === T_COMMA
997- || $ tokens [$ ptr ]['code ' ] === T_SEMICOLON
998- || $ tokens [$ ptr ]['code ' ] === T_DOUBLE_ARROW
999- ) {
1000- return $ ptr ;
1001- }
1002-
1003- if (in_array ($ tokens [$ ptr ]['code ' ], $ closingBracket , true )) {
1004- return $ phpcsFile ->findPrevious (Tokens::$ emptyTokens , $ ptr - 1 , null , true );
1005- }
1006-
1007- ++$ ptr ;
1008- }
1009-
1010- return $ lastToken ;
1011- }
1012-
1013949 /**
1014950 * Checks if there is another object operator
1015951 * before $ptr token.
0 commit comments