Skip to content

Commit

Permalink
Fix up phpstan level 6
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Nov 27, 2023
1 parent a336a54 commit 7b8f7b0
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 46 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 1
level: 6
treatPhpDocTypesAsCertain: false
bootstrapFiles:
- tests/bootstrap.php
Expand Down
28 changes: 14 additions & 14 deletions src/Validation/BrValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}

/**
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/Validation/EsValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Validation/FiValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/Validation/FrValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}
2 changes: 1 addition & 1 deletion src/Validation/IrValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down
4 changes: 0 additions & 4 deletions src/Validation/LvValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
8 changes: 4 additions & 4 deletions src/Validation/PlValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -133,15 +133,15 @@ 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;

return $checksum % 10 == $chars[8];
} 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;

Expand Down
3 changes: 2 additions & 1 deletion src/Validation/RsValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Validation/RuValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions src/Validation/TrValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,19 @@ public static function personId(string $tckn): bool
return false;
}

if ($tckn[0] === 0) {

Check failure on line 60 in src/Validation/TrValidation.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Found more than a single empty line between content
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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Validation/TwValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 7b8f7b0

Please sign in to comment.