1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Brazanation\Documents\StateRegistration; |
4
|
|
|
|
5
|
|
|
use Brazanation\Documents\DigitCalculator; |
6
|
|
|
|
7
|
|
|
class RioGrandeDoNorte extends State |
8
|
|
|
{ |
9
|
|
|
const LABEL = 'RioGrandeDoNorte'; |
10
|
|
|
|
11
|
|
|
const REGEX = '/^(20)(\d)?(\d{3})(\d{3})(\d{1})$/'; |
12
|
|
|
|
13
|
|
|
const REGEX_FOR_NINE_NUMBERS = '/^(20)(\d{3})(\d{3})(\d{1})$/'; |
14
|
|
|
|
15
|
|
|
const FORMAT = '$1.$2.$3.$4-$5'; |
16
|
|
|
|
17
|
|
|
const FORMAT_FOR_NINE_NUMBERS = '$1.$2.$3-$4'; |
18
|
|
|
|
19
|
|
|
const LENGTH = 10; |
20
|
|
|
|
21
|
|
|
const DIGITS_COUNT = 1; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var int |
25
|
|
|
*/ |
26
|
|
|
private $length; |
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
private $format; |
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
private $regex; |
|
|
|
|
37
|
|
|
|
38
|
13 |
|
public function __construct() |
39
|
|
|
{ |
40
|
13 |
|
$this->length = self::LENGTH; |
41
|
13 |
|
$this->format = self::FORMAT; |
42
|
13 |
|
$this->regex = self::REGEX; |
43
|
13 |
|
parent::__construct(self::LABEL, self::LENGTH, self::DIGITS_COUNT, self::REGEX, self::FORMAT); |
44
|
13 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
13 |
|
public function normalizeNumber($number) |
50
|
|
|
{ |
51
|
13 |
|
$number = parent::normalizeNumber($number); |
52
|
|
|
|
53
|
13 |
|
$this->applyForNineDigits($number); |
54
|
|
|
|
55
|
13 |
|
return $number; |
56
|
|
|
} |
57
|
|
|
|
58
|
2 |
|
public function getFormat() |
59
|
|
|
{ |
60
|
2 |
|
return $this->format; |
61
|
|
|
} |
62
|
|
|
|
63
|
13 |
|
public function getLength() |
64
|
|
|
{ |
65
|
13 |
|
return $this->length; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
2 |
|
public function getRegex() |
72
|
|
|
{ |
73
|
2 |
|
return $this->regex; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritdoc} |
78
|
|
|
* |
79
|
|
|
* @see http://www.sintegra.gov.br/Cad_Estados/cad_RN.html |
80
|
|
|
*/ |
81
|
10 |
|
public function calculateDigit($baseNumber) |
82
|
|
|
{ |
83
|
10 |
|
$calculator = new DigitCalculator($baseNumber); |
84
|
10 |
|
$calculator->useComplementaryInsteadOfModule(); |
85
|
10 |
|
$calculator->withMultipliersInterval(2, 10); |
86
|
10 |
|
$calculator->replaceWhen('0', 10, 11); |
87
|
10 |
|
$calculator->withModule(DigitCalculator::MODULE_11); |
88
|
|
|
|
89
|
10 |
|
$digit = $calculator->calculate(); |
90
|
|
|
|
91
|
10 |
|
return "{$digit}"; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param string $number |
96
|
|
|
*/ |
97
|
13 |
|
private function applyForNineDigits($number) |
98
|
|
|
{ |
99
|
13 |
|
if (strlen($number) != self::LENGTH) { |
100
|
5 |
|
$this->format = self::FORMAT_FOR_NINE_NUMBERS; |
101
|
5 |
|
$this->regex = self::REGEX_FOR_NINE_NUMBERS; |
102
|
5 |
|
$this->length = 9; |
103
|
|
|
} |
104
|
13 |
|
} |
105
|
|
|
} |
106
|
|
|
|