| Total Complexity | 7 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | class ValidationException extends Exception implements ValidationExceptionInterface, JsonSerializable |
||
| 12 | { |
||
| 13 | use ParseErrorsTrait; |
||
| 14 | |||
| 15 | private static ?ValidationExceptionFactoryInterface $userDefinedFactory = null; |
||
| 16 | |||
| 17 | /** @var Error[] */ |
||
| 18 | private array $errors; |
||
| 19 | |||
| 20 | public function __construct(array $errors, ?string $message = "", int $code = 400, ?Throwable $previous = null) |
||
| 21 | { |
||
| 22 | $this->errors = array_filter($errors, fn($e) => $e instanceof Error); |
||
| 23 | $message = $message ?? 'Input validation failed' . PHP_EOL . $this->errorsAsString(); |
||
| 24 | parent::__construct($message, $code, $previous); |
||
| 25 | } |
||
| 26 | |||
| 27 | /** @inheritDoc */ |
||
| 28 | public function getErrors(): array |
||
| 29 | { |
||
| 30 | return $this->errors; |
||
| 31 | } |
||
| 32 | |||
| 33 | public static function setFactory(?ValidationExceptionFactoryInterface $factory): void |
||
| 34 | { |
||
| 35 | self::$userDefinedFactory = $factory; |
||
| 36 | } |
||
| 37 | |||
| 38 | public static function hasFactory(): bool |
||
| 39 | { |
||
| 40 | return self::$userDefinedFactory instanceof ValidationExceptionFactoryInterface; |
||
| 41 | } |
||
| 42 | |||
| 43 | public static function getFactory(): ?ValidationExceptionFactoryInterface |
||
| 46 | } |
||
| 47 | |||
| 48 | public function toArray(): array |
||
| 54 | ]; |
||
| 55 | } |
||
| 56 | |||
| 57 | public function jsonSerialize(): array |
||
| 60 | } |
||
| 61 | } |
||
| 62 |