@@ -83,27 +83,54 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
8383
8484 private function fixArgumentsOrder (Tokens $ tokens , int $ startIndex , int $ endIndex ): void
8585 {
86- $ functionAnalyzer = new FunctionAnalyzer ();
87-
8886 for ($ index = $ startIndex ; $ index < $ endIndex ; $ index ++) {
8987 if (!self ::isAssertionCall ($ tokens , $ index )) {
9088 continue ;
9189 }
9290
93- $ arguments = $ functionAnalyzer -> getFunctionArguments ($ tokens , $ index );
91+ $ arguments = FunctionAnalyzer:: getFunctionArguments ($ tokens , $ index );
9492
95- if (!$ this -> shouldArgumentsBeSwapped ($ arguments )) {
93+ if (!self :: shouldArgumentsBeSwapped ($ arguments )) {
9694 continue ;
9795 }
9896
99- $ this ->swapArguments ($ tokens , $ arguments );
97+ self ::swapArguments ($ tokens , $ arguments );
98+ }
99+ }
100+
101+ private static function isAssertionCall (Tokens $ tokens , int $ index ): bool
102+ {
103+ static $ assertions ;
104+
105+ if ($ assertions === null ) {
106+ $ assertions = \array_flip (
107+ \array_map (
108+ static function (string $ name ): string {
109+ return \strtolower ($ name );
110+ },
111+ self ::ASSERTIONS
112+ )
113+ );
114+ }
115+
116+ if (!isset ($ assertions [\strtolower ($ tokens [$ index ]->getContent ())])) {
117+ return false ;
100118 }
119+
120+ /** @var int $openingBraceIndex */
121+ $ openingBraceIndex = $ tokens ->getNextMeaningfulToken ($ index );
122+
123+ if (!$ tokens [$ openingBraceIndex ]->equals ('( ' )) {
124+ return false ;
125+ }
126+
127+ return (new FunctionsAnalyzer ())->isTheSameClassCall ($ tokens , $ index );
101128 }
102129
103130 /**
104131 * @param array<ArgumentAnalysis> $arguments
105132 */
106- private function shouldArgumentsBeSwapped (array $ arguments ): bool
133+ private static function shouldArgumentsBeSwapped (array $ arguments ): bool
107134 {
108135 if (\count ($ arguments ) < 2 ) {
109136 return false ;
@@ -119,7 +146,7 @@ private function shouldArgumentsBeSwapped(array $arguments): bool
119146 /**
120147 * @param array<ArgumentAnalysis> $arguments
121148 */
122- private function swapArguments (Tokens $ tokens , array $ arguments ): void
149+ private static function swapArguments (Tokens $ tokens , array $ arguments ): void
123150 {
124151 $ expectedArgumentTokens = []; // these will be 1st argument
125152 for ($ index = $ arguments [1 ]->getStartIndex (); $ index <= $ arguments [1 ]->getEndIndex (); $ index ++) {
@@ -134,33 +161,4 @@ private function swapArguments(Tokens $tokens, array $arguments): void
134161 $ tokens ->overrideRange ($ arguments [1 ]->getStartIndex (), $ arguments [1 ]->getEndIndex (), $ actualArgumentTokens );
135162 $ tokens ->overrideRange ($ arguments [0 ]->getStartIndex (), $ arguments [0 ]->getEndIndex (), $ expectedArgumentTokens );
136163 }
137-
138- private static function isAssertionCall (Tokens $ tokens , int $ index ): bool
139- {
140- static $ assertions ;
141-
142- if ($ assertions === null ) {
143- $ assertions = \array_flip (
144- \array_map (
145- static function (string $ name ): string {
146- return \strtolower ($ name );
147- },
148- self ::ASSERTIONS
149- )
150- );
151- }
152-
153- if (!isset ($ assertions [\strtolower ($ tokens [$ index ]->getContent ())])) {
154- return false ;
155- }
156-
157- /** @var int $openingBraceIndex */
158- $ openingBraceIndex = $ tokens ->getNextMeaningfulToken ($ index );
159-
160- if (!$ tokens [$ openingBraceIndex ]->equals ('( ' )) {
161- return false ;
162- }
163-
164- return (new FunctionsAnalyzer ())->isTheSameClassCall ($ tokens , $ index );
165- }
166164}
0 commit comments