mirror of
https://github.com/Respect/Validation.git
synced 2024-06-01 21:32:14 +02:00
Add support for PHP 7.4 version
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
9a868f6e5f
commit
b9e73db494
|
@ -5,6 +5,7 @@ php:
|
|||
- 7.1
|
||||
- 7.2
|
||||
- 7.3
|
||||
- 7.4
|
||||
- nightly
|
||||
|
||||
cache:
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue