diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_mix_clear_and_unclear_type.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_mix_clear_and_unclear_type.php.inc new file mode 100644 index 00000000000..5abf6729ffe --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture/skip_mix_clear_and_unclear_type.php.inc @@ -0,0 +1,20 @@ + 'Firstitem', + 'second' => 'Seconditem', + ]; + + return $items[$key]; + } + + return $unclearType[$key]; + } +} diff --git a/rules/TypeDeclaration/NodeAnalyzer/VariableInSprintfMaskMatcher.php b/rules/TypeDeclaration/NodeAnalyzer/VariableInSprintfMaskMatcher.php index ee6e6d7c0e4..998e9109751 100644 --- a/rules/TypeDeclaration/NodeAnalyzer/VariableInSprintfMaskMatcher.php +++ b/rules/TypeDeclaration/NodeAnalyzer/VariableInSprintfMaskMatcher.php @@ -31,9 +31,7 @@ public function __construct( public function matchMask(ClassMethod|Function_ $functionLike, string $variableName, string $mask): bool { $funcCalls = $this->betterNodeFinder->findInstancesOfScoped((array) $functionLike->stmts, FuncCall::class); - $funcCalls = array_values(array_filter($funcCalls, function (FuncCall $funcCall): bool { - return $this->nodeNameResolver->isName($funcCall->name, 'sprintf'); - })); + $funcCalls = array_values(array_filter($funcCalls, fn(FuncCall $funcCall): bool => $this->nodeNameResolver->isName($funcCall->name, 'sprintf'))); if (count($funcCalls) !== 1) { return false; diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php index ad4e9e8b183..4ebd95ccfe9 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector.php @@ -112,28 +112,28 @@ public function refactor(Node $node): ?Node $dimFetchType = $this->getType($dimFetch->var); if (! $dimFetchType instanceof ArrayType && ! $dimFetchType instanceof ConstantArrayType) { - continue; + continue 2; } if ($dimFetch->dim instanceof Variable) { $type = $this->nodeTypeResolver->getType($dimFetch->dim); if ($type instanceof UnionType) { - continue; + continue 2; } } + } - $paramTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode( - $dimFetchType->getKeyType(), - TypeKind::PARAM - ); - - if (! $paramTypeNode instanceof Node) { - continue; - } + $paramTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode( + $dimFetchType->getKeyType(), + TypeKind::PARAM + ); - $param->type = $paramTypeNode; - $hasChanged = true; + if (! $paramTypeNode instanceof Node) { + continue; } + + $param->type = $paramTypeNode; + $hasChanged = true; } }