File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace PHPStan \Testing ;
4+
5+ use PhpParser \Node ;
6+ use PHPStan \Analyser \NodeCallbackInvoker ;
7+ use PHPStan \Analyser \Scope ;
8+ use PHPStan \Rules \DirectRegistry ;
9+ use PHPStan \Rules \Rule ;
10+ use function get_class ;
11+
12+ /**
13+ * Allows testing of rules which delegate work to NodeCallbackInvoker.
14+ *
15+ * @implements Rule<Node>
16+ *
17+ * @api
18+ */
19+ final class CompositeRule implements Rule
20+ {
21+
22+ private DirectRegistry $ registry ;
23+
24+ public function __construct (DirectRegistry $ ruleRegisty )
25+ {
26+ $ this ->registry = $ ruleRegisty ;
27+ }
28+
29+ public function getNodeType (): string
30+ {
31+ return Node::class;
32+ }
33+
34+ public function processNode (Node $ node , Scope &NodeCallbackInvoker $ scope ): array
35+ {
36+ $ errors = [];
37+
38+ $ nodeType = get_class ($ node );
39+ foreach ($ this ->registry ->getRules ($ nodeType ) as $ rule ) {
40+ foreach ($ rule ->processNode ($ node , $ scope ) as $ error ) {
41+ $ errors [] = $ error ;
42+ }
43+ }
44+
45+ return $ errors ;
46+ }
47+
48+ }
You can’t perform that action at this time.
0 commit comments