| Conditions | 8 |
| Paths | 11 |
| Total Lines | 32 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 20 |
| CRAP Score | 8.0069 |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | 3 | public function validate($value, Constraint $constraint) |
|
| 19 | { |
||
| 20 | 3 | if (!$value instanceof \DateTime || !$constraint instanceof Age) { |
|
| 21 | return; |
||
| 22 | } |
||
| 23 | |||
| 24 | 3 | $now = new \DateTime(); |
|
| 25 | 3 | $minAgeDate = new \DateTime("-{$constraint->min} years"); |
|
| 26 | 3 | $maxAgeDate = new \DateTime("-{$constraint->max} years"); |
|
| 27 | |||
| 28 | 3 | $error = false; |
|
| 29 | 3 | $limit = 0; |
|
| 30 | |||
| 31 | 3 | if ($value > $now) { |
|
| 32 | 1 | $error = $constraint->futureError; |
|
| 33 | } else { |
||
| 34 | 2 | if ($constraint->min > 0 && $value > $minAgeDate) { |
|
| 35 | 1 | $error = $constraint->minError; |
|
| 36 | 1 | $limit = $constraint->min; |
|
| 37 | } |
||
| 38 | |||
| 39 | 2 | if ($value < $maxAgeDate) { |
|
| 40 | 1 | $error = $constraint->maxError; |
|
| 41 | 1 | $limit = $constraint->max; |
|
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | 3 | if ($error) { |
|
|
|
|||
| 46 | 3 | $this->context |
|
| 47 | 3 | ->buildViolation($error) |
|
| 48 | 3 | ->setParameter('{{ limit }}', $limit) |
|
| 49 | 3 | ->addViolation(); |
|
| 50 | } |
||
| 53 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: