| Conditions | 5 |
| Paths | 7 |
| Total Lines | 25 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| CRAP Score | 5 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 28 | 6 | public function validate(mixed $value, object $rule, ?ValidationContext $context = null): Result |
|
| 29 | { |
||
| 30 | 6 | if (!$rule instanceof AtLeast) { |
|
| 31 | 1 | throw new UnexpectedRuleException(AtLeast::class, $rule); |
|
| 32 | } |
||
| 33 | |||
| 34 | 5 | $filledCount = 0; |
|
| 35 | |||
| 36 | 5 | foreach ($rule->getAttributes() as $attribute) { |
|
| 37 | 5 | if (!$this->isEmpty($value->{$attribute})) { |
|
| 38 | 4 | $filledCount++; |
|
| 39 | } |
||
| 40 | } |
||
| 41 | |||
| 42 | 5 | $result = new Result(); |
|
| 43 | |||
| 44 | 5 | if ($filledCount < $rule->getMin()) { |
|
| 45 | 3 | $formattedMessage = $this->formatter->format( |
|
| 46 | 3 | $rule->getMessage(), |
|
| 47 | 3 | ['min' => $rule->getMin(), 'attribute' => $context?->getAttribute(), 'value' => $value] |
|
| 48 | ); |
||
| 49 | 3 | $result->addError($formattedMessage); |
|
| 50 | } |
||
| 51 | |||
| 52 | 5 | return $result; |
|
| 53 | } |
||
| 55 |