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