1111use PHPStan \Analyser \Scope ;
1212use PHPStan \Reflection \ClassReflection ;
1313use PHPStan \Reflection \FunctionReflection ;
14+ use Rector \NodeAnalyzer \ArgsAnalyzer ;
1415use Rector \NodeTypeResolver \Node \AttributeKey ;
1516use Rector \NodeTypeResolver \PHPStan \ParametersAcceptorSelectorVariantsWrapper ;
1617use Rector \Php81 \NodeManipulator \NullToStrictStringIntConverter ;
@@ -29,7 +30,8 @@ final class ArrayKeyExistsNullToEmptyStringRector extends AbstractRector impleme
2930{
3031 public function __construct (
3132 private readonly ReflectionResolver $ reflectionResolver ,
32- private readonly NullToStrictStringIntConverter $ nullToStrictStringIntConverter
33+ private readonly NullToStrictStringIntConverter $ nullToStrictStringIntConverter ,
34+ private readonly ArgsAnalyzer $ argsAnalyzer
3335 ) {
3436 }
3537
@@ -93,7 +95,7 @@ public function refactor(Node $node): ?Node
9395 $ result = $ this ->nullToStrictStringIntConverter ->convertIfNull (
9496 $ node ,
9597 $ args ,
96- $ this ->resolvePosition ($ args ),
98+ $ this ->argsAnalyzer -> resolveArgPosition ($ args, ' key ' , 0 ),
9799 $ isTrait ,
98100 $ scope ,
99101 $ parametersAcceptor
@@ -109,18 +111,4 @@ public function provideMinPhpVersion(): int
109111 {
110112 return PhpVersionFeature::DEPRECATE_NULL_ARG_IN_ARRAY_KEY_EXISTS_FUNCTION ;
111113 }
112-
113- /**
114- * @param Arg[] $args
115- */
116- private function resolvePosition (array $ args ): int
117- {
118- foreach ($ args as $ position => $ arg ) {
119- if ($ arg ->name instanceof Identifier && $ arg ->name ->toString () === 'key ' ) {
120- return $ position ;
121- }
122- }
123-
124- return 0 ;
125- }
126114}
0 commit comments