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: /** @api */
11: class AnalysisResult
12: {
13:
14: /** @var Error[] sorted by their file name, line number and message */
15: private array $fileSpecificErrors;
16:
17: /**
18: * @param Error[] $fileSpecificErrors
19: * @param string[] $notFileSpecificErrors
20: * @param string[] $internalErrors
21: * @param string[] $warnings
22: * @param CollectedData[] $collectedData
23: */
24: public function __construct(
25: array $fileSpecificErrors,
26: private array $notFileSpecificErrors,
27: private array $internalErrors,
28: private array $warnings,
29: private array $collectedData,
30: private bool $defaultLevelUsed,
31: private ?string $projectConfigFile,
32: private bool $savedResultCache,
33: )
34: {
35: usort(
36: $fileSpecificErrors,
37: static fn (Error $a, Error $b): int => [
38: $a->getFile(),
39: $a->getLine(),
40: $a->getMessage(),
41: ] <=> [
42: $b->getFile(),
43: $b->getLine(),
44: $b->getMessage(),
45: ],
46: );
47:
48: $this->fileSpecificErrors = $fileSpecificErrors;
49: }
50:
51: public function hasErrors(): bool
52: {
53: return $this->getTotalErrorsCount() > 0;
54: }
55:
56: public function getTotalErrorsCount(): int
57: {
58: return count($this->fileSpecificErrors) + count($this->notFileSpecificErrors);
59: }
60:
61: /**
62: * @return Error[] sorted by their file name, line number and message
63: */
64: public function getFileSpecificErrors(): array
65: {
66: return $this->fileSpecificErrors;
67: }
68:
69: /**
70: * @return string[]
71: */
72: public function getNotFileSpecificErrors(): array
73: {
74: return $this->notFileSpecificErrors;
75: }
76:
77: /**
78: * @return string[]
79: */
80: public function getInternalErrors(): array
81: {
82: return $this->internalErrors;
83: }
84:
85: /**
86: * @return string[]
87: */
88: public function getWarnings(): array
89: {
90: return $this->warnings;
91: }
92:
93: public function hasWarnings(): bool
94: {
95: return count($this->warnings) > 0;
96: }
97:
98: /**
99: * @return CollectedData[]
100: */
101: public function getCollectedData(): array
102: {
103: return $this->collectedData;
104: }
105:
106: public function isDefaultLevelUsed(): bool
107: {
108: return $this->defaultLevelUsed;
109: }
110:
111: public function getProjectConfigFile(): ?string
112: {
113: return $this->projectConfigFile;
114: }
115:
116: public function hasInternalErrors(): bool
117: {
118: return count($this->internalErrors) > 0;
119: }
120:
121: public function isResultCacheSaved(): bool
122: {
123: return $this->savedResultCache;
124: }
125:
126: }
127: