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