Total Complexity | 5 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
16 | final class JsonHandler implements RuleHandlerInterface |
||
17 | { |
||
18 | 10 | public function validate(mixed $value, object $rule, ?ValidationContext $context = null): Result |
|
19 | { |
||
20 | 10 | if (!$rule instanceof Json) { |
|
21 | 1 | throw new UnexpectedRuleException(Json::class, $rule); |
|
22 | } |
||
23 | |||
24 | 9 | $result = new Result(); |
|
25 | |||
26 | 9 | if (!$this->isValidJson($value)) { |
|
27 | 6 | $result->addError($rule->message); |
|
28 | } |
||
29 | |||
30 | 9 | return $result; |
|
31 | } |
||
32 | |||
33 | 9 | private function isValidJson($value): bool |
|
53 | } |
||
54 | } |
||
55 |