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

Old::calculateDigit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
ccs 9
cts 9
cp 1
rs 9.4285
cc 1
eloc 9
nc 1
nop 1
crap 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