Skip to content

Commit b8b2941

Browse files
authored
Merge branch 'master' into valida-inscricao-estadual
2 parents 4fabe37 + 57a16aa commit b8b2941

File tree

7 files changed

+163
-1
lines changed

7 files changed

+163
-1
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,22 @@ $this->validate($request, [
115115
]);
116116
```
117117

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+
118134
* **formato_cnpj** - Verifica se o formato de um CNPJ é válida. ( 99.999.999/9999-99 )
119135

120136
```php
@@ -184,6 +200,8 @@ public function store(Request $request)
184200
'titulo_eleitor' => 'required|titulo_eleitor',
185201
'nis' => 'required|nis',
186202
'cns' => 'required|cns',
203+
'renavam' => 'required|renavam',
204+
'placa' => 'required|placa',
187205
]);
188206

189207
dd($data);
@@ -202,6 +220,8 @@ public function store(Request $request)
202220
* **CNS** - https://geradornv.com.br/gerador-cns/
203221
* **CERTIDÃO** - https://www.treinaweb.com.br/ferramentas-para-desenvolvedores/gerador/certidao
204222
* **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
205225

206226
Fique a vontade para contribuir fazendo um fork.
207227

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: 16 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;
@@ -111,4 +113,18 @@ protected function validateInscricaoEstadual($attribute, $value, $parameters): b
111113

112114
return $inscricaoEstadual->validateInscricaoEstadual($attribute, $value, $parameters);
113115
}
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+
}
114130
}

src/validator-docs/ValidatorProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ 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',

tests/TestValidator.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,4 +383,45 @@ public function inscricaoEstadual($data, $rules, $assert)
383383
);
384384
$this->assertTrue($correct->{$assert}());
385385
}
386-
}
386+
387+
/** @test**/
388+
public function formatoRenavam()
389+
{
390+
$correct = Validator::make(
391+
['certo' => '197073212'],
392+
['certo' => 'renavam']
393+
);
394+
395+
$incorrect = Validator::make(
396+
['errado' => '1234555582'],
397+
['errado' => 'renavam']
398+
);
399+
400+
$this->assertTrue($correct->passes());
401+
$this->assertTrue($incorrect->fails());
402+
403+
$correct = Validator::make(
404+
['certo' => '1970.73212'],
405+
['certo' => 'renavam']
406+
);
407+
408+
$this->assertTrue($correct->passes());
409+
}
410+
411+
public function placa()
412+
{
413+
$correct = Validator::make(
414+
['certo' => 'P15186'],
415+
['certo' => 'placa']
416+
);
417+
418+
$incorrect = Validator::make(
419+
['errado' => 'X1234'],
420+
['errado' => 'placa']
421+
);
422+
423+
$this->assertTrue($correct->passes());
424+
425+
$this->assertTrue($incorrect->fails());
426+
}
427+
}

0 commit comments

Comments
 (0)