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