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: /** @api */
12: class CollectedDataNode extends NodeAbstract
13: {
14:
15: /**
16: * @param CollectedData[] $collectedData
17: */
18: public function __construct(private array $collectedData, private bool $onlyFiles)
19: {
20: parent::__construct([]);
21: }
22:
23: /**
24: * @template TCollector of Collector<Node, TValue>
25: * @template TValue
26: * @param class-string<TCollector> $collectorType
27: * @return array<string, list<TValue>>
28: */
29: public function get(string $collectorType): array
30: {
31: $result = [];
32: foreach ($this->collectedData as $collectedData) {
33: if ($collectedData->getCollectorType() !== $collectorType) {
34: continue;
35: }
36:
37: $filePath = $collectedData->getFilePath();
38: if (!array_key_exists($filePath, $result)) {
39: $result[$filePath] = [];
40: }
41:
42: $result[$filePath][] = $collectedData->getData();
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: public function getType(): string
59: {
60: return 'PHPStan_Node_CollectedDataNode';
61: }
62:
63: /**
64: * @return array{}
65: */
66: public function getSubNodeNames(): array
67: {
68: return [];
69: }
70:
71: }
72: