diff --git a/src/validator-docs/Rules/Cpf.php b/src/validator-docs/Rules/Cpf.php index 1175a2a..0a28d36 100644 --- a/src/validator-docs/Rules/Cpf.php +++ b/src/validator-docs/Rules/Cpf.php @@ -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)) { diff --git a/src/validator-docs/Validator.php b/src/validator-docs/Validator.php index efb0a90..84a4dd0 100644 --- a/src/validator-docs/Validator.php +++ b/src/validator-docs/Validator.php @@ -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); } diff --git a/tests/TestValidator.php b/tests/TestValidator.php index 7506901..2a870b4 100644 --- a/tests/TestValidator.php +++ b/tests/TestValidator.php @@ -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 **/