mirror of
https://github.com/Respect/Validation.git
synced 2024-06-27 17:50:13 +02:00
Merge pull request #23 from jeanpimentel/develop
Remove Length Validator in Cpf Validator
This commit is contained in:
commit
36ea1579f6
|
@ -2,17 +2,15 @@
|
|||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
use Respect\Validation\Rules\Length;
|
||||
|
||||
class Cpf extends AbstractRule
|
||||
{
|
||||
|
||||
public function validate($input)
|
||||
{
|
||||
|
||||
$input = $this->clean($input);
|
||||
$input = preg_replace('([^0-9])', '', $input);
|
||||
|
||||
if ($this->hasInvalidLength($input))
|
||||
if (strlen($input) != 11)
|
||||
return false;
|
||||
|
||||
if ($this->isSequenceOfNumber($input))
|
||||
|
@ -56,13 +54,7 @@ class Cpf extends AbstractRule
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function hasInvalidLength($input)
|
||||
{
|
||||
$vl = new Length(11,11);
|
||||
return !$vl->assert($input);
|
||||
}
|
||||
|
||||
|
||||
private function isSequenceOfNumber($input)
|
||||
{
|
||||
for ($i = 0; $i <= 9; $i++)
|
||||
|
@ -72,9 +64,4 @@ class Cpf extends AbstractRule
|
|||
return false;
|
||||
}
|
||||
|
||||
private function clean($input)
|
||||
{
|
||||
return preg_replace("/\.|-/", "", $input);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ class CpfTest extends \PHPUnit_Framework_TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider providerInvalidFormattedAndUnformattedCpfLength
|
||||
* @expectedException Respect\Validation\Exceptions\LengthException
|
||||
* @expectedException Respect\Validation\Exceptions\CpfException
|
||||
*/
|
||||
public function testInvalidFormattedAndUnformattedCpfLength($input)
|
||||
{
|
||||
|
@ -112,4 +112,4 @@ class CpfTest extends \PHPUnit_Framework_TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue