Conditions | 6 |
Paths | 6 |
Total Lines | 21 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
21 | public function isValid(mixed $input, array $context = []): bool |
||
22 | { |
||
23 | if (!is_string($input) || !is_numeric($input)) { |
||
24 | return false; |
||
25 | } |
||
26 | |||
27 | $cpf = (string) $input; |
||
28 | if ($this->mask) { |
||
29 | if (preg_match(Cpf::MASK, $cpf) !== 1) { |
||
30 | return false; |
||
31 | } |
||
32 | |||
33 | $cpf = preg_replace('/\D/', '', $cpf); |
||
34 | } |
||
35 | |||
36 | $cpf = str_pad($cpf, Cpf::LENGTH, '0', STR_PAD_LEFT); |
||
37 | if (strlen($cpf) !== Cpf::LENGTH) { |
||
38 | return false; |
||
39 | } |
||
40 | |||
41 | return DigitoVerificador::checkCpfCnpjDigits($cpf); |
||
42 | } |
||
44 |