1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Node;
4:
5: use PhpParser\Node;
6: use PhpParser\NodeAbstract;
7: use PHPStan\Collectors\CollectedData;
8: use PHPStan\Collectors\Collector;
9:
10: /**
11: * @api
12: * @phpstan-import-type CollectorData from CollectedData
13: */
14: final class CollectedDataNode extends NodeAbstract implements VirtualNode
15: {
16:
17: /**
18: * @param CollectorData $collectedData
19: */
20: public function __construct(private array $collectedData, private bool $onlyFiles)
21: {
22: parent::__construct([]);
23: }
24:
25: /**
26: * @template TCollector of Collector<Node, TValue>
27: * @template TValue
28: * @param class-string<TCollector> $collectorType
29: * @return array<string, list<TValue>>
30: */
31: public function get(string $collectorType): array
32: {
33: $result = [];
34: foreach ($this->collectedData as $filePath => $collectedDataPerCollector) {
35: if (!isset($collectedDataPerCollector[$collectorType])) {
36: continue;
37: }
38:
39: foreach ($collectedDataPerCollector[$collectorType] as $rawData) {
40: $result[$filePath][] = $rawData;
41: }
42: }
43:
44: return $result;
45: }
46:
47: /**
48: * Indicates that only files were passed to the analyser, not directory paths.
49: *
50: * True being returned strongly suggests that it's a partial analysis, not full project analysis.
51: */
52: public function isOnlyFilesAnalysis(): bool
53: {
54: return $this->onlyFiles;
55: }
56:
57: public function getType(): string
58: {
59: return 'PHPStan_Node_CollectedDataNode';
60: }
61:
62: /**
63: * @return array{}
64: */
65: public function getSubNodeNames(): array
66: {
67: return [];
68: }
69:
70: }
71: