Skip to content

Commit

Permalink
[TypeDeclaration] Skip more detailed type on AddMethodCallBasedStrict…
Browse files Browse the repository at this point in the history
…ParamTypeRector (#5866)

* [TypeDeclaration] Skip more detailed type on AddMethodCallBasedStrictParamTypeRector

* Fix
  • Loading branch information
samsonasik committed May 10, 2024
1 parent ef84a1a commit 558f44d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

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

use PhpParser\Node;
use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;

final class SkipMoreDetailType
{
/**
* @param Name $node
*/
public function run(Node $node)
{
if ($node instanceof FullyQualified) {
return;
}

$this->execute($node);
}

private function execute(Name $node)
{
}
}
9 changes: 8 additions & 1 deletion rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
use Rector\NodeCollector\ValueObject\ArrayCallable;
use Rector\NodeTypeResolver\NodeTypeResolver;
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
use Rector\NodeTypeResolver\TypeComparator\TypeComparator;

final readonly class CallTypesResolver
{
public function __construct(
private NodeTypeResolver $nodeTypeResolver,
private TypeFactory $typeFactory,
private ReflectionProvider $reflectionProvider
private ReflectionProvider $reflectionProvider,
private TypeComparator $typeComparator
) {
}

Expand Down Expand Up @@ -74,6 +76,11 @@ private function resolveStrictArgValueType(Arg $arg): Type
return new MixedType();
}

$type = $this->nodeTypeResolver->getType($arg->value);
if (! $type->equals($argValueType) && $this->typeComparator->isSubtype($type, $argValueType)) {
return $type;
}

return $argValueType;
}

Expand Down

0 comments on commit 558f44d

Please sign in to comment.