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