Total Complexity | 11 |
Total Lines | 59 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
9 | class ValidationResultSet |
||
10 | { |
||
11 | use Guard; |
||
12 | |||
13 | /** @var Result[] */ |
||
14 | private array $validationResults = []; |
||
15 | |||
16 | public function add(Result ...$results): self |
||
17 | { |
||
18 | $instance = clone $this; |
||
19 | array_push($instance->validationResults, ...$results); |
||
20 | return $instance; |
||
21 | } |
||
22 | |||
23 | public function isOk(): bool |
||
32 | } |
||
33 | |||
34 | public function getErrors(): array |
||
35 | { |
||
36 | $errors = []; |
||
37 | foreach ($this->validationResults as $result) { |
||
38 | foreach ($result->getErrors() as $error) { |
||
39 | $field = $result->getField(); |
||
40 | if ($field !== null) { |
||
41 | $errors[$field][] = $error; |
||
42 | } else { |
||
43 | $errors[] = $error; |
||
44 | } |
||
45 | } |
||
46 | } |
||
47 | |||
48 | return $errors; |
||
49 | } |
||
50 | |||
51 | /** @return Result[] */ |
||
52 | public function validationResults(): array |
||
53 | { |
||
54 | return $this->validationResults; |
||
55 | } |
||
56 | |||
57 | public function isEmpty(): bool |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @throws ValidationExceptionInterface |
||
64 | */ |
||
65 | public function guard(?ValidationExceptionInterface $validationException = null): void |
||
70 |