Skip to content

Commit ccc6db7

Browse files
Add new way to create a Document objects (#42)
Trying to keep simple to use and avoid throw exception on construct object with invalid document numbers. Create an object from given string is similar behaviour from DateTime::createFromFormat, when give a valid number it returns an document object or FALSE when failure.
1 parent 445418b commit ccc6db7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+592
-214
lines changed

.styleci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ enabled:
77
- no_unused_imports
88
- no_whitespace_in_blank_lines
99
- ordered_imports
10-
- phpdoc_align
1110
- phpdoc_separation
1211
- return
1312
- short_array_syntax

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
Change Log
22
==========
33

4+
## [v0.8.0](https://github.com/brazanation/documents/tree/v0.8.0) (2018-02-17)
5+
[Full Changelog](https://github.com/brazanation/documents/compare/v0.7.1...v0.8.0)
6+
7+
**Implemented enhancements:**
8+
9+
- Add Judiciary Process document [#38](https://github.com/brazanation/documents/pull/38) ([robmachado](https://github.com/robmachado))
10+
- Detail how Judiciary Process number is composed [#41](https://github.com/brazanation/documents/pull/41) ([tonicospinelli](https://github.com/tonicospinelli))
11+
12+
**Fixed bugs:**
13+
14+
- Fix StyleCI configuration [#40](https://github.com/brazanation/documents/pull/40) ([tonicospinelli](https://github.com/tonicospinelli))
15+
16+
**Closed issues:**
17+
18+
**Merged pull requests:**
19+
20+
- Add Judiciary Process document [#38](https://github.com/brazanation/documents/pull/38) ([robmachado](https://github.com/robmachado))
21+
- Fix StyleCI configuration [#40](https://github.com/brazanation/documents/pull/40) ([tonicospinelli](https://github.com/tonicospinelli))
22+
- Detail how Judiciary Process number is composed [#41](https://github.com/brazanation/documents/pull/41) ([tonicospinelli](https://github.com/tonicospinelli))
23+
424
## [v0.7.1](https://github.com/brazanation/documents/tree/v0.7.1) (2018-02-17)
525
[Full Changelog](https://github.com/brazanation/documents/compare/v0.7.0...v0.7.1)
626

README.md

Lines changed: 86 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Install the library using [composer][1]. Add the following to your `composer.jso
1717
```json
1818
{
1919
"require": {
20-
"brazanation/documents": "0.7.*"
20+
"brazanation/documents": "0.8.*"
2121
}
2222
}
2323
```
@@ -31,22 +31,34 @@ $ composer.phar install
3131
or
3232

3333
```sh
34-
$ composer require brazanation/documents 0.7.*
34+
$ composer require brazanation/documents 0.8.*
3535
```
3636

3737
### CPF (cadastro de pessoas físicas)
3838

3939
Registration of individuals or Tax Identification
4040

41+
```php
42+
use Brazanation\Documents\Cpf;
43+
44+
$document = Cpf::createFromString('06843273173');
45+
if (false === $cpf) {
46+
echo "Not Valid";
47+
}
48+
echo $document; // prints 06843273173
49+
echo $document->format(); // prints 068.432.731-73
50+
51+
```
52+
or
4153
```php
4254
use Brazanation\Documents\Cpf;
4355
use Brazanation\Documents\Exception\InvalidDocument as InvalidDocumentException;
4456

4557
try {
46-
$cpf = new Cpf('06843273173');
47-
echo $cpf; // prints 06843273173
48-
echo $cpf->format(); // prints 068.432.731-73
49-
}catch (InvalidDocumentException $e){
58+
$document = new Cpf('06843273173');
59+
echo $document; // prints 06843273173
60+
echo $document->format(); // prints 068.432.731-73
61+
} catch (InvalidDocumentException $e) {
5062
echo $e->getMessage();
5163
}
5264
```
@@ -57,15 +69,14 @@ Company Identification or National Register of Legal Entities
5769

5870
```php
5971
use Brazanation\Documents\Cnpj;
60-
use Brazanation\Documents\Exception\InvalidDocument as InvalidDocumentException;
6172

62-
try {
63-
$cnpj = new Cnpj('99999090910270');
64-
echo $cnpj; // prints 99999090910270
65-
echo $cnpj->format(); // prints 99.999.090/9102-70
66-
}catch (InvalidDocumentException $e){
67-
echo $e->getMessage();
73+
$document = Cnpj::createFromString('99999090910270');
74+
75+
if (false === $document) {
76+
echo "Not Valid";
6877
}
78+
echo $document; // prints 99999090910270
79+
echo $document->format(); // prints 99.999.090/9102-70
6980
```
7081

7182
### CNH (carteira nacional de habilitação)
@@ -74,15 +85,14 @@ National Driving License
7485

7586
```php
7687
use Brazanation\Documents\Cnh;
77-
use Brazanation\Documents\Exception\InvalidDocument as InvalidDocumentException;
7888

79-
try {
80-
$cnh = new Cnh('83592802666');
81-
echo $cnh; // prints 83592802666
82-
echo $cnh->format(); // prints 83592802666
83-
}catch (InvalidDocumentException $e){
84-
echo $e->getMessage();
89+
$document = Cnh::createFromString('83592802666');
90+
91+
if (false === $document) {
92+
echo "Not Valid";
8593
}
94+
echo $cnh; // prints 83592802666
95+
echo $cnh->format(); // prints 83592802666
8696
```
8797

8898
### Chave de Acesso Sped (chave da NFe, CTe e MDFe)
@@ -98,15 +108,14 @@ Available models:
98108

99109
```php
100110
use Brazanation\Documents\Sped\NFe;
101-
use Brazanation\Documents\Exception\InvalidDocument as InvalidDocumentException;
102111

103-
try {
104-
$accessKey = new NFe('52060433009911002506550120000007801267301613');
105-
echo $accessKey; // prints 52060433009911002506550120000007801267301613
106-
echo $accessKey->format(); // prints 5206 0433 0099 1100 2506 5501 2000 0007 8012 6730 1613
107-
}catch (InvalidDocumentException $e){
108-
echo $e->getMessage();
112+
$document = NFe::createFromString('52060433009911002506550120000007801267301613');
113+
114+
if (false === $document) {
115+
echo "Not Valid";
109116
}
117+
echo $document; // prints 52060433009911002506550120000007801267301613
118+
echo $document->format(); // prints 5206 0433 0099 1100 2506 5501 2000 0007 8012 6730 1613
110119
```
111120
or generate your number
112121

@@ -133,15 +142,15 @@ Social Integration Program and Training Program of the Heritage of Public Servan
133142

134143
```php
135144
use Brazanation\Documents\PisPasep;
136-
use Brazanation\Documents\Exception\InvalidDocument as InvalidDocumentException;
137145

138-
try {
139-
$pispasep = new PisPasep('51.82312.94-92');
140-
echo $pispasep; // prints 51823129492
141-
echo $pispasep->format(); // prints 51.82312.94-92
142-
}catch (InvalidDocumentException $e){
143-
echo $e->getMessage();
146+
$document = PisPasep::createFromString('51.82312.94-92');
147+
148+
if (false === $document) {
149+
echo "Not Valid";
144150
}
151+
152+
echo $document; // prints 51823129492
153+
echo $document->format(); // prints 51.82312.94-92
145154
```
146155

147156
### Título de Eleitor
@@ -150,16 +159,16 @@ Voter Registration
150159

151160
```php
152161
use Brazanation\Documents\Voter;
153-
use Brazanation\Documents\Exception\InvalidDocument as InvalidDocumentException;
154162

155-
try {
156-
$voter = new Voter('106644440302', 20, 42);
157-
echo $voter; // prints 106644440302
158-
echo $voter->getSection(); // prints 0020
159-
echo $voter->getZone(); // prints 042
160-
}catch (InvalidDocumentException $e){
161-
echo $e->getMessage();
163+
$document = Voter::createFromString('106644440302', 20, 42);
164+
165+
if (false === $document) {
166+
echo "Not Valid";
162167
}
168+
169+
echo $document; // prints 106644440302
170+
echo $document->getSection(); // prints 0020
171+
echo $document->getZone(); // prints 042
163172
```
164173

165174
### Inscrição Estadual
@@ -168,11 +177,6 @@ State Registration
168177

169178
```php
170179
use Brazanation\Documents\StateRegistration;
171-
use Brazanation\Documents\Exception\InvalidDocument as InvalidDocumentException;
172-
173-
$state = StateRegistration::AC('0100482300112');
174-
echo $state; // prints 0100482300112
175-
echo $state->format(); // prints 01.004.823/001-12
176180

177181
// for Commercial São Paulo
178182
$state = StateRegistration::SP('110.042.490.114');
@@ -183,6 +187,17 @@ echo $state->format(); // prints 110.042.490.114
183187
$state = StateRegistration::SP('P011004243002');
184188
echo $state; // prints P011004243002
185189
echo $state->format(); // prints P-01100424.3/002
190+
```
191+
or
192+
```php
193+
use Brazanation\Documents\StateRegistration;
194+
195+
$document = StateRegistration::createFromString('P011004243002', 'SP');
196+
197+
if (false === $document) {
198+
echo "Not Valid";
199+
}
200+
186201
```
187202

188203
### Cartão Nacional de Saúde (SUS)
@@ -192,9 +207,14 @@ National Health Card
192207
```php
193208
use Brazanation\Documents\Cns;
194209

195-
$cns = new Cns('242912018460005')
196-
echo $cns; // prints 242912018460005
197-
echo $cns->format(); // prints 242 9120 1846 0005
210+
$document = Cns::createFromString('242912018460005');
211+
212+
if (false === $document) {
213+
echo "Not Valid";
214+
}
215+
216+
echo $document; // prints 242912018460005
217+
echo $document->format(); // prints 242 9120 1846 0005
198218
```
199219

200220
### Renavam (Registro Nacional de Veículos Automotores)
@@ -204,9 +224,14 @@ National Registry of Motor Vehicles
204224
```php
205225
use Brazanation\Documents\Renavam;
206226

207-
$renavam = new Renavam('61855253306')
208-
echo $renavam; // prints 61855253306
209-
echo $renavam->format(); // prints 6185.525330-6
227+
$document = Renavam::createFromString('61855253306');
228+
229+
if (false === $document) {
230+
echo "Not Valid";
231+
}
232+
233+
echo $document; // prints 61855253306
234+
echo $document->format(); // prints 6185.525330-6
210235
```
211236

212237
### Processos Judiciais
@@ -216,9 +241,14 @@ Numbers of legal proceedings related to Judiciary assessments
216241
```php
217242
use Brazanation\Documents\JudiciaryProcess;
218243

219-
$procjud = new JudiciaryProcess('0048032982009809');
220-
echo $procjud; //prints 0048032982009809
221-
echo $procjud->format(); //prints 0048032.98.2009.8.09.0000
244+
$document = JudiciaryProcess::createFromString('0048032982009809');
245+
246+
if (false === $document) {
247+
echo "Not Valid";
248+
}
249+
250+
echo $document; //prints 0048032982009809
251+
echo $document->format(); //prints 0048032.98.2009.8.09.0000
222252

223253
```
224254

0 commit comments

Comments
 (0)