Skip to content

Commit

Permalink
Use instanceof check on ClassReflection resolve (#4547)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jul 20, 2023
1 parent 141a94a commit f77e355
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ public function processNodes(
$scope = $formerMutatingScope ?? $this->scopeFactory->createFromFile($filePath);

// skip chain method calls, performance issue: https://github.com/phpstan/phpstan/issues/254
$nodeCallback = function (Node $node, MutatingScope $mutatingScope) use (
&$nodeCallback,
$filePath
): void {
$nodeCallback = function (Node $node, MutatingScope $mutatingScope) use (&$nodeCallback, $filePath): void {
if ($node instanceof FileWithoutNamespace) {
$this->nodeScopeResolver->processNodes($node->stmts, $mutatingScope, $nodeCallback);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PhpParser\Node\UnionType;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\MixedType;
use PHPStan\Type\TypeCombinator;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
Expand Down Expand Up @@ -149,11 +150,11 @@ public function refactor(Node $node): ?Node
continue;
}

if ($classReflection === null) {
if (! $classReflection instanceof ClassReflection) {
$classReflection = $this->reflectionResolver->resolveClassReflection($node);
}

if ($classReflection === null) {
if (! $classReflection instanceof ClassReflection) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Property;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\UnionType;
Expand Down Expand Up @@ -113,11 +114,11 @@ public function refactor(Node $node): ?Node
continue;
}

if ($classReflection === null) {
if (! $classReflection instanceof ClassReflection) {
$classReflection = $this->reflectionResolver->resolveClassReflection($node);
}

if ($classReflection === null) {
if (! $classReflection instanceof ClassReflection) {
return null;
}

Expand Down

0 comments on commit f77e355

Please sign in to comment.