1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Analyser;
4:
5: use PhpParser\Node;
6: use PHPStan\Collectors\Collector;
7:
8: /**
9: * The interface CollectedDataEmitter can be typehinted in 2nd parameter of Rule::processNode()
10: * and Collector::processNode():
11: *
12: * ```php
13: * public function processNode(Node $node, Scope&CollectedDataEmitter $scope): array
14: * ```
15: *
16: * It allows rules to emit collected data directly, without having to write
17: * a separate complex Collector class, and collectors to emit data for other collectors
18: * besides the data they return. The emitted data is aggregated the same way
19: * as data from Collectors and can be consumed by rules registered
20: * for CollectedDataNode.
21: *
22: * The actual MyCollector class in the example has to exist, to verify
23: * the data type statically, and to identify the collected data.
24: *
25: * The referenced MyCollector class should NOT be registered
26: * as a collector, unless you also want it to collect data on its own.
27: *
28: * ```php
29: * $scope->emitCollectedData(MyCollector::class, ['some', 'data']);
30: * ```
31: *
32: * @api
33: * @api-do-not-implement
34: */
35: interface CollectedDataEmitter
36: {
37:
38: /**
39: * @template TCollector of Collector<Node, mixed>
40: * @param class-string<TCollector> $collectorType
41: * @param template-type<TCollector, Collector, 'TValue'> $data
42: */
43: public function emitCollectedData(string $collectorType, mixed $data): void;
44:
45: }
46: