Conditions | 5 |
Paths | 6 |
Total Lines | 20 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 30 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | public function validate($value, Constraint $constraint) |
||
13 | { |
||
14 | if (!$constraint instanceof InducementsAmount) { |
||
15 | throw new UnexpectedTypeException($constraint, InducementsAmount::class); |
||
16 | } |
||
17 | if (!is_array($value)) { |
||
18 | throw new UnexpectedTypeException($value, 'array'); |
||
19 | } |
||
20 | |||
21 | $spend = 0; |
||
22 | |||
23 | foreach ($value as $inducement) { |
||
24 | /** @var Inducement $inducement */ |
||
25 | $spend += $inducement->getValue(); |
||
26 | } |
||
27 | |||
28 | if ($spend > $constraint->budget) { |
||
29 | $this->context->buildViolation($constraint->limitMessage) |
||
30 | ->setParameter('{{ budget }}', $constraint->budgetToDisplay) |
||
31 | ->addViolation(); |
||
32 | } |
||
35 |