1: | <?php declare(strict_types = 1); |
2: | |
3: | namespace PHPStan\Command; |
4: | |
5: | use PHPStan\Analyser\Error; |
6: | use PHPStan\Analyser\InternalError; |
7: | use PHPStan\Collectors\CollectedData; |
8: | use function count; |
9: | use function usort; |
10: | |
11: | |
12: | |
13: | |
14: | final class AnalysisResult |
15: | { |
16: | |
17: | |
18: | private array $fileSpecificErrors; |
19: | |
20: | |
21: | |
22: | |
23: | |
24: | |
25: | |
26: | |
27: | |
28: | public function __construct( |
29: | array $fileSpecificErrors, |
30: | private array $notFileSpecificErrors, |
31: | private array $internalErrors, |
32: | private array $warnings, |
33: | private array $collectedData, |
34: | private bool $defaultLevelUsed, |
35: | private ?string $projectConfigFile, |
36: | private bool $savedResultCache, |
37: | private int $peakMemoryUsageBytes, |
38: | private bool $isResultCacheUsed, |
39: | private array $changedProjectExtensionFilesOutsideOfAnalysedPaths, |
40: | ) |
41: | { |
42: | usort( |
43: | $fileSpecificErrors, |
44: | static fn (Error $a, Error $b): int => [ |
45: | $a->getFile(), |
46: | $a->getLine(), |
47: | $a->getMessage(), |
48: | ] <=> [ |
49: | $b->getFile(), |
50: | $b->getLine(), |
51: | $b->getMessage(), |
52: | ], |
53: | ); |
54: | |
55: | $this->fileSpecificErrors = $fileSpecificErrors; |
56: | } |
57: | |
58: | public function hasErrors(): bool |
59: | { |
60: | return $this->getTotalErrorsCount() > 0; |
61: | } |
62: | |
63: | public function getTotalErrorsCount(): int |
64: | { |
65: | return count($this->fileSpecificErrors) + count($this->notFileSpecificErrors); |
66: | } |
67: | |
68: | |
69: | |
70: | |
71: | public function getFileSpecificErrors(): array |
72: | { |
73: | return $this->fileSpecificErrors; |
74: | } |
75: | |
76: | |
77: | |
78: | |
79: | public function getNotFileSpecificErrors(): array |
80: | { |
81: | return $this->notFileSpecificErrors; |
82: | } |
83: | |
84: | |
85: | |
86: | |
87: | public function getInternalErrorObjects(): array |
88: | { |
89: | return $this->internalErrors; |
90: | } |
91: | |
92: | |
93: | |
94: | |
95: | public function getWarnings(): array |
96: | { |
97: | return $this->warnings; |
98: | } |
99: | |
100: | public function hasWarnings(): bool |
101: | { |
102: | return count($this->warnings) > 0; |
103: | } |
104: | |
105: | |
106: | |
107: | |
108: | public function getCollectedData(): array |
109: | { |
110: | return $this->collectedData; |
111: | } |
112: | |
113: | public function isDefaultLevelUsed(): bool |
114: | { |
115: | return $this->defaultLevelUsed; |
116: | } |
117: | |
118: | public function getProjectConfigFile(): ?string |
119: | { |
120: | return $this->projectConfigFile; |
121: | } |
122: | |
123: | public function hasInternalErrors(): bool |
124: | { |
125: | return count($this->internalErrors) > 0; |
126: | } |
127: | |
128: | public function isResultCacheSaved(): bool |
129: | { |
130: | return $this->savedResultCache; |
131: | } |
132: | |
133: | public function getPeakMemoryUsageBytes(): int |
134: | { |
135: | return $this->peakMemoryUsageBytes; |
136: | } |
137: | |
138: | public function isResultCacheUsed(): bool |
139: | { |
140: | return $this->isResultCacheUsed; |
141: | } |
142: | |
143: | |
144: | |
145: | |
146: | public function getChangedProjectExtensionFilesOutsideOfAnalysedPaths(): array |
147: | { |
148: | return $this->changedProjectExtensionFilesOutsideOfAnalysedPaths; |
149: | } |
150: | |
151: | } |
152: | |