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, private ?CollectedDataNodeReads $reads = null)
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: if ($this->reads !== null) {
35: $this->reads->addCollectorType($collectorType);
36: }
37:
38: $result = [];
39: foreach ($this->collectedData as $filePath => $collectedDataPerCollector) {
40: if (!isset($collectedDataPerCollector[$collectorType])) {
41: continue;
42: }
43:
44: foreach ($collectedDataPerCollector[$collectorType] as $rawData) {
45: $result[$filePath][] = $rawData;
46: }
47: }
48:
49: return $result;
50: }
51:
52: /**
53: * Indicates that only files were passed to the analyser, not directory paths.
54: *
55: * True being returned strongly suggests that it's a partial analysis, not full project analysis.
56: */
57: public function isOnlyFilesAnalysis(): bool
58: {
59: if ($this->reads !== null) {
60: $this->reads->addOnlyFiles();
61: }
62:
63: return $this->onlyFiles;
64: }
65:
66: #[Override]
67: public function getType(): string
68: {
69: return 'PHPStan_Node_CollectedDataNode';
70: }
71:
72: /**
73: * @return array{}
74: */
75: #[Override]
76: public function getSubNodeNames(): array
77: {
78: return [];
79: }
80:
81: }
82: