diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index c8922c8d29..b69e02a10b 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -89,6 +89,7 @@ use PHPStan\Node\InForeachNode; use PHPStan\Node\InFunctionNode; use PHPStan\Node\InstantiationCallableNode; +use PHPStan\Node\InTraitNode; use PHPStan\Node\LiteralArrayItem; use PHPStan\Node\LiteralArrayNode; use PHPStan\Node\MatchExpressionArm; @@ -4362,7 +4363,10 @@ private function processNodesForTraitUse($node, ClassReflection $traitReflection $methodAst->setAttribute('originalTraitMethodName', $methodAst->name->toLowerString()); $methodAst->name = $methodNames[$methodName]; } - $this->processStmtNodes($node, $stmts, $scope->enterTrait($traitReflection), $nodeCallback, StatementContext::createTopLevel()); + + $traitScope = $scope->enterTrait($traitReflection); + $nodeCallback(new InTraitNode($node, $traitReflection), $traitScope); + $this->processStmtNodes($node, $stmts, $traitScope, $nodeCallback, StatementContext::createTopLevel()); return; } if ($node instanceof Node\Stmt\ClassLike) { diff --git a/src/Node/InTraitNode.php b/src/Node/InTraitNode.php new file mode 100644 index 0000000000..688c04499b --- /dev/null +++ b/src/Node/InTraitNode.php @@ -0,0 +1,40 @@ +getAttributes()); + } + + public function getOriginalNode(): Node\Stmt\Trait_ + { + return $this->originalNode; + } + + public function getTraitReflection(): ClassReflection + { + return $this->traitReflection; + } + + public function getType(): string + { + return 'PHPStan_Stmt_InTraitNode'; + } + + /** + * @return string[] + */ + public function getSubNodeNames(): array + { + return []; + } + +}