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