Total Complexity | 5 |
Total Lines | 32 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
8 | trait ParseErrors |
||
9 | { |
||
10 | /** @return Error[] */ |
||
11 | abstract public function getErrors(): array; |
||
12 | |||
13 | public function errorsAsArray(): array |
||
14 | { |
||
15 | $errors = []; |
||
16 | foreach ($this->getErrors() as $error) { |
||
17 | $errors[] = [ |
||
18 | 'field' => $error->field(), |
||
19 | 'message' => $error->message(), |
||
20 | 'type' => $error->rule() ? array_reverse(explode('\\', get_class($error->rule())))[0] : null |
||
21 | ]; |
||
22 | } |
||
23 | |||
24 | return $errors; |
||
25 | } |
||
26 | |||
27 | public function errorsAsString(): string |
||
40 | } |
||
41 | } |
||
42 |