1 | <?php |
||
17 | final class Cnp extends Embeddable |
||
18 | { |
||
19 | /** @var Gender */ |
||
20 | private $gender; |
||
21 | |||
22 | /** @var Date */ |
||
23 | private $birthday; |
||
24 | |||
25 | /** @var County */ |
||
26 | private $county; |
||
27 | |||
28 | /** @var Serial */ |
||
29 | private $serial; |
||
30 | |||
31 | /** @var Checksum */ |
||
32 | private $checksum; |
||
33 | |||
34 | /** |
||
35 | * Build a {@link CNP} instance from a CNP number. |
||
36 | * |
||
37 | * @static |
||
38 | * @access public |
||
39 | * @param string $number A CNP number. |
||
40 | * @return self |
||
41 | * |
||
42 | * @throws InvalidCnpException |
||
43 | */ |
||
44 | 20 | public static function fromString($number) |
|
70 | |||
71 | /** |
||
72 | * @param Gender $gender |
||
73 | * @param Date $birthday |
||
74 | * @param County $county |
||
75 | * @param Serial $serial |
||
76 | * @param Checksum $checksum |
||
77 | * |
||
78 | * @throws InvalidCnpException |
||
79 | */ |
||
80 | 38 | public function __construct(Gender $gender, Date $birthday, County $county, Serial $serial, Checksum $checksum) |
|
95 | |||
96 | /** |
||
97 | * @access public |
||
98 | * @return Gender |
||
99 | */ |
||
100 | 38 | public function getGender() |
|
104 | |||
105 | /** |
||
106 | * @access public |
||
107 | * @return Date |
||
108 | */ |
||
109 | 38 | public function getBirthday() |
|
113 | |||
114 | /** |
||
115 | * @access public |
||
116 | * @return County |
||
117 | */ |
||
118 | 34 | public function getCounty() |
|
122 | |||
123 | /** |
||
124 | * @access public |
||
125 | * @return Serial |
||
126 | */ |
||
127 | 34 | public function getSerial() |
|
131 | |||
132 | /** |
||
133 | * @access public |
||
134 | * @return Checksum |
||
135 | */ |
||
136 | 34 | public function getChecksum() |
|
140 | |||
141 | /** |
||
142 | * @access public |
||
143 | * @return bool |
||
144 | */ |
||
145 | 4 | public function isResident() |
|
149 | |||
150 | /** |
||
151 | * {@inheritDoc} |
||
152 | */ |
||
153 | 16 | public function equals(Embeddable $object) |
|
157 | |||
158 | /** |
||
159 | * {@inheritDoc} |
||
160 | */ |
||
161 | 34 | public function __toString() |
|
169 | |||
170 | /** |
||
171 | * Rebuild a date object with the year changed. |
||
172 | * |
||
173 | * Year prefix is changed according to gender. |
||
174 | * |
||
175 | * @access private |
||
176 | * @param Date $birthday |
||
177 | * @return $this |
||
178 | */ |
||
179 | 38 | private function setBirthday(Date $birthday) |
|
195 | |||
196 | /** |
||
197 | * @access private |
||
198 | * @param County $county |
||
199 | * @return $this |
||
200 | * |
||
201 | * @throws \DomainException |
||
202 | */ |
||
203 | 38 | private function setCounty(County $county) |
|
219 | |||
220 | /** |
||
221 | * Extract element from string at given position. |
||
222 | * |
||
223 | * @access private |
||
224 | * @param string $from |
||
225 | * @param int $position |
||
226 | * @return string |
||
227 | */ |
||
228 | 48 | private static function getValue($from, $position) |
|
234 | |||
235 | /** |
||
236 | * @access private |
||
237 | * @param Gender $gender |
||
238 | * @return int |
||
239 | */ |
||
240 | 38 | private function getYearPrefix(Gender $gender) |
|
263 | |||
264 | /** |
||
265 | * Calculate checksum and compare with the one provided in order to validate |
||
266 | * |
||
267 | * @access private |
||
268 | * @param string $cnp |
||
269 | * @return void |
||
270 | * |
||
271 | * @throws \Vimishor\Cnp\Exception\InvalidCnpException |
||
272 | */ |
||
273 | 34 | private function validate($cnp) |
|
280 | |||
281 | /** |
||
282 | * @access private |
||
283 | * @param string $cnp |
||
284 | * @return int |
||
285 | */ |
||
286 | 34 | private function calculateChecksum($cnp) |
|
299 | } |
||
300 |