-
Notifications
You must be signed in to change notification settings - Fork 566
Expand file tree
/
Copy pathCompositeRule.php
More file actions
55 lines (45 loc) · 1.03 KB
/
CompositeRule.php
File metadata and controls
55 lines (45 loc) · 1.03 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
<?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\Rule;
use function get_class;
/**
* Allows testing of rules which delegate work to NodeCallbackInvoker.
*
* @implements Rule<Node>
*
* @api
*/
final class CompositeRule implements Rule
{
private DirectRegistry $registry;
/**
* @template T of Node
* @param array<Rule<T>> $rules
*
* @api
*/
public function __construct(array $rules)
{
$this->registry = new DirectRegistry($rules);
}
public function getNodeType(): string
{
return Node::class;
}
public function processNode(Node $node, Scope&NodeCallbackInvoker&CollectedDataEmitter $scope): array
{
$errors = [];
$nodeType = get_class($node);
foreach ($this->registry->getRules($nodeType) as $rule) {
foreach ($rule->processNode($node, $scope) as $error) {
$errors[] = $error;
}
}
return $errors;
}
}