Conditions | 4 |
Paths | 4 |
Total Lines | 17 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 7 |
CRAP Score | 4 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
24 | public function validate(mixed $value, object $rule, ValidationContext $context): Result |
||
25 | 16 | { |
|
26 | 16 | if (!$rule instanceof Callback) { |
|
27 | 1 | throw new UnexpectedRuleException(Callback::class, $rule); |
|
28 | } |
||
29 | |||
30 | 15 | $callback = $rule->getCallback(); |
|
31 | 15 | if ($callback === null) { |
|
32 | 1 | throw new InvalidArgumentException('Using method outside of attribute scope is prohibited.'); |
|
33 | } |
||
34 | |||
35 | 14 | $result = $callback($value, $rule, $context); |
|
36 | if (!$result instanceof Result) { |
||
37 | throw new InvalidCallbackReturnTypeException($result); |
||
38 | } |
||
39 | |||
40 | return $result; |
||
41 | } |
||
43 |