Passed
Branch main (274970)
by Antonio Oertel
03:05
created

DistritoFederal   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 16
dl 0
loc 35
ccs 11
cts 11
cp 1
rs 10
c 1
b 1
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A calculateDigit() 0 11 1
1
<?php
2
3
namespace Brazanation\Documents\StateRegistration;
4
5
use Brazanation\Documents\DigitCalculator;
6
7
class DistritoFederal extends State
8
{
9
    const LONG_NAME = 'DistritoFederal';
10
11
    const REGEX = '/^(\d{2})(\d{6})(\d{3})(\d{2})$/';
12
13
    const FORMAT = '$1.$2.$3-$4';
14
15
    const LENGTH = 13;
16
17
    const NUMBER_OF_DIGITS = 2;
18
19
    const SHORT_NAME = 'DF';
20
21 18
    public function __construct()
22
    {
23 18
        parent::__construct(self::LONG_NAME, self::LENGTH, self::NUMBER_OF_DIGITS, self::REGEX, self::FORMAT);
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     *
29
     * @see http://www.sintegra.gov.br/Cad_Estados/cad_DF.html
30
     */
31 16
    public function calculateDigit(string $baseNumber) : string
32
    {
33 16
        $calculator = new DigitCalculator($baseNumber);
34 16
        $calculator->useComplementaryInsteadOfModule();
35 16
        $calculator->replaceWhen('0', 10, 11);
36 16
        $calculator->withModule(DigitCalculator::MODULE_11);
37 16
        $firstDigit = $calculator->calculate();
38 16
        $calculator->addDigit($firstDigit);
39 16
        $secondDigit = $calculator->calculate();
40
41 16
        return "{$firstDigit}{$secondDigit}";
42
    }
43
}
44