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

MatoGrosso   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

3 Methods

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