Conditions | 5 |
Paths | 5 |
Total Lines | 27 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 13 |
CRAP Score | 5 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
17 | 16 | public function validate(mixed $value, object $rule, ValidationContext $context): Result |
|
18 | { |
||
19 | 16 | if (!$rule instanceof IsTrue) { |
|
20 | 1 | throw new UnexpectedRuleException(IsTrue::class, $rule); |
|
21 | } |
||
22 | |||
23 | 15 | if ($rule->isStrict()) { |
|
24 | 7 | $valid = $value === $rule->getTrueValue(); |
|
25 | } else { |
||
26 | 8 | $valid = $value == $rule->getTrueValue(); |
|
27 | } |
||
28 | |||
29 | 15 | $result = new Result(); |
|
30 | |||
31 | 15 | if ($valid) { |
|
32 | 4 | return $result; |
|
33 | } |
||
34 | |||
35 | 11 | $result->addError( |
|
36 | 11 | message: $rule->getMessage(), |
|
37 | parameters: [ |
||
38 | 11 | 'true' => $rule->getTrueValue() === true ? 'true' : $rule->getTrueValue(), |
|
39 | 'value' => $value, |
||
40 | ] |
||
41 | ); |
||
42 | |||
43 | 11 | return $result; |
|
44 | } |
||
46 |