Skip to content

Commit 657fc54

Browse files
committed
Introduce InTraitNode
1 parent e9ef210 commit 657fc54

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
use PHPStan\Node\InForeachNode;
9090
use PHPStan\Node\InFunctionNode;
9191
use PHPStan\Node\InstantiationCallableNode;
92+
use PHPStan\Node\InTraitNode;
9293
use PHPStan\Node\LiteralArrayItem;
9394
use PHPStan\Node\LiteralArrayNode;
9495
use PHPStan\Node\MatchExpressionArm;
@@ -4362,7 +4363,10 @@ private function processNodesForTraitUse($node, ClassReflection $traitReflection
43624363
$methodAst->setAttribute('originalTraitMethodName', $methodAst->name->toLowerString());
43634364
$methodAst->name = $methodNames[$methodName];
43644365
}
4365-
$this->processStmtNodes($node, $stmts, $scope->enterTrait($traitReflection), $nodeCallback, StatementContext::createTopLevel());
4366+
4367+
$traitScope = $scope->enterTrait($traitReflection);
4368+
$nodeCallback(new InTraitNode($node, $traitReflection), $traitScope);
4369+
$this->processStmtNodes($node, $stmts, $traitScope, $nodeCallback, StatementContext::createTopLevel());
43664370
return;
43674371
}
43684372
if ($node instanceof Node\Stmt\ClassLike) {

src/Node/InTraitNode.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Node;
4+
5+
use PhpParser\Node;
6+
use PHPStan\Reflection\ClassReflection;
7+
8+
/** @api */
9+
class InTraitNode extends Node\Stmt implements VirtualNode
10+
{
11+
12+
public function __construct(private Node\Stmt\Trait_ $originalNode, private ClassReflection $traitReflection)
13+
{
14+
parent::__construct($originalNode->getAttributes());
15+
}
16+
17+
public function getOriginalNode(): Node\Stmt\Trait_
18+
{
19+
return $this->originalNode;
20+
}
21+
22+
public function getTraitReflection(): ClassReflection
23+
{
24+
return $this->traitReflection;
25+
}
26+
27+
public function getType(): string
28+
{
29+
return 'PHPStan_Stmt_InTraitNode';
30+
}
31+
32+
/**
33+
* @return string[]
34+
*/
35+
public function getSubNodeNames(): array
36+
{
37+
return [];
38+
}
39+
40+
}

0 commit comments

Comments
 (0)