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

EFisco   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

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