Skip to content

Commit

Permalink
chore: better validate if bcmath is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
krzaczek committed Dec 27, 2021
1 parent aff84d9 commit 73baac6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/Vies/Validator/ValidatorFR.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private function validateOld(string $vatNumber): string
return "";
}
$checkVal .= "12";
if (PHP_INT_SIZE === 4 && function_exists("bcmod")) {
if (PHP_INT_SIZE === 4 && extension_loaded('bcmath')) {
$checkVal = (int) bcmod($checkVal, "97");
} else {
$checkVal = intval($checkVal) % 97;
Expand All @@ -119,10 +119,10 @@ private function validateNew(string $vatNumber): bool
$checkCharacter = array_flip(str_split($this->alphabet));
$checkVal = ($checkCharacter[$vatNumber[0]] * $multiplier) + $checkCharacter[$vatNumber[1]] - $subStractor;

if (PHP_INT_SIZE === 4 && function_exists("bcmod")) {
if (PHP_INT_SIZE === 4 && extension_loaded("bcmath")) {
return (int) bcmod(bcadd(substr($vatNumber, 2), strval(($checkVal / 11) + 1)), "11") === $checkVal % 11;
} else {
return ((int)(intval(substr($vatNumber, 2)) + ($checkVal / 11) + 1) % 11) == $checkVal % 11;
return ((int) (intval(substr($vatNumber, 2)) + ($checkVal / 11) + 1) % 11) == $checkVal % 11;
}
}
}
2 changes: 1 addition & 1 deletion src/Vies/Validator/ValidatorNL.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected function validateSoleProprietor(string $vatNumber): bool
return $acc.$this->checkCharacter[$e];
}, '2321');

if (PHP_INT_SIZE === 4 && function_exists('bcmod')) {
if (PHP_INT_SIZE === 4 && extension_loaded('bcmath')) {
return bcmod($sumBase, '97') === '1';
} else {
return ((int) $sumBase % 97) === 1;
Expand Down
2 changes: 1 addition & 1 deletion src/Vies/Validator/ValidatorSK.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function validate(string $vatNumber): bool
return false;
}

if (PHP_INT_SIZE === 4 && function_exists('bcmod')) {
if (PHP_INT_SIZE === 4 && extension_loaded("bcmath")) {
return bcmod($vatNumber, '11') === '0';
} else {
return $vatNumber % 11 == 0;
Expand Down

0 comments on commit 73baac6

Please sign in to comment.