Skip to content

Commit 73baac6

Browse files
committed
chore: better validate if bcmath is loaded
1 parent aff84d9 commit 73baac6

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/Vies/Validator/ValidatorFR.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private function validateOld(string $vatNumber): string
9393
return "";
9494
}
9595
$checkVal .= "12";
96-
if (PHP_INT_SIZE === 4 && function_exists("bcmod")) {
96+
if (PHP_INT_SIZE === 4 && extension_loaded('bcmath')) {
9797
$checkVal = (int) bcmod($checkVal, "97");
9898
} else {
9999
$checkVal = intval($checkVal) % 97;
@@ -119,10 +119,10 @@ private function validateNew(string $vatNumber): bool
119119
$checkCharacter = array_flip(str_split($this->alphabet));
120120
$checkVal = ($checkCharacter[$vatNumber[0]] * $multiplier) + $checkCharacter[$vatNumber[1]] - $subStractor;
121121

122-
if (PHP_INT_SIZE === 4 && function_exists("bcmod")) {
122+
if (PHP_INT_SIZE === 4 && extension_loaded("bcmath")) {
123123
return (int) bcmod(bcadd(substr($vatNumber, 2), strval(($checkVal / 11) + 1)), "11") === $checkVal % 11;
124124
} else {
125-
return ((int)(intval(substr($vatNumber, 2)) + ($checkVal / 11) + 1) % 11) == $checkVal % 11;
125+
return ((int) (intval(substr($vatNumber, 2)) + ($checkVal / 11) + 1) % 11) == $checkVal % 11;
126126
}
127127
}
128128
}

src/Vies/Validator/ValidatorNL.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ protected function validateSoleProprietor(string $vatNumber): bool
130130
return $acc.$this->checkCharacter[$e];
131131
}, '2321');
132132

133-
if (PHP_INT_SIZE === 4 && function_exists('bcmod')) {
133+
if (PHP_INT_SIZE === 4 && extension_loaded('bcmath')) {
134134
return bcmod($sumBase, '97') === '1';
135135
} else {
136136
return ((int) $sumBase % 97) === 1;

src/Vies/Validator/ValidatorSK.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function validate(string $vatNumber): bool
4141
return false;
4242
}
4343

44-
if (PHP_INT_SIZE === 4 && function_exists('bcmod')) {
44+
if (PHP_INT_SIZE === 4 && extension_loaded("bcmath")) {
4545
return bcmod($vatNumber, '11') === '0';
4646
} else {
4747
return $vatNumber % 11 == 0;

0 commit comments

Comments
 (0)