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