| Total Complexity | 8 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 5 | ||
| Bugs | 1 | Features | 1 |
| 1 | <?php |
||
| 9 | final class Result |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @psalm-var array<int|string, string> |
||
| 13 | */ |
||
| 14 | private array $errors = []; |
||
| 15 | |||
| 16 | 159 | public function isValid(): bool |
|
| 19 | } |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Add an error. |
||
| 23 | * |
||
| 24 | * @param string $message Error message. |
||
| 25 | * @param int|string|null $key For simple rules the key is null meaning error will be appended to the end of the |
||
| 26 | * array. Otherwise, it's a path to a current error value in the input data concatenated using dot notation. For |
||
| 27 | * example: "charts.0.points.0.coordinates.x". |
||
| 28 | */ |
||
| 29 | 129 | public function addError(string $message, $key = null): void |
|
| 30 | { |
||
| 31 | 129 | if ($key !== null && $key !== 0 && !isset($this->errors[$key])) { |
|
| 32 | 6 | $this->errors[$key] = $message; |
|
| 33 | } else { |
||
| 34 | 129 | $this->errors[] = $message; |
|
| 35 | } |
||
| 36 | 129 | } |
|
| 37 | |||
| 38 | /** |
||
| 39 | * @psalm-return array<int|string, string> |
||
| 40 | */ |
||
| 41 | 37 | public function getErrors(): array |
|
| 44 | } |
||
| 45 | |||
| 46 | 1 | public function getNestedErrors(): array |
|
| 54 | } |
||
| 55 | } |
||
| 56 |