| Total Complexity | 5 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | final class ValidationException extends \LogicException |
||
| 14 | { |
||
| 15 | public const DEFAULT_MESSAGE = 'Validation error'; |
||
| 16 | |||
| 17 | /** @var Error[] */ |
||
| 18 | private array $errors; |
||
| 19 | |||
| 20 | 4 | #[Pure] |
|
| 21 | private function __construct(Error ...$errors) |
||
| 22 | { |
||
| 23 | 4 | parent::__construct(self::DEFAULT_MESSAGE); |
|
| 24 | 4 | $this->errors = $errors; |
|
| 25 | 4 | } |
|
| 26 | |||
| 27 | /** @noinspection PhpParamsInspection */ |
||
| 28 | 2 | public static function fromConstraintViolationList(ConstraintViolationList $violationList): self |
|
| 29 | { |
||
| 30 | 2 | return self::fromConstraintViolations(...$violationList); |
|
| 31 | } |
||
| 32 | |||
| 33 | 2 | public static function fromConstraintViolations(ConstraintViolation ...$violations): self |
|
| 34 | { |
||
| 35 | 2 | return self::fromErrors(...array_map(static fn (ConstraintViolation $violation) => ValidationError::fromConstraint($violation), $violations)); |
|
| 36 | } |
||
| 37 | |||
| 38 | 4 | #[Pure] |
|
| 39 | public static function fromErrors(Error ...$errors): self |
||
| 40 | { |
||
| 41 | 4 | return new self(...$errors); |
|
| 42 | } |
||
| 43 | |||
| 44 | /** @return Error[] */ |
||
| 45 | 3 | public function getErrors(): array |
|
| 48 | } |
||
| 49 | } |
||
| 50 |