Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed May 21, 2024
1 parent 112c5ca commit 45786a2
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Rules/NoReturnSetterMethodRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\NodeTraverser;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Rules\Rule;
use Symplify\PHPStanRules\NodeFinder\TypeAwareNodeFinder;
use Symplify\PHPStanRules\NodeVisitor\HasScopedReturnNodeVisitor;
Expand Down Expand Up @@ -57,8 +58,7 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

$classReflection = $scope->getClassReflection();
if (! $classReflection->isClass()) {
if (! $this->isInsideClassReflection($scope)) {
return [];
}

Expand Down Expand Up @@ -124,4 +124,14 @@ private function hasReturnReturnFunctionLike(ClassMethod $classMethod): bool
$yield = $this->typeAwareNodeFinder->findFirstInstanceOf($classMethod, Yield_::class);
return $yield instanceof Yield_;
}

private function isInsideClassReflection(Scope $scope): bool
{
$classReflection = $scope->getClassReflection();
if (! $classReflection instanceof ClassReflection) {
return false;
}

return $classReflection->isClass();
}
}

0 comments on commit 45786a2

Please sign in to comment.