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
|
18 |
|
public function __construct() |
20
|
|
|
{ |
21
|
18 |
|
$this->calculation = new Eleven(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
18 |
|
public function getState() : string |
28
|
|
|
{ |
29
|
18 |
|
return $this->calculation->getState(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
18 |
|
public function getLength() : int |
36
|
|
|
{ |
37
|
18 |
|
return $this->calculation->getLength(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
2 |
|
public function getRegex() : string |
44
|
|
|
{ |
45
|
2 |
|
return $this->calculation->getRegex(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
2 |
|
public function getFormat() : string |
52
|
|
|
{ |
53
|
2 |
|
return $this->calculation->getFormat(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
18 |
|
public function getNumberOfDigits() : int |
60
|
|
|
{ |
61
|
18 |
|
return $this->calculation->getNumberOfDigits(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
18 |
|
public function normalizeNumber(string $number) : string |
68
|
|
|
{ |
69
|
18 |
|
$this->defineStrategy($number); |
70
|
|
|
|
71
|
18 |
|
return $this->calculation->normalizeNumber($number); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
18 |
|
public function extractBaseNumber(string $number) : string |
78
|
|
|
{ |
79
|
18 |
|
return $this->calculation->extractBaseNumber($number); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritdoc} |
84
|
|
|
*/ |
85
|
18 |
|
public function extractCheckerDigit(string $number) : string |
86
|
|
|
{ |
87
|
18 |
|
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
|
16 |
|
public function calculateDigit(string $baseNumber) : string |
96
|
|
|
{ |
97
|
16 |
|
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
|
18 |
|
private function defineStrategy(string $number) |
106
|
|
|
{ |
107
|
18 |
|
$number = preg_replace('/\D/', '', $number); |
108
|
18 |
|
if (strlen($number) == 9) { |
109
|
10 |
|
$this->calculation = new Nine(); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|