Passed
Pull Request — master (#44)
by
unknown
02:52
created

MatoGrosso   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 44
ccs 13
cts 14
cp 0.9286
rs 10
c 0
b 0
f 0

3 Methods

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