Skip to content

Commit 2d7e7ba

Browse files
authored
Revert "fix CPF validation"
1 parent 7d0040c commit 2d7e7ba

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

src/validator-docs/Rules/Cpf.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,13 @@
44

55
namespace geekcom\ValidatorDocs\Rules;
66

7-
use geekcom\ValidatorDocs\ValidatorFormats;
8-
97
use function preg_match;
108
use function mb_strlen;
119

1210
final class Cpf extends Sanitization
1311
{
14-
protected function validateCPFFormat(string $value)
15-
{
16-
if (!empty($value)) {
17-
return (new ValidatorFormats())->execute($value, 'cpf');
18-
}
19-
}
20-
2112
public function validateCpf($attribute, $value): bool
2213
{
23-
24-
if (!$this->validateCPFFormat($value)) {
25-
return false;
26-
}
27-
2814
$c = $this->sanitize($value);
2915

3016
if (mb_strlen($c) != 11 || preg_match("/^{$c[0]}{11}$/", $c)) {

src/validator-docs/Validator.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,19 @@ public function __construct(
3030
parent::__construct($translator, $data, $rules, $messages, $customAttributes);
3131
}
3232

33+
protected function validateFormat($value, $document, $attribute = null)
34+
{
35+
if (!empty($value)) {
36+
return (new ValidatorFormats())->execute($value, $document);
37+
}
38+
}
39+
3340
protected function validateCpf($attribute, $value): bool
3441
{
3542
$cpf = new Cpf();
3643

44+
$this->validateFormat($value, 'cpf');
45+
3746
return $cpf->validateCpf($attribute, $value);
3847
}
3948

tests/TestValidator.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,9 @@ public function cpf()
1919
['errado' => 'cpf']
2020
);
2121

22-
$incorrectWithAlpha = Validator::make(
23-
['errado' => '094.050.986-59ABCDEF'],
24-
['errado' => 'cpf']
25-
);
26-
2722
$this->assertTrue($correct->passes());
2823

2924
$this->assertTrue($incorrect->fails());
30-
31-
$this->assertTrue($incorrectWithAlpha->fails());
3225
}
3326

3427
/** @test **/

0 commit comments

Comments
 (0)