Skip to content

Commit

Permalink
[Php71] Remove parent lookup on CountableAnalyzer (#4251)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik authored Jun 17, 2023
1 parent 6282607 commit 3122f5e
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions rules/Php71/NodeAnalyzer/CountableAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\ClassLike;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\Php\PhpPropertyReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\ArrayType;
Expand All @@ -19,7 +20,8 @@
use PHPStan\Type\TypeWithClassName;
use PHPStan\Type\UnionType;
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\PhpParser\AstResolver;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\NodeTypeResolver;
use Rector\TypeDeclaration\AlreadyAssignDetector\ConstructorAssignDetector;
Expand All @@ -30,9 +32,10 @@ public function __construct(
private readonly NodeTypeResolver $nodeTypeResolver,
private readonly NodeNameResolver $nodeNameResolver,
private readonly ReflectionProvider $reflectionProvider,
private readonly BetterNodeFinder $betterNodeFinder,
private readonly PropertyFetchAnalyzer $propertyFetchAnalyzer,
private readonly ConstructorAssignDetector $constructorAssignDetector
private readonly ConstructorAssignDetector $constructorAssignDetector,
private readonly ReflectionResolver $reflectionResolver,
private readonly AstResolver $astResolver
) {
}

Expand Down Expand Up @@ -110,12 +113,18 @@ private function isIterableOrFilledAtConstruct(
return true;
}

$classLike = $this->betterNodeFinder->findParentType($propertyFetch, ClassLike::class);
if (! $classLike instanceof ClassLike) {
if ($propertyFetch->name instanceof Expr) {
return false;
}

if ($propertyFetch->name instanceof Expr) {
$classReflection = $this->reflectionResolver->resolveClassReflection($propertyFetch);
if (! $classReflection instanceof ClassReflection) {
return false;
}

$classLike = $this->astResolver->resolveClassFromName($classReflection->getName());

if (! $classLike instanceof ClassLike) {
return false;
}

Expand Down

0 comments on commit 3122f5e

Please sign in to comment.