Add support for brick/math 0.14 (#617)

This commit is contained in:
Christophe Coevoet
2025-09-04 22:51:02 +02:00
committed by GitHub
parent 101bb3a166
commit 592a97d70f
2 changed files with 9 additions and 12 deletions
+1 -1
View File
@@ -10,7 +10,7 @@
],
"require": {
"php": "^8.0",
"brick/math": "^0.8.8 || ^0.9 || ^0.10 || ^0.11 || ^0.12 || ^0.13",
"brick/math": "^0.8.8 || ^0.9 || ^0.10 || ^0.11 || ^0.12 || ^0.13 || ^0.14",
"ramsey/collection": "^1.2 || ^2.0"
},
"require-dev": {
+8 -11
View File
@@ -49,10 +49,10 @@ final class BrickMathCalculator implements CalculatorInterface
$sum = BigInteger::of($augend->toString());
foreach ($addends as $addend) {
$sum = $sum->plus($addend->toString()); /** @phpstan-ignore possiblyImpure.methodCall */
$sum = $sum->plus($addend->toString());
}
/** @phpstan-ignore possiblyImpure.methodCall, possiblyImpure.new */
/** @phpstan-ignore possiblyImpure.new */
return new IntegerObject((string) $sum);
}
@@ -61,10 +61,10 @@ final class BrickMathCalculator implements CalculatorInterface
$difference = BigInteger::of($minuend->toString());
foreach ($subtrahends as $subtrahend) {
$difference = $difference->minus($subtrahend->toString()); /** @phpstan-ignore possiblyImpure.methodCall */
$difference = $difference->minus($subtrahend->toString());
}
/** @phpstan-ignore possiblyImpure.methodCall, possiblyImpure.new */
/** @phpstan-ignore possiblyImpure.new */
return new IntegerObject((string) $difference);
}
@@ -73,11 +73,10 @@ final class BrickMathCalculator implements CalculatorInterface
$product = BigInteger::of($multiplicand->toString());
foreach ($multipliers as $multiplier) {
/** @phpstan-ignore possiblyImpure.methodCall */
$product = $product->multipliedBy($multiplier->toString());
}
/** @phpstan-ignore possiblyImpure.methodCall, possiblyImpure.new */
/** @phpstan-ignore possiblyImpure.new */
return new IntegerObject((string) $product);
}
@@ -93,23 +92,22 @@ final class BrickMathCalculator implements CalculatorInterface
$quotient = BigDecimal::of($dividend->toString());
foreach ($divisors as $divisor) {
/** @phpstan-ignore possiblyImpure.methodCall */
$quotient = $quotient->dividedBy($divisor->toString(), $scale, $brickRounding);
}
if ($scale === 0) {
/** @phpstan-ignore possiblyImpure.methodCall, possiblyImpure.methodCall, possiblyImpure.new */
/** @phpstan-ignore possiblyImpure.new */
return new IntegerObject((string) $quotient->toBigInteger());
}
/** @phpstan-ignore possiblyImpure.methodCall, possiblyImpure.new */
/** @phpstan-ignore possiblyImpure.new */
return new Decimal((string) $quotient);
}
public function fromBase(string $value, int $base): IntegerObject
{
try {
/** @phpstan-ignore possiblyImpure.methodCall, possiblyImpure.new */
/** @phpstan-ignore possiblyImpure.new */
return new IntegerObject((string) BigInteger::fromBase($value, $base));
} catch (MathException | \InvalidArgumentException $exception) {
throw new InvalidArgumentException(
@@ -123,7 +121,6 @@ final class BrickMathCalculator implements CalculatorInterface
public function toBase(IntegerObject $value, int $base): string
{
try {
/** @phpstan-ignore possiblyImpure.methodCall */
return BigInteger::of($value->toString())->toBase($base);
} catch (MathException | \InvalidArgumentException $exception) {
throw new InvalidArgumentException(