Skip to content

Commit 7ed992a

Browse files
committed
TraitHandler
1 parent 2674c0f commit 7ed992a

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Analyser\Generator\StmtHandler;
4+
5+
use Generator;
6+
use PhpParser\Node\Stmt;
7+
use PhpParser\Node\Stmt\Trait_;
8+
use PHPStan\Analyser\Generator\GeneratorScope;
9+
use PHPStan\Analyser\Generator\StmtAnalysisResult;
10+
use PHPStan\Analyser\Generator\StmtHandler;
11+
use PHPStan\Analyser\StatementContext;
12+
use PHPStan\DependencyInjection\AutowiredService;
13+
14+
/**
15+
* @implements StmtHandler<Trait_>
16+
*/
17+
#[AutowiredService]
18+
final class TraitHandler implements StmtHandler
19+
{
20+
21+
public function supports(Stmt $stmt): bool
22+
{
23+
return $stmt instanceof Trait_;
24+
}
25+
26+
public function analyseStmt(Stmt $stmt, GeneratorScope $scope, StatementContext $context, ?callable $alternativeNodeCallback): Generator
27+
{
28+
// This handler is there as a no-op. Rules looking for Trait_ node
29+
// will be called but the internals of a trait are analysed
30+
// in context of each TraitUse, not as a standalone unit.
31+
32+
yield from [];
33+
34+
return new StmtAnalysisResult(
35+
$scope,
36+
hasYield: false,
37+
isAlwaysTerminating: false,
38+
exitPoints: [],
39+
throwPoints: [],
40+
impurePoints: [],
41+
);
42+
}
43+
44+
}

0 commit comments

Comments
 (0)