| Conditions | 5 |
| Paths | 4 |
| Total Lines | 22 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | 21 | public function validate($value, Constraint $constraint) |
|
| 11 | { |
||
| 12 | 21 | if (empty($value)) { |
|
| 13 | 2 | return true; |
|
| 14 | } |
||
| 15 | |||
| 16 | 19 | if (!preg_match('/^[0-9]{11}$/', $value) || $value === '00000000000') { |
|
| 17 | 3 | $this->buildViolation($value, $constraint); |
|
| 18 | |||
| 19 | 3 | return false; |
|
| 20 | } |
||
| 21 | |||
| 22 | 16 | $checksum = $this->calculateChecksum($value); |
|
| 23 | |||
| 24 | 16 | if ($checksum % 10 !== 0) { |
|
| 25 | 2 | $this->buildViolation($value, $constraint); |
|
| 26 | |||
| 27 | 2 | return false; |
|
| 28 | } |
||
| 29 | |||
| 30 | 14 | return true; |
|
| 31 | } |
||
| 32 | |||
| 62 | } |