Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddParamFromDimFetchKeyUseRector\Fixture;

final class SkipMixClearAndUnClearType
{
public function process($key, $unclearType)
{
if (rand(0, 1)) {
$items = [
'first' => 'Firstitem',
'second' => 'Seconditem',
];

return $items[$key];
}

return $unclearType[$key];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
Loading