| Total Complexity | 8 |
| Total Lines | 47 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class ErrorReporting implements Result |
||
| 10 | { |
||
| 11 | use GuardTrait; |
||
| 12 | |||
| 13 | /** @var Error[] */ |
||
| 14 | private array $errors = []; |
||
| 15 | |||
| 16 | final public function __construct(Error | Result ...$errors) |
||
| 17 | { |
||
| 18 | foreach ($errors as $errorOrResult) { |
||
| 19 | array_push( |
||
| 20 | $this->errors, |
||
| 21 | ...($errorOrResult instanceof Error ? [$errorOrResult] : $errorOrResult->getErrors()) |
||
| 22 | ); |
||
| 23 | } |
||
| 24 | } |
||
| 25 | |||
| 26 | public function add(Error | Result ...$errors): self |
||
| 27 | { |
||
| 28 | return new self(...$this->errors, ...$errors); |
||
| 29 | } |
||
| 30 | |||
| 31 | public function addError(string $message, ?string $field = null): self |
||
| 32 | { |
||
| 33 | return $this->add(new ErrorMessage($message, $field)); |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @inheritDoc |
||
| 38 | */ |
||
| 39 | public function isOk(): bool |
||
| 40 | { |
||
| 41 | return empty($this->errors); |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @inheritDoc |
||
| 46 | */ |
||
| 47 | public function getErrors(): array |
||
| 50 | } |
||
| 51 | |||
| 52 | /** @throws ValidationExceptionInterface */ |
||
| 53 | public function guard(ValidationExceptionInterface | string | null $validationException = null): void |
||
| 56 | } |
||
| 57 | } |
||
| 58 |