Merge branch '1.0' into 1.1

This commit is contained in:
Henrique Moody 2017-01-26 15:39:48 +01:00
commit 03f4abbd08
No known key found for this signature in database
GPG key ID: 221E9281655813A6
4 changed files with 34 additions and 17 deletions

View file

@ -15,23 +15,31 @@ class Cnpj extends AbstractRule
{
public function validate($input)
{
//Code ported from jsfromhell.com
$c = preg_replace('/\D/', '', $input);
if (!is_scalar($input)) {
return false;
}
// Code ported from jsfromhell.com
$cleanInput = preg_replace('/\D/', '', $input);
$b = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
if (strlen($c) != 14) {
if ($cleanInput < 1) {
return false;
}
for ($i = 0, $n = 0; $i < 12; $n += $c[$i] * $b[++$i]);
if ($c[12] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
if (mb_strlen($cleanInput) != 14) {
return false;
}
for ($i = 0, $n = 0; $i <= 12; $n += $c[$i] * $b[$i++]);
for ($i = 0, $n = 0; $i < 12; $n += $cleanInput[$i] * $b[++$i]);
if ($c[13] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
if ($cleanInput[12] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
return false;
}
for ($i = 0, $n = 0; $i <= 12; $n += $cleanInput[$i] * $b[$i++]);
if ($cleanInput[13] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
return false;
}

View file

@ -43,7 +43,7 @@ class PostalCode extends Regex
'CL' => "/^(\d{7})$/",
'CN' => "/^(\d{6})$/",
'CR' => "/^(\d{4})$/",
'CS' => "/^(\d{5})$/",
'CS' => "/^((\d{5})|(\d{3}\040\d{2}))$/",
'CU' => "/^(?:CP)*(\d{5})$/",
'CV' => "/^(\d{4})$/",
'CX' => "/^(\d{4})$/",
@ -147,7 +147,7 @@ class PostalCode extends Regex
'SG' => "/^(\d{6})$/",
'SH' => '/^(STHL1ZZ)$/',
'SI' => "/^(?:SI)*(\d{4})$/",
'SK' => "/^(\d{5})$/",
'SK' => "/^((\d{5})|(\d{3}\040\d{2}))$/",
'SM' => "/^(4789\d)$/",
'SN' => "/^(\d{5})$/",
'SO' => "/^([A-Z]{2}\d{5})$/",

View file

@ -36,8 +36,9 @@ class CuSubdivisionCode extends AbstractSearcher
'12', // Granma
'13', // Santiago de Cuba
'14', // Guantanamo
'15', // Artemisa
'16', // Mayabeque
'99', // Isla de la Juventud
'02', // La Habana
];
public $compareIdentical = true;

View file

@ -99,12 +99,20 @@ class CnpjTest extends \PHPUnit_Framework_TestCase
public function providerInvalidUnformattedCnpj()
{
return [
['11111111111'],
['22222222222'],
['12345678900'],
['99299929384'],
['84434895894'],
['44242340000'],
['00000000000000'],
['11111111111111'],
['22222222222222'],
['33333333333333'],
['44444444444444'],
['55555555555555'],
['66666666666666'],
['77777777777777'],
['88888888888888'],
['99999999999999'],
['12345678900123'],
['99299929384987'],
['84434895894444'],
['44242340000000'],
];
}