| 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: | * |
| 11: | * ```php |
| 12: | * public function processNode(Node $node, Scope&CollectedDataEmitter $scope): array |
| 13: | * ``` |
| 14: | * |
| 15: | * It allows rules to emit collected data directly, without having to write |
| 16: | * a separate complex Collector class. The emitted data is aggregated the same way |
| 17: | * as data from Collectors and can be consumed by rules registered |
| 18: | * for CollectedDataNode. |
| 19: | * |
| 20: | * The actual MyCollector class in the example has to exist, to verify |
| 21: | * the data type statically, and to identify the collected data. |
| 22: | * |
| 23: | * The referenced MyCollector class should NOT be registered |
| 24: | * as a collector, unless you also want it to collect data on its own. |
| 25: | * |
| 26: | * ```php |
| 27: | * $scope->emitCollectedData(MyCollector::class, ['some', 'data']); |
| 28: | * ``` |
| 29: | * |
| 30: | * @api |
| 31: | */ |
| 32: | interface CollectedDataEmitter |
| 33: | { |
| 34: | |
| 35: | /** |
| 36: | * @template TCollector of Collector<Node, mixed> |
| 37: | * @param class-string<TCollector> $collectorType |
| 38: | * @param template-type<TCollector, Collector, 'TValue'> $data |
| 39: | */ |
| 40: | public function emitCollectedData(string $collectorType, mixed $data): void; |
| 41: | |
| 42: | } |
| 43: |