| Total Complexity | 10 |
| Total Lines | 47 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | class ValidationException extends ApieException implements LocalizationableException |
||
| 15 | { |
||
| 16 | private $errors; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var Throwable[][] | null |
||
| 20 | */ |
||
| 21 | private $exceptions; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param string[][]|ErrorBag $errors |
||
| 25 | * @param Throwable|null $previous |
||
| 26 | */ |
||
| 27 | public function __construct($errors, Throwable $previous = null) |
||
| 28 | { |
||
| 29 | $this->errors = $errors instanceof ErrorBag ? $errors->getErrors() : (array) $errors; |
||
| 30 | if (!$previous && $errors instanceof ErrorBag && $errors->hasErrors()) { |
||
| 31 | $this->exceptions = $errors->getExceptions(); |
||
| 32 | $tmp = reset($this->exceptions); |
||
| 33 | if ($tmp) { |
||
| 34 | $previous = reset($tmp) ? : null; |
||
| 35 | } |
||
| 36 | } |
||
| 37 | parent::__construct(422, 'A validation error occurred', $previous); |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Returns the validation errors. |
||
| 42 | * |
||
| 43 | * @return string[][] |
||
| 44 | */ |
||
| 45 | public function getErrors(): array |
||
| 46 | { |
||
| 47 | return $this->errors; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @return Throwable[][] | null |
||
| 52 | */ |
||
| 53 | public function getExceptions(): array |
||
| 56 | } |
||
| 57 | |||
| 58 | public function getI18n(): LocalizationInfo |
||
| 63 |