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