Skip to content

Commit 865c2a7

Browse files
author
Evandro Kondrat
committed
Merge remote-tracking branch 'upstream/master'
2 parents aa91ca2 + 5464a7e commit 865c2a7

15 files changed

+573
-204
lines changed

CHANGELOG.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<!-- changelog-linker -->
2+
3+
<!-- dumped content start -->
4+
5+
## [3.3.1]
6+
7+
- [#50] minor correction, update doc, Thanks to [@geekcom]
8+
9+
<!-- dumped content end -->
10+
11+
<!-- dumped content start -->
12+
13+
## [3.3.0]
14+
15+
- [#49] solved: complexity, update: tests, Thanks to [@geekcom]
16+
17+
<!-- dumped content end -->
18+
19+
<!-- dumped content start -->
20+
21+
## Unreleased
22+
23+
- [#48] added support for changelogs, Thanks to [@geekcom]
24+
- [#45] fixing "Unparenthesized is deprecated" error, Thanks to [@kidh0]
25+
- [#17] fix: erro em phpunit.xml, melhorias nos testes, namespace para testes, Thanks to [@geekcom]
26+
- [#25] Melhorias de leitura nos códigos, Thanks to [@geekcom]
27+
- [#2] Alteração da função validateCnpj para impedir que o Cnpj 00.000.000/0…, Thanks to [@andrergcosta]
28+
- [#3] Criada as funções validateFormatoCpfCnpj e validateCpfCnpj, Thanks to [@andrergcosta]
29+
- [#4] Inclusão do exemplo para validação de CPF/CNPJ no arquivo readme, Thanks to [@andrergcosta]
30+
- [#5] Validar título eleitor, Thanks to [@andrergcosta]
31+
- [#8] Faltando parâmetro $attributes em ValidatorProvider., Thanks to [@setefocos]
32+
- [#11] nova badge e melhoria no readme.me, Thanks to [@geekcom]
33+
- [#12] scrutinizer CI, Thanks to [@geekcom]
34+
- [#19] Criação da função para verificar PIS/PASEP/NIS/NIT, Thanks to [@lordantonelli]
35+
- [#20] Master from develop, Thanks to [@geekcom]
36+
- [#21] Merge pull request [#20] from geekcom/master, Thanks to [@geekcom]
37+
- [#23] update docs, minor corrections, Thanks to [@geekcom]
38+
- [#24] update docs, Thanks to [@geekcom]
39+
- [#30] update scrutinizer CI check, Thanks to [@geekcom]
40+
- [#27] atualizacao para Laravel 6, Thanks to [@geekcom]
41+
- [#47] Merge pull request [#46] from geekcom/master, Thanks to [@geekcom]
42+
- [#31] Atualização dos requisitos e testes, Thanks to [@victorhsanjos]
43+
- [#32] master into develop, Thanks to [@geekcom]
44+
- [#33] Merge pull request [#32] from geekcom/master, Thanks to [@geekcom]
45+
- [#35] auto-discover composer, Thanks to [@geekcom]
46+
- [#37] Adicionando validação do Cartão Nacional de Saúde, Thanks to [@MrEko]
47+
- [#38] Merge, Thanks to [@geekcom]
48+
- [#39] Merge pull request [#38] from geekcom/master, Thanks to [@geekcom]
49+
- [#40] melhorias de documentacao e sintaxe, v3.0.0, Thanks to [@geekcom]
50+
- [#41] Validação de Certidão de Nascimento, Casamento ou Óbito, Thanks to [@MrEko]
51+
- [#42] merge master into develop, Thanks to [@geekcom]
52+
- [#43] Merge pull request [#42] from geekcom/master, Thanks to [@geekcom]
53+
- [#44] melhoria na validacao de CNH,strict_types PHP ativado, Thanks to [@geekcom]
54+
- [#46] merge master inte develop, Thanks to [@geekcom]
55+
- [#1] Update README.md, Thanks to [@yvescabral]
56+
57+
<!-- dumped content end -->
58+
59+
[#48]: https://github.com/geekcom/validator-docs/pull/48
60+
[#47]: https://github.com/geekcom/validator-docs/pull/47
61+
[#46]: https://github.com/geekcom/validator-docs/pull/46
62+
[#45]: https://github.com/geekcom/validator-docs/pull/45
63+
[#44]: https://github.com/geekcom/validator-docs/pull/44
64+
[#43]: https://github.com/geekcom/validator-docs/pull/43
65+
[#42]: https://github.com/geekcom/validator-docs/pull/42
66+
[#41]: https://github.com/geekcom/validator-docs/pull/41
67+
[#40]: https://github.com/geekcom/validator-docs/pull/40
68+
[#39]: https://github.com/geekcom/validator-docs/pull/39
69+
[#38]: https://github.com/geekcom/validator-docs/pull/38
70+
[#37]: https://github.com/geekcom/validator-docs/pull/37
71+
[#35]: https://github.com/geekcom/validator-docs/pull/35
72+
[#33]: https://github.com/geekcom/validator-docs/pull/33
73+
[#32]: https://github.com/geekcom/validator-docs/pull/32
74+
[#31]: https://github.com/geekcom/validator-docs/pull/31
75+
[#30]: https://github.com/geekcom/validator-docs/pull/30
76+
[#27]: https://github.com/geekcom/validator-docs/pull/27
77+
[#25]: https://github.com/geekcom/validator-docs/pull/25
78+
[#24]: https://github.com/geekcom/validator-docs/pull/24
79+
[#23]: https://github.com/geekcom/validator-docs/pull/23
80+
[#21]: https://github.com/geekcom/validator-docs/pull/21
81+
[#20]: https://github.com/geekcom/validator-docs/pull/20
82+
[#19]: https://github.com/geekcom/validator-docs/pull/19
83+
[#17]: https://github.com/geekcom/validator-docs/pull/17
84+
[#12]: https://github.com/geekcom/validator-docs/pull/12
85+
[#11]: https://github.com/geekcom/validator-docs/pull/11
86+
[#8]: https://github.com/geekcom/validator-docs/pull/8
87+
[#5]: https://github.com/geekcom/validator-docs/pull/5
88+
[#4]: https://github.com/geekcom/validator-docs/pull/4
89+
[#3]: https://github.com/geekcom/validator-docs/pull/3
90+
[#2]: https://github.com/geekcom/validator-docs/pull/2
91+
[#1]: https://github.com/geekcom/validator-docs/pull/1
92+
[@yvescabral]: https://github.com/yvescabral
93+
[@victorhsanjos]: https://github.com/victorhsanjos
94+
[@setefocos]: https://github.com/setefocos
95+
[@lordantonelli]: https://github.com/lordantonelli
96+
[@kidh0]: https://github.com/kidh0
97+
[@geekcom]: https://github.com/geekcom
98+
[@andrergcosta]: https://github.com/andrergcosta
99+
[@MrEko]: https://github.com/MrEko
100+
[#49]: https://github.com/geekcom/validator-docs/pull/49
101+
[#50]: https://github.com/geekcom/validator-docs/pull/50

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ _Validação de documentos do Brasil usando **Laravel 6**_
77

88
> Para a versão compatível com Laravel 5 consulte o branch https://github.com/geekcom/validator-docs/tree/5.x.x
99
10-
Biblioteca Laravel para validação de CPF, CNPJ, CPF/CNPJ (quando salvos no mesmo atributo), CNH, PIS/PASEP/NIT/NIS, Título de Eleitor e Cartão Nacional de Saúde(CNS).
10+
Biblioteca Laravel para validação de CPF, CNPJ, CPF/CNPJ (quando salvos no mesmo atributo), CNH, PIS/PASEP/NIT/NIS, Título de Eleitor, Cartão Nacional de Saúde(CNS) e Certidões(nascimento/casamento/óbito).
1111

1212
## Instalação
1313

1414
No arquivo `composer.json`, adicione validator-docs como dependência do seu projeto:
1515

1616
```
1717
"require": {
18-
"geekcom/validator-docs" : "^3.0"
18+
"geekcom/validator-docs" : "^3.3"
1919
},
2020
```
2121

@@ -93,6 +93,14 @@ $this->validate($request, [
9393
]);
9494
```
9595

96+
* **certidao** - Verifica se uma certidão de nascimento/casamento/óbito é válida.
97+
98+
```php
99+
$this->validate($request, [
100+
'certidao' => 'required|certidao',
101+
]);
102+
```
103+
96104
* **formato_cnpj** - Verifica se o formato de um CNPJ é válida. ( 99.999.999/9999-99 )
97105

98106
```php
@@ -124,6 +132,14 @@ $this->validate($request, [
124132
'formato_nis' => 'required|formato_nis',
125133
]);
126134
```
135+
136+
* **formato_certidao** - Verifica se o formato de uma certidão é válida. ( 99999.99.99.9999.9.99999.999.9999999-99 ou 99999 99 99 9999 9 99999 999 9999999 99)
137+
138+
```php
139+
$this->validate($request, [
140+
'formato_certidao' => 'required|formato_certidao',
141+
]);
142+
```
127143
----------------------------------------------------------------------------------------------------------------------------
128144

129145
## Combinando validação e formato
@@ -170,6 +186,7 @@ public function store(Request $request)
170186
* **CPF** - http://geradordecpf.org
171187
* **NIS** - https://www.4devs.com.br/gerador_de_pis_pasep
172188
* **CNS** - https://geradornv.com.br/gerador-cns/
189+
* **CERTIDÃO** - https://www.treinaweb.com.br/ferramentas-para-desenvolvedores/gerador/certidao
173190

174191
Fique a vontade para contribuir fazendo um fork.
175192

changelog-linker.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parameters:
2+
repository_url: 'https://github.com/geekcom/validator-docs'

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
},
1414
"require-dev": {
1515
"phpunit/phpunit": "^8.3",
16-
"orchestra/testbench": "^4.0"
16+
"orchestra/testbench": "^4.0",
17+
"symplify/changelog-linker": "^6.1"
1718
},
1819
"autoload": {
1920
"psr-4": {

src/validator-docs/Rules/Certidao.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace geekcom\ValidatorDocs\Rules;
6+
7+
use function mb_strlen;
8+
use function preg_match;
9+
use function substr;
10+
11+
final class Certidao extends Sanitization
12+
{
13+
/*
14+
* CERTIDÃO DE NASCIMENTO/CASAMENTO/ÓBITO
15+
* Fonte: http://ghiorzi.org/DVnew.htm#zc
16+
*
17+
* Nota: se o resto for "10", o DV será "1"
18+
*/
19+
public function validateCertidao($attribute, $value): bool
20+
{
21+
$certidao = $this->sanitize($value);
22+
23+
if (!preg_match("/[0-9]{32}/", $certidao)) {
24+
return false;
25+
}
26+
27+
$num = substr($certidao, 0, -2);
28+
$dv = substr($certidao, -2);
29+
30+
$dv1 = $this->somaPonderadaCertidao($num) % 11;
31+
$dv1 = $dv1 > 9 ? 1 : $dv1;
32+
$dv2 = $this->somaPonderadaCertidao($num.$dv1) % 11;
33+
$dv2 = $dv2 > 9 ? 1 : $dv2;
34+
35+
// Compara o dv recebido com os dois numeros calculados
36+
if ($dv === $dv1.$dv2) {
37+
return true;
38+
}
39+
40+
return false;
41+
}
42+
43+
private function somaPonderadaCertidao($value): int
44+
{
45+
$soma = 0;
46+
47+
$multiplicador = 32 - mb_strlen($value);
48+
49+
for ($i = 0; $i < mb_strlen($value); $i++) {
50+
51+
$soma += $value[$i] * $multiplicador;
52+
53+
$multiplicador += 1;
54+
$multiplicador = $multiplicador > 10 ? 0 : $multiplicador;
55+
}
56+
57+
return $soma;
58+
}
59+
}

src/validator-docs/Rules/Cnh.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace geekcom\ValidatorDocs\Rules;
6+
7+
use function mb_strlen;
8+
use function is_scalar;
9+
10+
final class Cnh extends Sanitization
11+
{
12+
/**
13+
* Trecho retirado do respect validation
14+
*/
15+
public function validateCnh($attribute, $value): bool
16+
{
17+
if (!is_scalar($value)) {
18+
return false;
19+
}
20+
21+
$value = $this->sanitize($value);
22+
23+
if (mb_strlen($value) != 11 || ((int) $value === 0)) {
24+
return false;
25+
}
26+
27+
for ($c = $s1 = $s2 = 0, $p = 9; $c < 9; $c++, $p--) {
28+
$s1 += (int) $value[$c] * $p;
29+
$s2 += (int) $value[$c] * (10 - $p);
30+
}
31+
32+
$dv1 = $s1 % 11;
33+
if ($value[9] != ($dv1 > 9) ? 0 : $dv1) {
34+
return false;
35+
}
36+
37+
$dv2 = $s2 % 11 - ($dv1 > 9 ? 2 : 0);
38+
39+
$check = $dv2 < 0 ? $dv2 + 11 : ($dv2 > 9 ? 0 : $dv2);
40+
41+
return $value[10] == $check;
42+
}
43+
}

src/validator-docs/Rules/Cnpj.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace geekcom\ValidatorDocs\Rules;
6+
7+
use function mb_strlen;
8+
use function preg_match;
9+
10+
final class Cnpj extends Sanitization
11+
{
12+
public function validateCnpj($attribute, $value): bool
13+
{
14+
$c = $this->sanitize($value);
15+
16+
if (mb_strlen($c) != 14 || preg_match("/^{$c[0]}{14}$/", $c)) {
17+
return false;
18+
}
19+
20+
$b = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
21+
22+
for ($i = 0, $n = 0; $i < 12; $n += $c[$i] * $b[++$i]);
23+
24+
if ($c[12] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
25+
return false;
26+
}
27+
28+
for ($i = 0, $n = 0; $i <= 12; $n += $c[$i] * $b[$i++]);
29+
30+
if ($c[13] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
31+
return false;
32+
}
33+
34+
return true;
35+
}
36+
}

src/validator-docs/Rules/Cns.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace geekcom\ValidatorDocs\Rules;
6+
7+
use function preg_match;
8+
use function mb_strlen;
9+
10+
final class Cns extends Sanitization
11+
{
12+
public function validateCns($attribute, $value): bool
13+
{
14+
$cns = $this->sanitize($value);
15+
16+
// CNSs definitivos começam em 1 ou 2 / CNSs provisórios em 7, 8 ou 9
17+
if (preg_match("/[1-2][0-9]{10}00[0-1][0-9]/", $cns) || preg_match("/[7-9][0-9]{14}/", $cns)) {
18+
return $this->somaPonderadaCns($cns) % 11 == 0;
19+
}
20+
21+
return false;
22+
}
23+
24+
private function somaPonderadaCns($value): int
25+
{
26+
$soma = 0;
27+
28+
for ($i = 0; $i < mb_strlen($value); $i++) {
29+
$soma += $value[$i] * (15 - $i);
30+
}
31+
32+
return $soma;
33+
}
34+
}

src/validator-docs/Rules/Cpf.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace geekcom\ValidatorDocs\Rules;
6+
7+
use function preg_match;
8+
use function mb_strlen;
9+
10+
final class Cpf extends Sanitization
11+
{
12+
public function validateCpf($attribute, $value): bool
13+
{
14+
$c = $this->sanitize($value);
15+
16+
if (mb_strlen($c) != 11 || preg_match("/^{$c[0]}{11}$/", $c)) {
17+
return false;
18+
}
19+
20+
for ($s = 10, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--);
21+
22+
if ($c[9] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
23+
return false;
24+
}
25+
26+
for ($s = 11, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--);
27+
28+
if ($c[10] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
29+
return false;
30+
}
31+
32+
return true;
33+
}
34+
}

0 commit comments

Comments
 (0)