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