| Total Complexity | 8 |
| Total Lines | 70 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 5 | ||
| Bugs | 1 | Features | 1 |
| 1 | <?php |
||
| 9 | final class Result |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var Error[] |
||
| 13 | */ |
||
| 14 | 157 | private array $errors = []; |
|
| 15 | |||
| 16 | 157 | public function isValid(): bool |
|
| 19 | 127 | } |
|
| 20 | |||
| 21 | 127 | /** |
|
| 22 | 127 | * @psalm-param list<int|string>|null $valuePath |
|
| 23 | */ |
||
| 24 | public function addError(string $message, array $valuePath = []): void |
||
| 25 | { |
||
| 26 | $this->errors[] = new Error($message, $valuePath); |
||
| 27 | 35 | } |
|
| 28 | |||
| 29 | 35 | /** |
|
| 30 | * @return Error[] |
||
| 31 | */ |
||
| 32 | public function getErrorObjects(): array |
||
| 33 | { |
||
| 34 | return $this->errors; |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @return string[] |
||
| 39 | */ |
||
| 40 | public function getErrors(): array |
||
| 45 | }); |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @return array |
||
| 50 | */ |
||
| 51 | public function getNestedErrors(): array |
||
| 52 | { |
||
| 53 | $valuePathCountMap = []; |
||
| 54 | $errors = []; |
||
| 55 | foreach ($this->errors as $error) { |
||
| 56 | $stringValuePath = $error->getStringValuePath(); |
||
| 57 | $valuePathCount = $valuePathCountMap[$stringValuePath] ?? 0; |
||
| 58 | $errorValuePath = "$stringValuePath.$valuePathCount"; |
||
| 59 | |||
| 60 | ArrayHelper::setValueByPath($errors, $errorValuePath, $error->getMessage()); |
||
| 61 | $valuePathCount++; |
||
| 62 | $valuePathCountMap[$stringValuePath] = $valuePathCount; |
||
| 63 | } |
||
| 64 | |||
| 65 | return $errors; |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @return array |
||
| 70 | */ |
||
| 71 | public function getFlatDetailedErrors(): array |
||
| 79 | } |
||
| 80 | } |
||
| 81 |