Merge pull request #23 from jeanpimentel/develop

Remove Length Validator in Cpf Validator
This commit is contained in:
Alexandre Gomes Gaigalas 2011-09-22 16:01:07 -07:00
commit 36ea1579f6
2 changed files with 6 additions and 19 deletions

View file

@ -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);
}
}
}

View file

@ -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 {
);
}
}
}