Passed
Push — main ( 48c7ef...34571b )
by Breno
01:46
created

Cnpj::unmaskedLength()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace BrenoRoosevelt\Validation\Rules\Brazilian;
5
6
use Attribute;
7
use BrenoRoosevelt\Validation\Rules\Document;
8
9
#[Attribute(Attribute::TARGET_PROPERTY)]
10
class Cnpj extends Document
11
{
12
    public function __construct(bool $mask = true, ?string $message = 'CNPJ inválido')
13
    {
14
        parent::__construct($mask, $message);
15
    }
16
17
    public function isValidDocument(string $input): bool
18
    {
19
        if (!$this->validateNumbersWithCorrectLength($input)) {
20
            return false;
21
        }
22
23
        return DigitoVerificador::checkCpfCnpjDigits($input);
24
    }
25
26
    public function maskPattern(): string
27
    {
28
        return '/^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/';
29
    }
30
31
    public function unmaskedLength(): int
32
    {
33
        return 14;
34
    }
35
36
    public function adjustZeroPadding(string $input): string
37
    {
38
        return str_pad($input, $this->unmaskedLength(), '0', STR_PAD_LEFT);
39
    }
40
}
41