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: use function array_key_exists;
10:
11: /**
12: * @api
13: */
14: final class CollectedDataNode extends NodeAbstract implements VirtualNode
15: {
16:
17: /**
18: * @param CollectedData[] $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 $collectedData) {
35: if ($collectedData->getCollectorType() !== $collectorType) {
36: continue;
37: }
38:
39: $filePath = $collectedData->getFilePath();
40: if (!array_key_exists($filePath, $result)) {
41: $result[$filePath] = [];
42: }
43:
44: $result[$filePath][] = $collectedData->getData();
45: }
46:
47: return $result;
48: }
49:
50: /**
51: * Indicates that only files were passed to the analyser, not directory paths.
52: *
53: * True being returned strongly suggests that it's a partial analysis, not full project analysis.
54: */
55: public function isOnlyFilesAnalysis(): bool
56: {
57: return $this->onlyFiles;
58: }
59:
60: public function getType(): string
61: {
62: return 'PHPStan_Node_CollectedDataNode';
63: }
64:
65: /**
66: * @return array{}
67: */
68: public function getSubNodeNames(): array
69: {
70: return [];
71: }
72:
73: }
74: