Skip to content

Commit

Permalink
[NodeTypeResolver] Remove findParentType() on PropertyFetchTypeResolv…
Browse files Browse the repository at this point in the history
…er (#4202)
  • Loading branch information
samsonasik committed Jun 12, 2023
1 parent 58047d4 commit d90d321
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@

use PhpParser\Node;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Stmt\ClassLike;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\Contract\NodeTypeResolverInterface;
use Rector\NodeTypeResolver\Node\AttributeKey;
Expand All @@ -30,8 +28,7 @@ final class PropertyFetchTypeResolver implements NodeTypeResolverInterface

public function __construct(
private readonly NodeNameResolver $nodeNameResolver,
private readonly ReflectionProvider $reflectionProvider,
private readonly BetterNodeFinder $betterNodeFinder
private readonly ReflectionProvider $reflectionProvider
) {
}

Expand Down Expand Up @@ -62,16 +59,7 @@ public function resolve(Node $node): Type

$scope = $node->getAttribute(AttributeKey::SCOPE);
if (! $scope instanceof Scope) {
$classLike = $this->betterNodeFinder->findParentType($node, ClassLike::class);

// fallback to class, since property fetches are not scoped by PHPStan
if ($classLike instanceof ClassLike) {
$scope = $classLike->getAttribute(AttributeKey::SCOPE);
}

if (! $scope instanceof Scope) {
return new MixedType();
}
return new MixedType();
}

return $scope->getType($node);
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/RectorKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class RectorKernel
/**
* @var string
*/
private const CACHE_KEY = 'v112';
private const CACHE_KEY = 'v113';

private ContainerInterface|null $container = null;

Expand Down

0 comments on commit d90d321

Please sign in to comment.