1212use PHPStan \Reflection \ClassReflection ;
1313use PHPStan \Reflection \FunctionReflection ;
1414use PHPStan \Reflection \Native \NativeFunctionReflection ;
15- use Rector \NodeAnalyzer \ArgsAnalyzer ;
1615use Rector \NodeTypeResolver \Node \AttributeKey ;
1716use Rector \NodeTypeResolver \PHPStan \ParametersAcceptorSelectorVariantsWrapper ;
1817use Rector \Php81 \Enum \NameNullToStrictNullFunctionMap ;
@@ -31,7 +30,6 @@ final class NullToStrictStringFuncCallArgRector extends AbstractRector implement
3130{
3231 public function __construct (
3332 private readonly ReflectionResolver $ reflectionResolver ,
34- private readonly ArgsAnalyzer $ argsAnalyzer ,
3533 private readonly NullToStrictStringIntConverter $ nullToStrictStringIntConverter
3634 ) {
3735 }
@@ -89,9 +87,7 @@ public function refactor(Node $node): ?Node
8987 }
9088
9189 $ args = $ node ->getArgs ();
92- $ positions = $ this ->argsAnalyzer ->hasNamedArg ($ args )
93- ? $ this ->resolveNamedPositions ($ node , $ args )
94- : $ this ->resolveOriginalPositions ($ node , $ scope );
90+ $ positions = $ this ->resolvePositions ($ node , $ args , $ scope );
9591
9692 if ($ positions === []) {
9793 return null ;
@@ -139,11 +135,13 @@ public function provideMinPhpVersion(): int
139135 * @param Arg[] $args
140136 * @return int[]|string[]
141137 */
142- private function resolveNamedPositions (FuncCall $ funcCall , array $ args ): array
138+ private function resolvePositions (FuncCall $ funcCall , array $ args, Scope $ scope ): array
143139 {
140+ $ positions = [];
141+
144142 $ functionName = $ this ->getName ($ funcCall );
145143 $ argNames = NameNullToStrictNullFunctionMap::FUNCTION_TO_PARAM_NAMES [$ functionName ] ?? [];
146- $ positions = [];
144+ $ excludedArgNames = [];
147145
148146 foreach ($ args as $ position => $ arg ) {
149147 if (! $ arg ->name instanceof Identifier) {
@@ -154,20 +152,13 @@ private function resolveNamedPositions(FuncCall $funcCall, array $args): array
154152 continue ;
155153 }
156154
155+ $ excludedArgNames [] = $ arg ->name ->toString ();
157156 $ positions [] = $ position ;
158157 }
159158
160- return $ positions ;
161- }
162-
163- /**
164- * @return int[]|string[]
165- */
166- private function resolveOriginalPositions (FuncCall $ funcCall , Scope $ scope ): array
167- {
168159 $ functionReflection = $ this ->reflectionResolver ->resolveFunctionLikeReflectionFromCall ($ funcCall );
169160 if (! $ functionReflection instanceof NativeFunctionReflection) {
170- return [] ;
161+ return $ positions ;
171162 }
172163
173164 $ parametersAcceptor = ParametersAcceptorSelectorVariantsWrapper::select (
@@ -177,10 +168,10 @@ private function resolveOriginalPositions(FuncCall $funcCall, Scope $scope): arr
177168 );
178169 $ functionName = $ functionReflection ->getName ();
179170 $ argNames = NameNullToStrictNullFunctionMap::FUNCTION_TO_PARAM_NAMES [$ functionName ];
180- $ positions = [];
181171
182172 foreach ($ parametersAcceptor ->getParameters () as $ position => $ parameterReflection ) {
183- if (in_array ($ parameterReflection ->getName (), $ argNames , true )) {
173+ if (in_array ($ parameterReflection ->getName (), $ argNames , true )
174+ && ! in_array ($ parameterReflection ->getName (), $ excludedArgNames , true )) {
184175 $ positions [] = $ position ;
185176 }
186177 }
0 commit comments