Passed
Push — main ( bd8ab6...d7b565 )
by Breno
01:49
created

Cpf::evaluate()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 11
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 19
rs 9.9

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Cpf::maskPattern() 0 3 1
A Cpf::unmaskedLength() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace BrenoRoosevelt\Validation\Rules\Brazilian;
5
6
use Attribute;
7
8
#[Attribute(Attribute::TARGET_PROPERTY)]
9
class Cpf extends Document
10
{
11
    public function __construct(bool $mask = true, ?string $message = 'CPF inválido')
12
    {
13
        parent::__construct($mask, $message);
14
    }
15
16
    protected function isValidDocument(string $input): bool
17
    {
18
        if (!$this->validateNumbersWithCorrectLength($input)) {
19
            return false;
20
        }
21
22
        return $this->validateCpfCnpjDigits($input);
23
    }
24
25
    protected function maskPattern(): string
26
    {
27
        return '/^[0-9]{3}\.[0-9]{3}\.[0-9]{3}\-[0-9]{2}$/';
28
    }
29
30
    protected function unmaskedLength(): int
31
    {
32
        return 11;
33
    }
34
}
35