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