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