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

Tocantins::defineStrategy()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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