Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/validator-docs/Rules/Cpf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,13 @@

namespace geekcom\ValidatorDocs\Rules;

use geekcom\ValidatorDocs\ValidatorFormats;

use function preg_match;
use function mb_strlen;

final class Cpf extends Sanitization
{
protected function validateCPFFormat(string $value)
{
if (!empty($value)) {
return (new ValidatorFormats())->execute($value, 'cpf');
}
}

public function validateCpf($attribute, $value): bool
{

if (!$this->validateCPFFormat($value)) {
return false;
}

$c = $this->sanitize($value);

if (mb_strlen($c) != 11 || preg_match("/^{$c[0]}{11}$/", $c)) {
Expand Down
9 changes: 9 additions & 0 deletions src/validator-docs/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,19 @@ public function __construct(
parent::__construct($translator, $data, $rules, $messages, $customAttributes);
}

protected function validateFormat($value, $document, $attribute = null)
{
if (!empty($value)) {
return (new ValidatorFormats())->execute($value, $document);
}
}

protected function validateCpf($attribute, $value): bool
{
$cpf = new Cpf();

$this->validateFormat($value, 'cpf');

return $cpf->validateCpf($attribute, $value);
}

Expand Down
7 changes: 0 additions & 7 deletions tests/TestValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,9 @@ public function cpf()
['errado' => 'cpf']
);

$incorrectWithAlpha = Validator::make(
['errado' => '094.050.986-59ABCDEF'],
['errado' => 'cpf']
);

$this->assertTrue($correct->passes());

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

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

/** @test **/
Expand Down
Loading