| Total Complexity | 10 |
| Total Lines | 61 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | final class Result |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var Error[] |
||
| 11 | */ |
||
| 12 | private array $errors = []; |
||
| 13 | private ?string $attribute; |
||
| 14 | |||
| 15 | 495 | public function __construct(string $attribute = null) |
|
| 16 | { |
||
| 17 | 495 | $this->attribute = $attribute; |
|
| 18 | } |
||
| 19 | |||
| 20 | 493 | public function isValid(): bool |
|
| 21 | { |
||
| 22 | 493 | return $this->errors === []; |
|
| 23 | } |
||
| 24 | |||
| 25 | 4 | public function isAttributeValid(string $attribute): bool |
|
| 26 | { |
||
| 27 | 4 | foreach ($this->errors as $error) { |
|
| 28 | 4 | $firstItem = $error->getAttribute(); |
|
| 29 | 4 | if ($firstItem === $attribute) { |
|
| 30 | 4 | return false; |
|
| 31 | } |
||
| 32 | } |
||
| 33 | |||
| 34 | 4 | return true; |
|
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @return Error[] |
||
| 39 | */ |
||
| 40 | 494 | public function getErrors(): array |
|
| 43 | } |
||
| 44 | |||
| 45 | 269 | public function addError(string $message, array $parameters = [], string $attribute = null): self |
|
| 46 | { |
||
| 57 | } |
||
| 58 | |||
| 59 | 16 | public function mergeError(Error $error): self |
|
| 70 |