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