diff --git a/phpstan.neon b/phpstan.neon index 2a03e49..2d588bc 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 1 + level: 6 treatPhpDocTypesAsCertain: false bootstrapFiles: - tests/bootstrap.php diff --git a/src/Validation/BrValidation.php b/src/Validation/BrValidation.php index 5bc0873..28ccd52 100644 --- a/src/Validation/BrValidation.php +++ b/src/Validation/BrValidation.php @@ -96,12 +96,12 @@ public static function cpf(string $check): bool $sum = 0; $position = $pos + 1; for ($i = 0; $i <= $pos - 1; $i++, $position--) { - $sum += (int)$check[$i] * $position; + $sum += (int)(int)$check[$i] * $position; } $div = $sum % 11; - $check[$pos] = $div < 2 ? 0 : 11 - $div; + (int)$check[$pos] = $div < 2 ? 0 : 11 - $div; } - $dvRight = (int)$check[9] * 10 + (int)$check[10]; + $dvRight = (int)(int)$check[9] * 10 + (int)(int)$check[10]; return $dvRight == $dv; } @@ -125,20 +125,20 @@ public static function cnpj(string $check): bool if (strlen($check) !== 14) { return false; } - $firstSum = ($check[0] * 5) + ($check[1] * 4) + ($check[2] * 3) + ($check[3] * 2) + - ($check[4] * 9) + ($check[5] * 8) + ($check[6] * 7) + ($check[7] * 6) + - ($check[8] * 5) + ($check[9] * 4) + ($check[10] * 3) + ($check[11] * 2); + $firstSum = ((int)$check[0] * 5) + ((int)$check[1] * 4) + ((int)$check[2] * 3) + ((int)$check[3] * 2) + + ((int)$check[4] * 9) + ((int)$check[5] * 8) + ((int)$check[6] * 7) + ((int)$check[7] * 6) + + ((int)$check[8] * 5) + ((int)$check[9] * 4) + ((int)$check[10] * 3) + ((int)$check[11] * 2); $firstVerificationDigit = $firstSum % 11 < 2 ? 0 : 11 - ($firstSum % 11); - $secondSum = ($check[0] * 6) + ($check[1] * 5) + ($check[2] * 4) + ($check[3] * 3) + - ($check[4] * 2) + ($check[5] * 9) + ($check[6] * 8) + ($check[7] * 7) + - ($check[8] * 6) + ($check[9] * 5) + ($check[10] * 4) + ($check[11] * 3) + - ($check[12] * 2); + $secondSum = ((int)$check[0] * 6) + ((int)$check[1] * 5) + ((int)$check[2] * 4) + ((int)$check[3] * 3) + + ((int)$check[4] * 2) + ((int)$check[5] * 9) + ((int)$check[6] * 8) + ((int)$check[7] * 7) + + ((int)$check[8] * 6) + ((int)$check[9] * 5) + ((int)$check[10] * 4) + ((int)$check[11] * 3) + + ((int)$check[12] * 2); $secondVerificationDigit = $secondSum % 11 < 2 ? 0 : 11 - ($secondSum % 11); - return ($check[12] == $firstVerificationDigit) && ($check[13] == $secondVerificationDigit); + return ((int)$check[12] == $firstVerificationDigit) && ((int)$check[13] == $secondVerificationDigit); } /** @@ -162,7 +162,7 @@ public static function cnh(string $cnh): bool } // Calculate the number for ($i = 0, $j = 9, $v = 0; $i < 9; ++$i, --$j) { - $v += $check[$i] * $j; + $v += (int)$check[$i] * $j; } $dsc = 0; @@ -174,7 +174,7 @@ public static function cnh(string $cnh): bool } for ($i = 0, $j = 1, $v = 0; $i < 9; ++$i, ++$j) { - $v += $check[$i] * $j; + $v += (int)$check[$i] * $j; } // Calculate second digit @@ -198,7 +198,7 @@ public static function cns(string $cns): bool $len = strlen($cns); $soma = 0; for ($i = 0; $i < $len; $i++) { - $soma += $cns[$i] * (15 - $i); + $soma += (int)$cns[$i] * (15 - $i); } return $soma % 11 === 0; diff --git a/src/Validation/EsValidation.php b/src/Validation/EsValidation.php index be7523a..015e2a0 100644 --- a/src/Validation/EsValidation.php +++ b/src/Validation/EsValidation.php @@ -131,14 +131,14 @@ public static function nif(string $check): bool return false; } - $sum = $check[2] + $check[4] + $check[6]; + $sum = (int)$check[2] + (int)$check[4] + (int)$check[6]; for ($i = 1; $i < 8; $i += 2) { - $tmp = (string)(2 * $check[$i]); - $sum += $tmp[0] + (strlen($tmp) === 2 ? $tmp[1] : 0); + $tmp = (string)(2 * (int)$check[$i]); + $sum += (int)$tmp[0] + (strlen($tmp) === 2 ? (int)$tmp[1] : 0); } - $num = 10 - substr(strval($sum), -1); + $num = 10 - (int)substr(strval($sum), -1); return $check[strlen($check) - 1] === chr($num + 64); } diff --git a/src/Validation/FiValidation.php b/src/Validation/FiValidation.php index c2f4f1e..49153bc 100644 --- a/src/Validation/FiValidation.php +++ b/src/Validation/FiValidation.php @@ -67,7 +67,7 @@ public static function phone(string $check): bool public static function personId(string $check): bool { $pattern = '/^\d{6}[-+A][0-9A-Z]{4}$/'; - if (!(bool)preg_match($pattern, strval($check))) { + if (!preg_match($pattern, $check)) { return false; } @@ -120,7 +120,7 @@ public static function businessId(string $check): bool $n = 0; foreach (str_split(substr($businessId, 0, 7)) as $k => $y) { - $n += $weights[$k] * $y; + $n += $weights[$k] * (int)$y; } $match = $n % 11 === 0 ? 0 : 11 - $n % 11; @@ -196,12 +196,12 @@ public static function calculateReferenceNumberChecksum(string $base): int $i = 0; } $multiplier = $pattern[$i]; - $result += $multiplier * $node; + $result += $multiplier * (int)$node; $i++; } $lastItems = str_split(strval($result), 1); - $checksum = 10 - end($lastItems); + $checksum = 10 - (int)end($lastItems); if ($checksum >= 10) { $checksum = 0; diff --git a/src/Validation/FrValidation.php b/src/Validation/FrValidation.php index 941fa06..464b9fc 100644 --- a/src/Validation/FrValidation.php +++ b/src/Validation/FrValidation.php @@ -81,13 +81,13 @@ public static function personId(string $check): bool // source : https://xml.insee.fr/schema/nir.html // check : https://www.parodie.com/monetique/nir.htm if ($numberWithoutKey[6] === 'A') { - $numberWithoutKey = str_replace('A', '0', $numberWithoutKey); + $numberWithoutKey = (int)str_replace('A', '0', $numberWithoutKey); $numberWithoutKey -= 1000000; } elseif ($numberWithoutKey[6] === 'B') { - $numberWithoutKey = str_replace('B', '0', $numberWithoutKey); + $numberWithoutKey = (int)str_replace('B', '0', $numberWithoutKey); $numberWithoutKey -= 2000000; } - return $key == 97 - ($numberWithoutKey - (floor($numberWithoutKey / 97) * 97)); + return $key === (string)(97 - ((int)$numberWithoutKey - (int)(floor((int)$numberWithoutKey / 97) * 97))); } } diff --git a/src/Validation/IrValidation.php b/src/Validation/IrValidation.php index 6771185..f79409d 100644 --- a/src/Validation/IrValidation.php +++ b/src/Validation/IrValidation.php @@ -122,7 +122,7 @@ public static function personId(string $check): bool $sum = 0; $equivalent = 0; for ($i = 0; $i < 9; $i++) { - $sum += substr($check, $i, 1) * (10 - $i); + $sum += (int)substr($check, $i, 1) * (10 - $i); if (substr($check, 1, 1) === substr($check, $i, 1)) { $equivalent++; } diff --git a/src/Validation/LvValidation.php b/src/Validation/LvValidation.php index ccee3ff..af92716 100644 --- a/src/Validation/LvValidation.php +++ b/src/Validation/LvValidation.php @@ -83,10 +83,6 @@ public static function personId(string $check): bool $counter += (int)$check[$index] * $multiplier; } - if ($counter === false) { - return false; - } - return (1101 - $counter) % 11 === (int)$check[10]; } } diff --git a/src/Validation/PlValidation.php b/src/Validation/PlValidation.php index 1903f29..021e45f 100644 --- a/src/Validation/PlValidation.php +++ b/src/Validation/PlValidation.php @@ -74,7 +74,7 @@ public static function nip(string $check): bool $weights = [6, 5, 7, 2, 3, 4, 5, 6, 7]; $check = str_replace('-', '', $check); for ($i = 0; $i < 9; $i++) { - $sum += $check[$i] * $weights[$i]; + $sum += (int)$check[$i] * $weights[$i]; } $control = $sum % 11; if ($control === 10) { @@ -99,7 +99,7 @@ public static function pesel(string $check): bool $sum = 0; $weights = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3]; for ($i = 0; $i < 10; $i++) { - $sum += $check[$i] * $weights[$i]; + $sum += (int)$check[$i] * $weights[$i]; } $control = 10 - $sum % 10; if ($control === 10) { @@ -133,7 +133,7 @@ public static function regon(string $check): bool if (strlen($check) === 9) { // Validate short version (9 digits) $sum = array_sum(array_map(function ($weight, $digit) { - return $weight * $digit; + return $weight * (int)$digit; }, [8, 9, 2, 3, 4, 5, 6, 7], array_slice($chars, 0, 8))); $checksum = $sum % 11; @@ -141,7 +141,7 @@ public static function regon(string $check): bool } else { // Validate long version (14 digits) $sum = array_sum(array_map(function ($weight, $digit) { - return $weight * $digit; + return $weight * (int)$digit; }, [2, 4, 8, 5, 0, 9, 7, 3, 6, 1, 2, 4, 8], array_slice($chars, 0, 13))); $checksum = $sum % 11; diff --git a/src/Validation/RsValidation.php b/src/Validation/RsValidation.php index b244f5a..f635c6c 100644 --- a/src/Validation/RsValidation.php +++ b/src/Validation/RsValidation.php @@ -59,7 +59,8 @@ public static function personId(string $check): bool } [$a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k, $l, $m] = str_split(strval($check)); - $checksum = 11 - ( 7 * ($a + $g) + 6 * ($b + $h) + 5 * ($c + $i) + 4 * ($d + $j) + 3 * ($e + $k) + 2 * ($f + $l) ) % 11; + $checksum = 11 - ( 7 * ((int)$a + (int)$g) + 6 * ((int)$b + (int)$h) + + 5 * ((int)$c + (int)$i) + 4 * ((int)$d + (int)$j) + 3 * ((int)$e + (int)$k) + 2 * ((int)$f + (int)$l) ) % 11; return $checksum == $m; } diff --git a/src/Validation/RuValidation.php b/src/Validation/RuValidation.php index 5a7d60a..54b2724 100644 --- a/src/Validation/RuValidation.php +++ b/src/Validation/RuValidation.php @@ -106,7 +106,7 @@ public static function vatin(string $check): bool $checksum = array_pop($digits); $tbNum = [2, 4, 10, 3, 5, 9, 4, 6, 8]; $calculatedChecksum = array_sum(array_map(function ($value, $multiplier) { - return $value * $multiplier; + return $value * (int)$multiplier; }, $tbNum, $digits)) % 11 % 10; } else { // human person @@ -121,7 +121,7 @@ public static function vatin(string $check): bool $sum = [0, 0]; foreach ($tbNum as $key => $multipliers) { $sum[$key] = array_sum(array_map(function ($value, $multiplier) { - return $value * $multiplier; + return $value * (int)$multiplier; }, $multipliers, $digits)) % 11 % 10; } @@ -164,7 +164,7 @@ public static function snils(string $check): bool $sum = 0; foreach ($digits as $position => $value) { - $sum += ($position + 1) * $value; + $sum += ($position + 1) * (int)$value; } $calculatedChecksum = $sum % 101; diff --git a/src/Validation/TrValidation.php b/src/Validation/TrValidation.php index 140694b..24fa5a6 100644 --- a/src/Validation/TrValidation.php +++ b/src/Validation/TrValidation.php @@ -57,18 +57,19 @@ public static function personId(string $tckn): bool return false; } - if ($tckn[0] === 0) { + + if ((int)$tckn[0] === 0) { return false; } - $even = $tckn[0] + $tckn[2] + $tckn[4] + $tckn[6] + $tckn[8]; - $odd = $tckn[1] + $tckn[3] + $tckn[5] + $tckn[7]; + $even = (int)$tckn[0] + (int)$tckn[2] + (int)$tckn[4] + (int)$tckn[6] + (int)$tckn[8]; + $odd = (int)$tckn[1] + (int)$tckn[3] + (int)$tckn[5] + (int)$tckn[7]; $check = ($even * 7) - $odd; if ($check % 10 !== (int)$tckn[9]) { return false; } - $check = $even + $odd + $tckn[9]; + $check = $even + $odd + (int)$tckn[9]; if ($check % 10 !== (int)$tckn[10]) { return false; } diff --git a/src/Validation/TwValidation.php b/src/Validation/TwValidation.php index 37de0fb..e22c61a 100644 --- a/src/Validation/TwValidation.php +++ b/src/Validation/TwValidation.php @@ -78,7 +78,7 @@ public static function personId(string $check): bool $checksum = (int)($n1 / 10) + ($n1 % 10) * 9; for ($i = 1; $i < 9; $i++) { - $checksum += $check[$i] * (9 - $i); + $checksum += (int)$check[$i] * (9 - $i); } return substr(strval(10 - ($checksum % 10)), 0, 1) === $check[9]; @@ -99,12 +99,12 @@ public static function ubn(string $check): bool $tbNum = [1, 2, 1, 2, 1, 2, 4, 1]; $intSum = 0; for ($i = 0; $i < 8; $i++) { - $intMultiply = $check[$i] * $tbNum[$i]; + $intMultiply = (int)$check[$i] * $tbNum[$i]; $intAddition = floor($intMultiply / 10) + ($intMultiply % 10); $intSum += $intAddition; } - return ($intSum % 10 === 0) || ($intSum % 10 === 9 && $check[6] === 7); + return ($intSum % 10 === 0) || ($intSum % 10 === 9 && (int)$check[6] === 7); } /**