Ignore PHPStan errors about possibly impure method calls

This commit is contained in:
Ben Ramsey
2025-12-13 19:54:15 -06:00
parent ff16728c5c
commit 4618169496
+11 -6
View File
@@ -49,10 +49,11 @@ final class BrickMathCalculator implements CalculatorInterface
$sum = BigInteger::of($augend->toString());
foreach ($addends as $addend) {
/** @phpstan-ignore possiblyImpure.methodCall */
$sum = $sum->plus($addend->toString());
}
/** @phpstan-ignore possiblyImpure.new */
/** @phpstan-ignore possiblyImpure.new, possiblyImpure.methodCall */
return new IntegerObject((string) $sum);
}
@@ -61,10 +62,11 @@ final class BrickMathCalculator implements CalculatorInterface
$difference = BigInteger::of($minuend->toString());
foreach ($subtrahends as $subtrahend) {
/** @phpstan-ignore possiblyImpure.methodCall */
$difference = $difference->minus($subtrahend->toString());
}
/** @phpstan-ignore possiblyImpure.new */
/** @phpstan-ignore possiblyImpure.new, possiblyImpure.methodCall */
return new IntegerObject((string) $difference);
}
@@ -73,10 +75,11 @@ 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.new */
/** @phpstan-ignore possiblyImpure.new, possiblyImpure.methodCall */
return new IntegerObject((string) $product);
}
@@ -92,22 +95,23 @@ 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.new */
/** @phpstan-ignore possiblyImpure.new, possiblyImpure.methodCall, possiblyImpure.methodCall */
return new IntegerObject((string) $quotient->toBigInteger());
}
/** @phpstan-ignore possiblyImpure.new */
/** @phpstan-ignore possiblyImpure.new, possiblyImpure.methodCall */
return new Decimal((string) $quotient);
}
public function fromBase(string $value, int $base): IntegerObject
{
try {
/** @phpstan-ignore possiblyImpure.new */
/** @phpstan-ignore possiblyImpure.new, possiblyImpure.methodCall */
return new IntegerObject((string) BigInteger::fromBase($value, $base));
} catch (MathException | \InvalidArgumentException $exception) {
throw new InvalidArgumentException(
@@ -121,6 +125,7 @@ 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(