Total Complexity | 11 |
Total Lines | 48 |
Duplicated Lines | 0 % |
Coverage | 95.24% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
5 | final class ValidationResult |
||
6 | { |
||
7 | private array $errors = []; |
||
8 | |||
9 | 4 | public function __construct(array $errors = []) |
|
12 | } |
||
13 | |||
14 | 4 | private function addErrors(array $errors, string $path = ''): void |
|
15 | { |
||
16 | 4 | foreach ($errors as $field => $error) { |
|
17 | 2 | $oldPath = $path; |
|
18 | 2 | $path .= ($path === '' ? '' : '.') . $field; |
|
19 | 2 | $this->addSubErrors($error, $path); |
|
20 | 2 | $path = $oldPath; |
|
21 | } |
||
22 | } |
||
23 | |||
24 | 2 | private function addSubErrors(array $error, string $path = ''): void |
|
31 | } |
||
32 | } |
||
33 | } |
||
34 | |||
35 | 2 | public function addError(string $field, string $message): void |
|
36 | { |
||
37 | 2 | $this->errors[$field] = $message; |
|
38 | } |
||
39 | |||
40 | 2 | public function getErrors(): array |
|
43 | } |
||
44 | |||
45 | 4 | public function success(): bool |
|
48 | } |
||
49 | |||
50 | 4 | public function fails(): bool |
|
55 |