Add support for PHP 7.4 version

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
Henrique Moody 2020-04-04 22:13:44 +02:00
parent 9a868f6e5f
commit b9e73db494
No known key found for this signature in database
GPG key ID: 221E9281655813A6
3 changed files with 11 additions and 4 deletions

View file

@ -5,6 +5,7 @@ php:
- 7.1
- 7.2
- 7.3
- 7.4
- nightly
cache:

View file

@ -56,7 +56,7 @@ final class Cnh extends AbstractRule
}
$dv2 = $s2 % 11 - ($dv1 > 9 ? 2 : 0);
$check = $dv2 < 0 ? $dv2 + 11 : $dv2 > 9 ? 0 : $dv2;
$check = $dv2 < 0 ? $dv2 + 11 : ($dv2 > 9 ? 0 : $dv2);
return $input[10] == $check;
}

View file

@ -13,6 +13,7 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use function is_scalar;
use function preg_match;
/**
@ -29,17 +30,22 @@ final class Pesel extends AbstractRule
*/
public function validate($input): bool
{
if (!preg_match('/^\d{11}$/', (string) $input)) {
if (!is_scalar($input)) {
return false;
}
$stringInput = (string) $input;
if (!preg_match('/^\d{11}$/', (string) $stringInput)) {
return false;
}
$weights = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3];
$targetControlNumber = $input[10];
$targetControlNumber = $stringInput[10];
$calculateControlNumber = 0;
for ($i = 0; $i < 10; ++$i) {
$calculateControlNumber += $input[$i] * $weights[$i];
$calculateControlNumber += $stringInput[$i] * $weights[$i];
}
$calculateControlNumber = (10 - $calculateControlNumber % 10) % 10;