-
Notifications
You must be signed in to change notification settings - Fork 566
Expand file tree
/
Copy pathDelayedRule.php
More file actions
59 lines (48 loc) · 1.14 KB
/
DelayedRule.php
File metadata and controls
59 lines (48 loc) · 1.14 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
50
51
52
53
54
55
56
57
58
59
<?php declare(strict_types = 1);
namespace PHPStan\Testing;
use PhpParser\Node;
use PHPStan\Analyser\CollectedDataEmitter;
use PHPStan\Analyser\NodeCallbackInvoker;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\DirectRegistry;
use PHPStan\Rules\IdentifierRuleError;
use PHPStan\Rules\Registry;
use PHPStan\Rules\Rule;
use function get_class;
/**
* @implements Rule<Node>
*/
final class DelayedRule implements Rule
{
private Registry $registry;
/** @var list<IdentifierRuleError> */
private array $errors = [];
/**
* @param Rule<covariant Node> $rule
*/
public function __construct(Rule $rule)
{
$this->registry = new DirectRegistry([$rule]);
}
public function getNodeType(): string
{
return Node::class;
}
/**
* @return list<IdentifierRuleError>
*/
public function getDelayedErrors(): array
{
return $this->errors;
}
public function processNode(Node $node, Scope&NodeCallbackInvoker&CollectedDataEmitter $scope): array
{
$nodeType = get_class($node);
foreach ($this->registry->getRules($nodeType) as $rule) {
foreach ($rule->processNode($node, $scope) as $error) {
$this->errors[] = $error;
}
}
return [];
}
}