Conditions | 5 |
Paths | 7 |
Total Lines | 24 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 13 |
CRAP Score | 5 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
20 | 6 | public function validate(mixed $value, object $rule, ValidationContext $context): Result |
|
21 | { |
||
22 | 6 | if (!$rule instanceof AtLeast) { |
|
23 | 1 | throw new UnexpectedRuleException(AtLeast::class, $rule); |
|
24 | } |
||
25 | |||
26 | 5 | $filledCount = 0; |
|
27 | |||
28 | 5 | foreach ($rule->getAttributes() as $attribute) { |
|
29 | 5 | if (!$this->isEmpty($value->{$attribute})) { |
|
30 | 4 | $filledCount++; |
|
31 | } |
||
32 | } |
||
33 | |||
34 | 5 | $result = new Result(); |
|
35 | |||
36 | 5 | if ($filledCount < $rule->getMin()) { |
|
37 | 3 | $result->addError( |
|
38 | 3 | message: $rule->getMessage(), |
|
39 | 3 | parameters: ['min' => $rule->getMin(), 'value' => $value] |
|
40 | ); |
||
41 | } |
||
42 | |||
43 | 5 | return $result; |
|
44 | } |
||
46 |