|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * (c) Copyright (c) 2016-2020 Ondřej Mirtes <[email protected]> |
| 5 | + * |
| 6 | + * This source file is subject to the MIT license. |
| 7 | + * |
| 8 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | + * of this software and associated documentation files (the "Software"), to deal |
| 10 | + * in the Software without restriction, including without limitation the rights |
| 11 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | + * copies of the Software, and to permit persons to whom the Software is |
| 13 | + * furnished to do so, subject to the following conditions: |
| 14 | + * |
| 15 | + * The above copyright notice and this permission notice shall be included in all |
| 16 | + * copies or substantial portions of the Software. |
| 17 | + * |
| 18 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 | + * SOFTWARE. |
| 25 | + */ |
| 26 | +declare(strict_types = 1); |
| 27 | + |
| 28 | +namespace CodeLts\CliTools; |
| 29 | + |
| 30 | +use CodeLts\CliTools\Error; |
| 31 | + |
| 32 | +class AnalysisResult |
| 33 | +{ |
| 34 | + |
| 35 | + /** @var \CodeLts\CliTools\Error[] sorted by their file name, line number and message */ |
| 36 | + private array $fileSpecificErrors; |
| 37 | + |
| 38 | + /** @var string[] */ |
| 39 | + private array $notFileSpecificErrors; |
| 40 | + |
| 41 | + /** @var string[] */ |
| 42 | + private array $internalErrors; |
| 43 | + |
| 44 | + /** @var string[] */ |
| 45 | + private array $warnings; |
| 46 | + |
| 47 | + private bool $defaultLevelUsed; |
| 48 | + |
| 49 | + private ?string $projectConfigFile; |
| 50 | + |
| 51 | + private bool $savedResultCache; |
| 52 | + |
| 53 | + /** |
| 54 | + * @param \CodeLts\CliTools\Error[] $fileSpecificErrors |
| 55 | + * @param string[] $notFileSpecificErrors |
| 56 | + * @param string[] $internalErrors |
| 57 | + * @param string[] $warnings |
| 58 | + * @param bool $defaultLevelUsed |
| 59 | + * @param string|null $projectConfigFile |
| 60 | + * @param bool $savedResultCache |
| 61 | + */ |
| 62 | + public function __construct( |
| 63 | + array $fileSpecificErrors, |
| 64 | + array $notFileSpecificErrors, |
| 65 | + array $internalErrors, |
| 66 | + array $warnings, |
| 67 | + bool $defaultLevelUsed, |
| 68 | + ?string $projectConfigFile, |
| 69 | + bool $savedResultCache |
| 70 | + ) |
| 71 | + { |
| 72 | + usort( |
| 73 | + $fileSpecificErrors, |
| 74 | + static function (Error $a, Error $b): int { |
| 75 | + return [ |
| 76 | + $a->getFile(), |
| 77 | + $a->getLine(), |
| 78 | + $a->getMessage(), |
| 79 | + ] <=> [ |
| 80 | + $b->getFile(), |
| 81 | + $b->getLine(), |
| 82 | + $b->getMessage(), |
| 83 | + ]; |
| 84 | + } |
| 85 | + ); |
| 86 | + |
| 87 | + $this->fileSpecificErrors = $fileSpecificErrors; |
| 88 | + $this->notFileSpecificErrors = $notFileSpecificErrors; |
| 89 | + $this->internalErrors = $internalErrors; |
| 90 | + $this->warnings = $warnings; |
| 91 | + $this->defaultLevelUsed = $defaultLevelUsed; |
| 92 | + $this->projectConfigFile = $projectConfigFile; |
| 93 | + $this->savedResultCache = $savedResultCache; |
| 94 | + } |
| 95 | + |
| 96 | + public function hasErrors(): bool |
| 97 | + { |
| 98 | + return $this->getTotalErrorsCount() > 0; |
| 99 | + } |
| 100 | + |
| 101 | + public function getTotalErrorsCount(): int |
| 102 | + { |
| 103 | + return count($this->fileSpecificErrors) + count($this->notFileSpecificErrors); |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * @return \CodeLts\CliTools\Error[] sorted by their file name, line number and message |
| 108 | + */ |
| 109 | + public function getFileSpecificErrors(): array |
| 110 | + { |
| 111 | + return $this->fileSpecificErrors; |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * @return string[] |
| 116 | + */ |
| 117 | + public function getNotFileSpecificErrors(): array |
| 118 | + { |
| 119 | + return $this->notFileSpecificErrors; |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * @return string[] |
| 124 | + */ |
| 125 | + public function getInternalErrors(): array |
| 126 | + { |
| 127 | + return $this->internalErrors; |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * @return string[] |
| 132 | + */ |
| 133 | + public function getWarnings(): array |
| 134 | + { |
| 135 | + return $this->warnings; |
| 136 | + } |
| 137 | + |
| 138 | + public function hasWarnings(): bool |
| 139 | + { |
| 140 | + return count($this->warnings) > 0; |
| 141 | + } |
| 142 | + |
| 143 | + public function isDefaultLevelUsed(): bool |
| 144 | + { |
| 145 | + return $this->defaultLevelUsed; |
| 146 | + } |
| 147 | + |
| 148 | + public function getProjectConfigFile(): ?string |
| 149 | + { |
| 150 | + return $this->projectConfigFile; |
| 151 | + } |
| 152 | + |
| 153 | + public function hasInternalErrors(): bool |
| 154 | + { |
| 155 | + return count($this->internalErrors) > 0; |
| 156 | + } |
| 157 | + |
| 158 | + public function isResultCacheSaved(): bool |
| 159 | + { |
| 160 | + return $this->savedResultCache; |
| 161 | + } |
| 162 | + |
| 163 | +} |
0 commit comments