Skip to content

Commit 0ebd28c

Browse files
authored
Merge pull request #98 from geekcom/master
Sync master into develop
2 parents 85a9c0e + 2c256ef commit 0ebd28c

File tree

9 files changed

+331
-4
lines changed

9 files changed

+331
-4
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: "Proposing Changes"
2+
3+
on:
4+
pull_request:
5+
branches: [ master, develop ]
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- name: Validate composer.json and composer.lock
15+
run: composer validate
16+
17+
- name: Cache Composer packages
18+
id: composer-cache
19+
uses: actions/cache@v2
20+
with:
21+
path: vendor
22+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
23+
restore-keys: |
24+
${{ runner.os }}-php-
25+
- name: Install dependencies
26+
if: steps.composer-cache.outputs.cache-hit != 'true'
27+
run: composer install --prefer-dist --no-progress --no-suggest
28+
29+
- name: Run Tests And Lint
30+
run: composer test

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# LaraValidator Docs - Brasil
22

3-
_Validação de documentos do Brasil usando **Laravel 6/7**_
3+
_Validação de documentos do Brasil usando **Laravel 6/7/8**_
44

55
[![Build Status](https://travis-ci.org/geekcom/validator-docs.svg?branch=master)](https://travis-ci.org/geekcom/validator-docs)
66
[![Coverage Status](https://coveralls.io/repos/github/geekcom/validator-docs/badge.svg?branch=master)](https://coveralls.io/github/geekcom/validator-docs?branch=master)
@@ -13,7 +13,7 @@ _Validação de documentos do Brasil usando **Laravel 6/7**_
1313

1414
> Para a versão compatível com Laravel 5 consulte o branch https://github.com/geekcom/validator-docs/tree/5.x.x
1515
16-
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).
16+
Biblioteca Laravel para validação de CPF, CNPJ, CPF/CNPJ (quando salvos no mesmo atributo), CNH, PIS/PASEP/NIT/NIS, Inscrição Estadual, Título de Eleitor, Cartão Nacional de Saúde(CNS) e Certidões(nascimento/casamento/óbito).
1717

1818
## Instalação
1919

@@ -83,6 +83,14 @@ $this->validate($request, [
8383
]);
8484
```
8585

86+
* **inscricao_estadual** - Verifica se uma Inscrição Estadual é valida para uma unidade federarativa (UF).
87+
88+
```php
89+
$this->validate($request, [
90+
'inscricao_estadual' => 'required|inscricao_estadual:BA',
91+
]);
92+
```
93+
8694
* **nis** - Verifica se um PIS/PASEP/NIT/NIS é válido.
8795

8896
```php
@@ -107,6 +115,22 @@ $this->validate($request, [
107115
]);
108116
```
109117

118+
* **renavam** - Verifica se o RENAVAM é válido
119+
120+
```php
121+
$this->validate($request, [
122+
'renavam' => 'required|renavam',
123+
]);
124+
```
125+
126+
* **placa** - Verifica se a PLACA é válida
127+
128+
```php
129+
$this->validate($request, [
130+
'placa' => 'required|placa',
131+
]);
132+
```
133+
110134
* **formato_cnpj** - Verifica se o formato de um CNPJ é válida. ( 99.999.999/9999-99 )
111135

112136
```php
@@ -176,6 +200,8 @@ public function store(Request $request)
176200
'titulo_eleitor' => 'required|titulo_eleitor',
177201
'nis' => 'required|nis',
178202
'cns' => 'required|cns',
203+
'renavam' => 'required|renavam',
204+
'placa' => 'required|placa',
179205
]);
180206

181207
dd($data);
@@ -193,6 +219,9 @@ public function store(Request $request)
193219
* **NIS** - https://www.4devs.com.br/gerador_de_pis_pasep
194220
* **CNS** - https://geradornv.com.br/gerador-cns/
195221
* **CERTIDÃO** - https://www.treinaweb.com.br/ferramentas-para-desenvolvedores/gerador/certidao
222+
* **INSCRIÇÃO ESTADUAL** - https://www.4devs.com.br/gerador_de_inscricao_estadual
223+
* **RENAVAM** - https://www.4devs.com.br/gerador_de_renavam
224+
* **PLACA** - https://www.4devs.com.br/gerador_de_placa_automoveis
196225

197226
Fique a vontade para contribuir fazendo um fork.
198227

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
}
1010
],
1111
"require": {
12-
"php": "^7.2"
12+
"php": "^7.2",
13+
"thiagocfn/inscricaoestadual": "^1.1"
1314
},
1415
"require-dev": {
1516
"phpunit/phpunit": "^8.4",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace geekcom\ValidatorDocs\Rules;
5+
6+
use Thiagocfn\InscricaoEstadual\Util\Validador;
7+
8+
final class InscricaoEstadual extends Sanitization
9+
{
10+
public function validateInscricaoEstadual($attribute, $value, $parameters)
11+
{
12+
if(empty($parameters[0]) || !is_string($parameters[0])) {
13+
return false;
14+
}
15+
$siglaUf = $this->sanitizeSiglaUf($parameters[0]);
16+
$inscricaoEstadual = $this->sanitize($value);
17+
return Validador::check($siglaUf, $inscricaoEstadual);
18+
}
19+
20+
/**
21+
* @param mixed $siglaUf
22+
* @return false|string|string[]
23+
*/
24+
private function sanitizeSiglaUf($siglaUf)
25+
{
26+
return mb_strtoupper($siglaUf);
27+
}
28+
}

src/validator-docs/Rules/Placa.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace geekcom\ValidatorDocs\Rules;
4+
5+
final class Placa extends Sanitization
6+
{
7+
public function validatePlaca($attribute, $placa): bool
8+
{
9+
$placa = $this->sanitize($placa);
10+
11+
$regexPlaca = '/^[A-Z][0-9]{5}$|' . // Placas dos anos 1915-1941 [ex A12345]
12+
'^[0-9]{7}$|' . // Placas dos anos 1941-1969 [ex 1234567]
13+
'^[A-Z]{2}[0-9]{4}$|' . // Placas dos anos 1969-1990 [ex AA1234]
14+
'^[A-Z]{3}[0-9]{4}$|' . // Placas dos anos 1990-2018 [ex AAA1234]
15+
'^[A-Z]{3}[0-9]{1}[A-Z]{1}[0-9]{2}$|' . // Placas de carros dos anos 2018+ [ex AAA1A23]
16+
'^[A-Z]{3}[0-9]{2}[A-Z]{1}[0-9]{1}$' . // Placas de motos dos anos 2018+ [ex AAA12A3]
17+
'/i';
18+
19+
return preg_match($regexPlaca, $placa) > 0;
20+
}
21+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace geekcom\ValidatorDocs\Rules;
4+
5+
class Renavam extends Sanitization
6+
{
7+
public function validateRenavam($attribute, $renavam): bool
8+
{
9+
$renavam = $this->sanitize($renavam);
10+
$sum = 0;
11+
$renavamArray = str_split($renavam);
12+
$digitCount = 0;
13+
14+
for ($i = 5; $i >= 2; $i--) {
15+
$sum += $renavamArray[$digitCount] * $i;
16+
$digitCount++;
17+
}
18+
19+
$valor = $sum % 11;
20+
21+
$digit = $valor;
22+
23+
if ($valor == 11 || $valor == 0 || $valor >= 10) {
24+
$digit = 0;
25+
}
26+
27+
if ($digit == $renavamArray[4]) {
28+
return true;
29+
}
30+
31+
return false;
32+
}
33+
}

src/validator-docs/Validator.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace geekcom\ValidatorDocs;
66

7+
use geekcom\ValidatorDocs\Rules\Placa;
8+
use geekcom\ValidatorDocs\Rules\Renavam;
79
use Illuminate\Validation\Validator as BaseValidator;
810
use geekcom\ValidatorDocs\Rules\TituloEleitoral;
911
use geekcom\ValidatorDocs\Rules\Cns;
@@ -12,6 +14,7 @@
1214
use geekcom\ValidatorDocs\Rules\Cnpj;
1315
use geekcom\ValidatorDocs\Rules\Cnh;
1416
use geekcom\ValidatorDocs\Rules\Certidao;
17+
use geekcom\ValidatorDocs\Rules\InscricaoEstadual;
1518

1619
use function preg_match;
1720

@@ -103,4 +106,25 @@ protected function validateCertidao($attribute, $value): bool
103106

104107
return $certidao->validateCertidao($attribute, $value);
105108
}
109+
110+
protected function validateInscricaoEstadual($attribute, $value, $parameters): bool
111+
{
112+
$inscricaoEstadual = new InscricaoEstadual();
113+
114+
return $inscricaoEstadual->validateInscricaoEstadual($attribute, $value, $parameters);
115+
}
116+
117+
protected function validateRenavam($attribute, $value): bool
118+
{
119+
$renavam = new Renavam();
120+
121+
return $renavam->validateRenavam($attribute, $value);
122+
}
123+
124+
protected function validatePlaca($attribute, $value): bool
125+
{
126+
$placa = new Placa();
127+
128+
return $placa->validatePlaca($attribute, $value);
129+
}
106130
}

src/validator-docs/ValidatorProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ protected function getMessages()
3636
'titulo_eleitor' => 'Título de Eleitor inválido',
3737
'cnpj' => 'CNPJ inválido',
3838
'cpf' => 'CPF inválido',
39+
'renavam' => 'Renavam inválido',
3940
'cpf_cnpj' => 'CPF ou CNPJ inválido',
4041
'nis' => 'PIS/PASEP/NIT/NIS inválido',
4142
'cns' => 'Cartão Nacional de Saúde inválido',
43+
'inscricao_estadual' => 'Inscrição Estadual ou UF inválidas',
4244
'certidao' => 'Número da Certidão inválido',
4345
'formato_cnpj' => 'Formato inválido para CNPJ',
4446
'formato_cpf' => 'Formato inválido para CPF',

0 commit comments

Comments
 (0)