forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNonexistentAnalysedClassRule.php
More file actions
47 lines (39 loc) · 1.07 KB
/
Copy pathNonexistentAnalysedClassRule.php
File metadata and controls
47 lines (39 loc) · 1.07 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
<?php declare(strict_types = 1);
namespace PHPStan\Testing;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Node\InClassNode;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use function sprintf;
/**
* @implements Rule<InClassNode>
*/
final class NonexistentAnalysedClassRule implements Rule
{
public function __construct(private ReflectionProvider $reflectionProvider)
{
}
public function getNodeType(): string
{
return InClassNode::class;
}
public function processNode(Node $node, Scope $scope): array
{
$className = $node->getClassReflection()->getName();
if ($this->reflectionProvider->hasClass($className)) {
return [];
}
return [
RuleErrorBuilder::message(sprintf(
'%s %s not found in ReflectionProvider. Configure "autoload-dev" section in composer.json to include your tests directory.',
$node->getClassReflection()->getClassTypeDescription(),
$node->getClassReflection()->getName(),
))
->identifier('phpstan.classNotFound')
->nonIgnorable()
->build(),
];
}
}