| Conditions | 3 |
| Paths | 3 |
| Total Lines | 19 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 3 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 19 | 10 | public function validate(mixed $value, object $rule, ValidationContext $context): Result |
|
| 20 | { |
||
| 21 | 10 | if (!$rule instanceof Json) { |
|
| 22 | 1 | throw new UnexpectedRuleException(Json::class, $rule); |
|
| 23 | } |
||
| 24 | |||
| 25 | 9 | $result = new Result(); |
|
| 26 | |||
| 27 | 9 | if (!$this->isValidJson($value)) { |
|
| 28 | 6 | $result->addError( |
|
| 29 | 6 | $rule->getMessage(), |
|
| 30 | [ |
||
| 31 | 6 | 'attribute' => $context->getAttribute(), |
|
| 32 | 'value' => $value, |
||
| 33 | ], |
||
| 34 | ); |
||
| 35 | } |
||
| 36 | |||
| 37 | 9 | return $result; |
|
| 38 | } |
||
| 62 |