Completed
Pull Request — master (#19)
by Antonio Oertel
03:14
created

Old   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 35
ccs 12
cts 12
cp 1
rs 10

2 Methods

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