Skip to content

Commit

Permalink
Merge pull request #141 from cauafroes/feature/passaporte-validacao
Browse files Browse the repository at this point in the history
suporte validação passaporte
  • Loading branch information
geekcom authored Mar 7, 2024
2 parents 5460d4a + 4149012 commit 00e2c7f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/validator-docs/Rules/Passaporte.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace geekcom\ValidatorDocs\Rules;

final class Passaporte extends Sanitization
{
public function validatePassaporte($attribute, $value): bool
{
return preg_match('/^[A-Za-z]{2}\d{6}$/i', $value) > 0;
}
}
9 changes: 8 additions & 1 deletion src/validator-docs/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
Nis,
Placa,
Renavam,
TituloEleitoral};
TituloEleitoral,
Passaporte};
use Illuminate\Contracts\Translation\Translator;
use Illuminate\Validation\Validator as BaseValidator;

Expand Down Expand Up @@ -122,4 +123,10 @@ protected function validateDdd($attribute, $value): bool

return $ddd->validateDdd($attribute, $value);
}

protected function validatePassaporte($attribute, $value): bool
{
$passaporte = new Passaporte();
return $passaporte->validatePassaporte($attribute, $value);
}
}
1 change: 1 addition & 0 deletions src/validator-docs/ValidatorProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected function getMessages()
'certidao' => 'Número da Certidão inválido',
'ddd' => 'DDD inválido',
'placa' => 'Placa inválida',
'passaporte' => 'Passaporte inválido',
'formato_cnpj' => 'Formato inválido para CNPJ',
'formato_cpf' => 'Formato inválido para CPF',
'formato_cpf_cnpj' => 'Formato inválido para CPF ou CNPJ',
Expand Down
17 changes: 17 additions & 0 deletions tests/TestValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,21 @@ public function ddd()

$this->assertTrue($incorrect->fails());
}

/** @test **/
public function passaporte()
{
$correct = Validator::make(
['certo' => 'GB139485'],
['certo' => 'passaporte']
);

$incorrect = Validator::make(
['errado' => 'A3948'],
['errado' => 'passaporte']
);

$this->assertTrue($correct->passes());
$this->assertTrue($incorrect->fails());
}
}

0 comments on commit 00e2c7f

Please sign in to comment.