Passed
Push — master ( 5ee16c...ec5b4c )
by Antonio Oertel
32s
created

Tocantins   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getState() 0 4 1
A getLength() 0 4 1
A getRegex() 0 4 1
A getFormat() 0 4 1
A getNumberOfDigits() 0 4 1
A normalizeNumber() 0 6 1
A extractBaseNumber() 0 4 1
A extractCheckerDigit() 0 4 1
A calculateDigit() 0 4 1
A defineStrategy() 0 7 2
1
<?php
2
3
namespace Brazanation\Documents\StateRegistration;
4
5
use Brazanation\Documents\StateRegistration\Tocantins\Eleven;
6
use Brazanation\Documents\StateRegistration\Tocantins\Nine;
7
8
class Tocantins implements StateInterface
9
{
10
    const LONG_NAME = 'Tocantins';
11
12
    const SHORT_NAME = 'TO';
13
14
    /**
15
     * @var State
16
     */
17
    private $calculation;
18
19 10
    public function __construct()
20
    {
21 10
        $this->calculation = new Eleven();
22 10
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 10
    public function getState()
28
    {
29 10
        return $this->calculation->getState();
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 10
    public function getLength()
36
    {
37 10
        return $this->calculation->getLength();
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 1
    public function getRegex()
44
    {
45 1
        return $this->calculation->getRegex();
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 1
    public function getFormat()
52
    {
53 1
        return $this->calculation->getFormat();
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 10
    public function getNumberOfDigits()
60
    {
61 10
        return $this->calculation->getNumberOfDigits();
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67 10
    public function normalizeNumber($number)
68
    {
69 10
        $this->defineStrategy($number);
70
71 10
        return $this->calculation->normalizeNumber($number);
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77 9
    public function extractBaseNumber($number)
78
    {
79 9
        return $this->calculation->extractBaseNumber($number);
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85 10
    public function extractCheckerDigit($number)
86
    {
87 10
        return $this->calculation->extractCheckerDigit($number);
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     *
93
     * @see http://www.sintegra.gov.br/Cad_Estados/cad_TO.html
94
     */
95 8
    public function calculateDigit($baseNumber)
96
    {
97 8
        return $this->calculation->calculateDigit($baseNumber);
98
    }
99
100
    /**
101
     * It will load calculation strategy based on number format.
102
     *
103
     * @param string $number Number of document.
104
     */
105 10
    private function defineStrategy($number)
106
    {
107 10
        $number = preg_replace('/\D/', '', $number);
108 10
        if (strlen($number) == 9) {
109 5
            $this->calculation = new Nine();
110
        }
111 10
    }
112
}
113