| Total Complexity | 6 |
| Total Lines | 51 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | class CreditCardRule extends AbstractRule |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var string error template |
||
| 24 | */ |
||
| 25 | protected $description = 'must be a valid Credit Card number'; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Check input data |
||
| 29 | * |
||
| 30 | * @param string $input |
||
| 31 | * |
||
| 32 | * @return bool |
||
| 33 | */ |
||
| 34 | 11 | public function validate($input): bool |
|
| 35 | { |
||
| 36 | 11 | $input = preg_replace('([ \.-])', '', (string) $input); |
|
| 37 | |||
| 38 | 11 | if (!is_numeric($input)) { |
|
| 39 | 4 | return false; |
|
| 40 | } |
||
| 41 | |||
| 42 | 7 | return $this->verifyMod10($input); |
|
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Verify by Mod10 |
||
| 47 | * |
||
| 48 | * @param string $input |
||
| 49 | * |
||
| 50 | * @return bool |
||
| 51 | */ |
||
| 52 | 7 | private function verifyMod10(string $input): bool |
|
| 71 | } |
||
| 72 | } |
||
| 73 |