forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNonexistentAnalysedTraitRule.php
More file actions
49 lines (41 loc) · 1.09 KB
/
Copy pathNonexistentAnalysedTraitRule.php
File metadata and controls
49 lines (41 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php declare(strict_types = 1);
namespace PHPStan\Testing;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\ShouldNotHappenException;
use function sprintf;
/**
* @implements Rule<Node\Stmt\Trait_>
*/
final class NonexistentAnalysedTraitRule implements Rule
{
public function __construct(private ReflectionProvider $reflectionProvider)
{
}
public function getNodeType(): string
{
return Node\Stmt\Trait_::class;
}
public function processNode(Node $node, Scope $scope): array
{
if ($node->namespacedName === null) {
throw new ShouldNotHappenException();
}
$traitName = $node->namespacedName->toString();
if ($this->reflectionProvider->hasClass($traitName)) {
return [];
}
return [
RuleErrorBuilder::message(sprintf(
'Trait %s not found in ReflectionProvider. Configure "autoload-dev" section in composer.json to include your tests directory.',
$traitName,
))
->identifier('phpstan.traitNotFound')
->nonIgnorable()
->build(),
];
}
}