| Total Complexity | 5 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | class ValidationException extends Exception implements ValidationExceptionInterface |
||
| 11 | { |
||
| 12 | private static ?ValidationExceptionFactoryInterface $userDefinedFactory = null; |
||
| 13 | |||
| 14 | /** @var Error[] */ |
||
| 15 | private array $errors; |
||
| 16 | |||
| 17 | public function __construct(array $errors, ?string $message = "", int $code = 422, ?Throwable $previous = null) |
||
| 18 | { |
||
| 19 | $this->errors = array_filter($errors, fn($e) => $e instanceof Error); |
||
| 20 | parent::__construct($message ?? '', $code, $previous); |
||
| 21 | } |
||
| 22 | |||
| 23 | /** @inheritDoc */ |
||
| 24 | public function getErrors(): array |
||
| 25 | { |
||
| 26 | return $this->errors; |
||
| 27 | } |
||
| 28 | |||
| 29 | public static function setFactory(?ValidationExceptionFactoryInterface $factory): void |
||
| 30 | { |
||
| 31 | self::$userDefinedFactory = $factory; |
||
| 32 | } |
||
| 33 | |||
| 34 | public static function hasFactory(): bool |
||
| 35 | { |
||
| 36 | return self::$userDefinedFactory instanceof ValidationExceptionFactoryInterface; |
||
| 37 | } |
||
| 38 | |||
| 39 | public static function getFactory(): ?ValidationExceptionFactoryInterface |
||
| 42 | } |
||
| 43 | } |
||
| 44 |