1 | <?php |
||
7 | final class Cpf implements DocumentInterface |
||
8 | { |
||
9 | const LENGTH = 11; |
||
10 | |||
11 | const LABEL = 'CPF'; |
||
12 | |||
13 | const REGEX = '/^([\d]{3})([\d]{3})([\d]{3})([\d]{2})$/'; |
||
14 | |||
15 | const FORMAT_REGEX = '/^[\d]{3}\.[\d]{3}\.[\d]{3}-[\d]{2}$/'; |
||
16 | |||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | private $cpf; |
||
21 | |||
22 | /** |
||
23 | * Cpf constructor. |
||
24 | * |
||
25 | * @param string $number Only accept numbers |
||
26 | */ |
||
27 | 11 | public function __construct($number) |
|
33 | |||
34 | /** |
||
35 | * Check if CPF is not empty and is a valid number. |
||
36 | * |
||
37 | * @param string $number |
||
38 | * |
||
39 | * @throws InvalidArgumentException when CPF is empty |
||
40 | * @throws InvalidArgumentException when CPF is not valid number |
||
41 | */ |
||
42 | 11 | private function validate($number) |
|
51 | |||
52 | /** |
||
53 | * Validates cpf is a valid number. |
||
54 | * |
||
55 | * @param string $number A number to be validate. |
||
56 | * |
||
57 | * @return bool Returns true if it is a valid number, otherwise false. |
||
58 | */ |
||
59 | 8 | private function isValidCV($number) |
|
71 | |||
72 | /** |
||
73 | * Formats CPF number |
||
74 | * |
||
75 | * @return string Returns formatted number, such as: 00.000.000/0000-00 |
||
76 | */ |
||
77 | 2 | public function format() |
|
81 | |||
82 | /** |
||
83 | * Returns the CPF number |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | 2 | public function __toString() |
|
91 | } |
||
92 |