[pkg-nagios-changes] [Git][nagios-team/icinga-php-library][master] 4 commits: New upstream version 0.18.1
Bas Couwenberg (@sebastic)
gitlab at salsa.debian.org
Thu Nov 27 16:39:21 GMT 2025
Bas Couwenberg pushed to branch master at Debian Nagios Maintainer Group / icinga-php-library
Commits:
e28627ab by Bas Couwenberg at 2025-11-27T17:35:40+01:00
New upstream version 0.18.1
- - - - -
cf4eecd5 by Bas Couwenberg at 2025-11-27T17:35:51+01:00
Update upstream source from tag 'upstream/0.18.1'
Update to upstream version '0.18.1'
with Debian dir 12b2ef4eca571d3ab47321ac03465f7c4d761a62
- - - - -
97b76a30 by Bas Couwenberg at 2025-11-27T17:36:02+01:00
New upstream release.
- - - - -
b4fb234f by Bas Couwenberg at 2025-11-27T17:37:08+01:00
Set distribution to unstable.
- - - - -
22 changed files:
- VERSION
- composer.lock
- debian/changelog
- vendor/brick/math/src/BigDecimal.php
- vendor/brick/math/src/BigInteger.php
- vendor/brick/math/src/BigNumber.php
- vendor/brick/math/src/BigRational.php
- vendor/brick/math/src/Exception/DivisionByZeroException.php
- vendor/brick/math/src/Exception/IntegerOverflowException.php
- vendor/brick/math/src/Exception/MathException.php
- vendor/brick/math/src/Exception/NumberFormatException.php
- vendor/brick/math/src/Exception/RoundingNecessaryException.php
- vendor/brick/math/src/Internal/Calculator.php
- vendor/brick/math/src/Internal/Calculator/BcMathCalculator.php
- vendor/brick/math/src/Internal/Calculator/GmpCalculator.php
- vendor/brick/math/src/Internal/Calculator/NativeCalculator.php
- vendor/brick/math/src/Internal/CalculatorRegistry.php
- + vendor/brick/math/tools/ecs/composer.json
- + vendor/brick/math/tools/ecs/ecs.php
- vendor/composer/installed.json
- vendor/composer/installed.php
- vendor/ipl/html/src/FormElement/BaseFormElement.php
Changes:
=====================================
VERSION
=====================================
@@ -1 +1 @@
-v0.18.0
+v0.18.1
=====================================
composer.lock
=====================================
@@ -8,16 +8,16 @@
"packages": [
{
"name": "brick/math",
- "version": "0.14.0",
+ "version": "0.14.1",
"source": {
"type": "git",
"url": "https://github.com/brick/math.git",
- "reference": "113a8ee2656b882d4c3164fa31aa6e12cbb7aaa2"
+ "reference": "f05858549e5f9d7bb45875a75583240a38a281d0"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/brick/math/zipball/113a8ee2656b882d4c3164fa31aa6e12cbb7aaa2",
- "reference": "113a8ee2656b882d4c3164fa31aa6e12cbb7aaa2",
+ "url": "https://api.github.com/repos/brick/math/zipball/f05858549e5f9d7bb45875a75583240a38a281d0",
+ "reference": "f05858549e5f9d7bb45875a75583240a38a281d0",
"shasum": ""
},
"require": {
@@ -56,7 +56,7 @@
],
"support": {
"issues": "https://github.com/brick/math/issues",
- "source": "https://github.com/brick/math/tree/0.14.0"
+ "source": "https://github.com/brick/math/tree/0.14.1"
},
"funding": [
{
@@ -64,7 +64,7 @@
"type": "github"
}
],
- "time": "2025-08-29T12:40:03+00:00"
+ "time": "2025-11-24T14:40:29+00:00"
},
{
"name": "doctrine/collections",
@@ -474,16 +474,16 @@
},
{
"name": "ipl/html",
- "version": "v0.9.0",
+ "version": "v0.9.1",
"source": {
"type": "git",
"url": "https://github.com/Icinga/ipl-html.git",
- "reference": "4ab3fb11794434d455b9db5b6c81901df34e10cf"
+ "reference": "a0cbfa405f9be9650141fd5eee894e423e3e4999"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/Icinga/ipl-html/zipball/4ab3fb11794434d455b9db5b6c81901df34e10cf",
- "reference": "4ab3fb11794434d455b9db5b6c81901df34e10cf",
+ "url": "https://api.github.com/repos/Icinga/ipl-html/zipball/a0cbfa405f9be9650141fd5eee894e423e3e4999",
+ "reference": "a0cbfa405f9be9650141fd5eee894e423e3e4999",
"shasum": ""
},
"require": {
@@ -516,9 +516,9 @@
],
"support": {
"issues": "https://github.com/Icinga/ipl-html/issues",
- "source": "https://github.com/Icinga/ipl-html/tree/v0.9.0"
+ "source": "https://github.com/Icinga/ipl-html/tree/v0.9.1"
},
- "time": "2025-11-13T15:18:42+00:00"
+ "time": "2025-11-27T15:07:15+00:00"
},
{
"name": "ipl/i18n",
=====================================
debian/changelog
=====================================
@@ -1,3 +1,9 @@
+icinga-php-library (0.18.1-1) unstable; urgency=medium
+
+ * New upstream release.
+
+ -- Bas Couwenberg <sebastic at debian.org> Thu, 27 Nov 2025 17:36:52 +0100
+
icinga-php-library (0.18.0-1) unstable; urgency=medium
* New upstream release.
=====================================
vendor/brick/math/src/BigDecimal.php
=====================================
@@ -9,8 +9,19 @@ use Brick\Math\Exception\MathException;
use Brick\Math\Exception\NegativeNumberException;
use Brick\Math\Internal\Calculator;
use Brick\Math\Internal\CalculatorRegistry;
+use InvalidArgumentException;
+use LogicException;
use Override;
+use function rtrim;
+use function sprintf;
+use function str_pad;
+use function str_repeat;
+use function strlen;
+use function substr;
+
+use const STR_PAD_LEFT;
+
/**
* Immutable, arbitrary-precision signed decimal numbers.
*/
@@ -46,12 +57,6 @@ final readonly class BigDecimal extends BigNumber
$this->scale = $scale;
}
- #[Override]
- protected static function from(BigNumber $number): static
- {
- return $number->toBigDecimal();
- }
-
/**
* Creates a BigDecimal from an unscaled value and a scale.
*
@@ -63,13 +68,13 @@ final readonly class BigDecimal extends BigNumber
*
* @pure
*/
- public static function ofUnscaledValue(BigNumber|int|float|string $value, int $scale = 0) : BigDecimal
+ public static function ofUnscaledValue(BigNumber|int|float|string $value, int $scale = 0): BigDecimal
{
$value = (string) BigInteger::of($value);
if ($scale < 0) {
if ($value !== '0') {
- $value .= \str_repeat('0', -$scale);
+ $value .= str_repeat('0', -$scale);
}
$scale = 0;
}
@@ -82,7 +87,7 @@ final readonly class BigDecimal extends BigNumber
*
* @pure
*/
- public static function zero() : BigDecimal
+ public static function zero(): BigDecimal
{
/** @var BigDecimal|null $zero */
static $zero;
@@ -99,7 +104,7 @@ final readonly class BigDecimal extends BigNumber
*
* @pure
*/
- public static function one() : BigDecimal
+ public static function one(): BigDecimal
{
/** @var BigDecimal|null $one */
static $one;
@@ -116,7 +121,7 @@ final readonly class BigDecimal extends BigNumber
*
* @pure
*/
- public static function ten() : BigDecimal
+ public static function ten(): BigDecimal
{
/** @var BigDecimal|null $ten */
static $ten;
@@ -139,7 +144,7 @@ final readonly class BigDecimal extends BigNumber
*
* @pure
*/
- public function plus(BigNumber|int|float|string $that) : BigDecimal
+ public function plus(BigNumber|int|float|string $that): BigDecimal
{
$that = BigDecimal::of($that);
@@ -170,7 +175,7 @@ final readonly class BigDecimal extends BigNumber
*
* @pure
*/
- public function minus(BigNumber|int|float|string $that) : BigDecimal
+ public function minus(BigNumber|int|float|string $that): BigDecimal
{
$that = BigDecimal::of($that);
@@ -197,7 +202,7 @@ final readonly class BigDecimal extends BigNumber
*
* @pure
*/
- public function multipliedBy(BigNumber|int|float|string $that) : BigDecimal
+ public function multipliedBy(BigNumber|int|float|string $that): BigDecimal
{
$that = BigDecimal::of($that);
@@ -222,12 +227,12 @@ final readonly class BigDecimal extends BigNumber
* @param int|null $scale The desired scale, or null to use the scale of this number.
* @param RoundingMode $roundingMode An optional rounding mode, defaults to UNNECESSARY.
*
- * @throws \InvalidArgumentException If the scale or rounding mode is invalid.
- * @throws MathException If the number is invalid, is zero, or rounding was necessary.
+ * @throws InvalidArgumentException If the scale or rounding mode is invalid.
+ * @throws MathException If the number is invalid, is zero, or rounding was necessary.
*
* @pure
*/
- public function dividedBy(BigNumber|int|float|string $that, ?int $scale = null, RoundingMode $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal
+ public function dividedBy(BigNumber|int|float|string $that, ?int $scale = null, RoundingMode $roundingMode = RoundingMode::UNNECESSARY): BigDecimal
{
$that = BigDecimal::of($that);
@@ -238,7 +243,7 @@ final readonly class BigDecimal extends BigNumber
if ($scale === null) {
$scale = $this->scale;
} elseif ($scale < 0) {
- throw new \InvalidArgumentException('Scale cannot be negative.');
+ throw new InvalidArgumentException('Scale cannot be negative.');
}
if ($that->value === '1' && $that->scale === 0 && $scale === $this->scale) {
@@ -265,7 +270,7 @@ final readonly class BigDecimal extends BigNumber
*
* @pure
*/
- public function exactlyDividedBy(BigNumber|int|float|string $that) : BigDecimal
+ public function exactlyDividedBy(BigNumber|int|float|string $that): BigDecimal
{
$that = BigDecimal::of($that);
@@ -275,13 +280,13 @@ final readonly class BigDecimal extends BigNumber
[, $b] = $this->scaleValues($this, $that);
- $d = \rtrim($b, '0');
- $scale = \strlen($b) - \strlen($d);
+ $d = rtrim($b, '0');
+ $scale = strlen($b) - strlen($d);
$calculator = CalculatorRegistry::get();
foreach ([5, 2] as $prime) {
- for (;;) {
+ for (; ;) {
$lastDigit = (int) $d[-1];
if ($lastDigit % $prime !== 0) {
@@ -308,13 +313,14 @@ final readonly class BigDecimal extends BigNumber
*
* @throws MathException If min/max are not convertible to a BigDecimal.
*/
- public function clamp(BigNumber|int|float|string $min, BigNumber|int|float|string $max) : BigDecimal
+ public function clamp(BigNumber|int|float|string $min, BigNumber|int|float|string $max): BigDecimal
{
if ($this->isLessThan($min)) {
return BigDecimal::of($min);
} elseif ($this->isGreaterThan($max)) {
return BigDecimal::of($max);
}
+
return $this;
}
@@ -323,11 +329,11 @@ final readonly class BigDecimal extends BigNumber
*
* The result has a scale of `$this->scale * $exponent`.
*
- * @throws \InvalidArgumentException If the exponent is not in the range 0 to 1,000,000.
+ * @throws InvalidArgumentException If the exponent is not in the range 0 to 1,000,000.
*
* @pure
*/
- public function power(int $exponent) : BigDecimal
+ public function power(int $exponent): BigDecimal
{
if ($exponent === 0) {
return BigDecimal::one();
@@ -338,10 +344,10 @@ final readonly class BigDecimal extends BigNumber
}
if ($exponent < 0 || $exponent > Calculator::MAX_POWER) {
- throw new \InvalidArgumentException(\sprintf(
+ throw new InvalidArgumentException(sprintf(
'The exponent %d is not in the range 0 to %d.',
$exponent,
- Calculator::MAX_POWER
+ Calculator::MAX_POWER,
));
}
@@ -359,7 +365,7 @@ final readonly class BigDecimal extends BigNumber
*
* @pure
*/
- public function quotient(BigNumber|int|float|string $that) : BigDecimal
+ public function quotient(BigNumber|int|float|string $that): BigDecimal
{
$that = BigDecimal::of($that);
@@ -386,7 +392,7 @@ final readonly class BigDecimal extends BigNumber
*
* @pure
*/
- public function remainder(BigNumber|int|float|string $that) : BigDecimal
+ public function remainder(BigNumber|int|float|string $that): BigDecimal
{
$that = BigDecimal::of($that);
@@ -417,7 +423,7 @@ final readonly class BigDecimal extends BigNumber
*
* @pure
*/
- public function quotientAndRemainder(BigNumber|int|float|string $that) : array
+ public function quotientAndRemainder(BigNumber|int|float|string $that): array
{
$that = BigDecimal::of($that);
@@ -441,15 +447,15 @@ final readonly class BigDecimal extends BigNumber
/**
* Returns the square root of this number, rounded down to the given number of decimals.
*
- * @throws \InvalidArgumentException If the scale is negative.
- * @throws NegativeNumberException If this number is negative.
+ * @throws InvalidArgumentException If the scale is negative.
+ * @throws NegativeNumberException If this number is negative.
*
* @pure
*/
- public function sqrt(int $scale) : BigDecimal
+ public function sqrt(int $scale): BigDecimal
{
if ($scale < 0) {
- throw new \InvalidArgumentException('Scale cannot be negative.');
+ throw new InvalidArgumentException('Scale cannot be negative.');
}
if ($this->value === '0') {
@@ -465,15 +471,15 @@ final readonly class BigDecimal extends BigNumber
if ($addDigits > 0) {
// add zeros
- $value .= \str_repeat('0', $addDigits);
+ $value .= str_repeat('0', $addDigits);
} elseif ($addDigits < 0) {
// trim digits
- if (-$addDigits >= \strlen($this->value)) {
+ if (-$addDigits >= strlen($this->value)) {
// requesting a scale too low, will always yield a zero result
return new BigDecimal('0', $scale);
}
- $value = \substr($value, 0, $addDigits);
+ $value = substr($value, 0, $addDigits);
}
$value = CalculatorRegistry::get()->sqrt($value);
@@ -486,7 +492,7 @@ final readonly class BigDecimal extends BigNumber
*
* @pure
*/
- public function withPointMovedLeft(int $n) : BigDecimal
+ public function withPointMovedLeft(int $n): BigDecimal
{
if ($n === 0) {
return $this;
@@ -504,7 +510,7 @@ final readonly class BigDecimal extends BigNumber
*
* @pure
*/
- public function withPointMovedRight(int $n) : BigDecimal
+ public function withPointMovedRight(int $n): BigDecimal
{
if ($n === 0) {
return $this;
@@ -519,7 +525,7 @@ final readonly class BigDecimal extends BigNumber
if ($scale < 0) {
if ($value !== '0') {
- $value .= \str_repeat('0', -$scale);
+ $value .= str_repeat('0', -$scale);
}
$scale = 0;
}
@@ -532,19 +538,19 @@ final readonly class BigDecimal extends BigNumber
*
* @pure
*/
- public function stripTrailingZeros() : BigDecimal
+ public function stripTrailingZeros(): BigDecimal
{
if ($this->scale === 0) {
return $this;
}
- $trimmedValue = \rtrim($this->value, '0');
+ $trimmedValue = rtrim($this->value, '0');
if ($trimmedValue === '') {
return BigDecimal::zero();
}
- $trimmableZeros = \strlen($this->value) - \strlen($trimmedValue);
+ $trimmableZeros = strlen($this->value) - strlen($trimmedValue);
if ($trimmableZeros === 0) {
return $this;
@@ -554,7 +560,7 @@ final readonly class BigDecimal extends BigNumber
$trimmableZeros = $this->scale;
}
- $value = \substr($this->value, 0, -$trimmableZeros);
+ $value = substr($this->value, 0, -$trimmableZeros);
$scale = $this->scale - $trimmableZeros;
return new BigDecimal($value, $scale);
@@ -565,7 +571,7 @@ final readonly class BigDecimal extends BigNumber
*
* @pure
*/
- public function abs() : BigDecimal
+ public function abs(): BigDecimal
{
return $this->isNegative() ? $this->negated() : $this;
}
@@ -575,13 +581,13 @@ final readonly class BigDecimal extends BigNumber
*
* @pure
*/
- public function negated() : BigDecimal
+ public function negated(): BigDecimal
{
return new BigDecimal(CalculatorRegistry::get()->neg($this->value), $this->scale);
}
#[Override]
- public function compareTo(BigNumber|int|float|string $that) : int
+ public function compareTo(BigNumber|int|float|string $that): int
{
$that = BigNumber::of($that);
@@ -595,11 +601,11 @@ final readonly class BigDecimal extends BigNumber
return CalculatorRegistry::get()->cmp($a, $b);
}
- return - $that->compareTo($this);
+ return -$that->compareTo($this);
}
#[Override]
- public function getSign() : int
+ public function getSign(): int
{
return ($this->value === '0') ? 0 : (($this->value[0] === '-') ? -1 : 1);
}
@@ -607,7 +613,7 @@ final readonly class BigDecimal extends BigNumber
/**
* @pure
*/
- public function getUnscaledValue() : BigInteger
+ public function getUnscaledValue(): BigInteger
{
return self::newBigInteger($this->value);
}
@@ -615,7 +621,7 @@ final readonly class BigDecimal extends BigNumber
/**
* @pure
*/
- public function getScale() : int
+ public function getScale(): int
{
return $this->scale;
}
@@ -644,7 +650,7 @@ final readonly class BigDecimal extends BigNumber
return 0;
}
- $length = \strlen($value);
+ $length = strlen($value);
return ($value[0] === '-') ? $length - 1 : $length;
}
@@ -656,7 +662,7 @@ final readonly class BigDecimal extends BigNumber
*
* @pure
*/
- public function getIntegralPart() : string
+ public function getIntegralPart(): string
{
if ($this->scale === 0) {
return $this->value;
@@ -664,7 +670,7 @@ final readonly class BigDecimal extends BigNumber
$value = $this->getUnscaledValueWithLeadingZeros();
- return \substr($value, 0, -$this->scale);
+ return substr($value, 0, -$this->scale);
}
/**
@@ -676,7 +682,7 @@ final readonly class BigDecimal extends BigNumber
*
* @pure
*/
- public function getFractionalPart() : string
+ public function getFractionalPart(): string
{
if ($this->scale === 0) {
return '';
@@ -684,7 +690,7 @@ final readonly class BigDecimal extends BigNumber
$value = $this->getUnscaledValueWithLeadingZeros();
- return \substr($value, -$this->scale);
+ return substr($value, -$this->scale);
}
/**
@@ -692,13 +698,13 @@ final readonly class BigDecimal extends BigNumber
*
* @pure
*/
- public function hasNonZeroFractionalPart() : bool
+ public function hasNonZeroFractionalPart(): bool
{
- return $this->getFractionalPart() !== \str_repeat('0', $this->scale);
+ return $this->getFractionalPart() !== str_repeat('0', $this->scale);
}
#[Override]
- public function toBigInteger() : BigInteger
+ public function toBigInteger(): BigInteger
{
$zeroScaleDecimal = $this->scale === 0 ? $this : $this->dividedBy(1, 0);
@@ -706,22 +712,22 @@ final readonly class BigDecimal extends BigNumber
}
#[Override]
- public function toBigDecimal() : BigDecimal
+ public function toBigDecimal(): BigDecimal
{
return $this;
}
#[Override]
- public function toBigRational() : BigRational
+ public function toBigRational(): BigRational
{
$numerator = self::newBigInteger($this->value);
- $denominator = self::newBigInteger('1' . \str_repeat('0', $this->scale));
+ $denominator = self::newBigInteger('1' . str_repeat('0', $this->scale));
return self::newBigRational($numerator, $denominator, false);
}
#[Override]
- public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal
+ public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::UNNECESSARY): BigDecimal
{
if ($scale === $this->scale) {
return $this;
@@ -731,13 +737,13 @@ final readonly class BigDecimal extends BigNumber
}
#[Override]
- public function toInt() : int
+ public function toInt(): int
{
return $this->toBigInteger()->toInt();
}
#[Override]
- public function toFloat() : float
+ public function toFloat(): float
{
return (float) (string) $this;
}
@@ -746,7 +752,7 @@ final readonly class BigDecimal extends BigNumber
* @return numeric-string
*/
#[Override]
- public function __toString() : string
+ public function __toString(): string
{
if ($this->scale === 0) {
/** @var numeric-string */
@@ -756,7 +762,7 @@ final readonly class BigDecimal extends BigNumber
$value = $this->getUnscaledValueWithLeadingZeros();
/** @phpstan-ignore return.type */
- return \substr($value, 0, -$this->scale) . '.' . \substr($value, -$this->scale);
+ return substr($value, 0, -$this->scale) . '.' . substr($value, -$this->scale);
}
/**
@@ -778,13 +784,13 @@ final readonly class BigDecimal extends BigNumber
*
* @param array{value: string, scale: int} $data
*
- * @throws \LogicException
+ * @throws LogicException
*/
public function __unserialize(array $data): void
{
/** @phpstan-ignore isset.initializedProperty */
if (isset($this->value)) {
- throw new \LogicException('__unserialize() is an internal function, it must not be called directly.');
+ throw new LogicException('__unserialize() is an internal function, it must not be called directly.');
}
/** @phpstan-ignore deadCode.unreachable */
@@ -792,6 +798,12 @@ final readonly class BigDecimal extends BigNumber
$this->scale = $data['scale'];
}
+ #[Override]
+ protected static function from(BigNumber $number): static
+ {
+ return $number->toBigDecimal();
+ }
+
/**
* Puts the internal values of the given decimal numbers on the same scale.
*
@@ -799,15 +811,15 @@ final readonly class BigDecimal extends BigNumber
*
* @pure
*/
- private function scaleValues(BigDecimal $x, BigDecimal $y) : array
+ private function scaleValues(BigDecimal $x, BigDecimal $y): array
{
$a = $x->value;
$b = $y->value;
if ($b !== '0' && $x->scale > $y->scale) {
- $b .= \str_repeat('0', $x->scale - $y->scale);
+ $b .= str_repeat('0', $x->scale - $y->scale);
} elseif ($a !== '0' && $x->scale < $y->scale) {
- $a .= \str_repeat('0', $y->scale - $x->scale);
+ $a .= str_repeat('0', $y->scale - $x->scale);
}
return [$a, $b];
@@ -816,12 +828,12 @@ final readonly class BigDecimal extends BigNumber
/**
* @pure
*/
- private function valueWithMinScale(int $scale) : string
+ private function valueWithMinScale(int $scale): string
{
$value = $this->value;
if ($this->value !== '0' && $scale > $this->scale) {
- $value .= \str_repeat('0', $scale - $this->scale);
+ $value .= str_repeat('0', $scale - $this->scale);
}
return $value;
@@ -832,12 +844,12 @@ final readonly class BigDecimal extends BigNumber
*
* @pure
*/
- private function getUnscaledValueWithLeadingZeros() : string
+ private function getUnscaledValueWithLeadingZeros(): string
{
$value = $this->value;
$targetLength = $this->scale + 1;
$negative = ($value[0] === '-');
- $length = \strlen($value);
+ $length = strlen($value);
if ($negative) {
$length--;
@@ -848,10 +860,10 @@ final readonly class BigDecimal extends BigNumber
}
if ($negative) {
- $value = \substr($value, 1);
+ $value = substr($value, 1);
}
- $value = \str_pad($value, $targetLength, '0', STR_PAD_LEFT);
+ $value = str_pad($value, $targetLength, '0', STR_PAD_LEFT);
if ($negative) {
$value = '-' . $value;
=====================================
vendor/brick/math/src/BigInteger.php
=====================================
@@ -11,8 +11,30 @@ use Brick\Math\Exception\NegativeNumberException;
use Brick\Math\Exception\NumberFormatException;
use Brick\Math\Internal\Calculator;
use Brick\Math\Internal\CalculatorRegistry;
+use InvalidArgumentException;
+use LogicException;
use Override;
+use function assert;
+use function bin2hex;
+use function chr;
+use function filter_var;
+use function hex2bin;
+use function in_array;
+use function intdiv;
+use function ltrim;
+use function ord;
+use function preg_match;
+use function preg_quote;
+use function random_bytes;
+use function sprintf;
+use function str_repeat;
+use function strlen;
+use function strtolower;
+use function substr;
+
+use const FILTER_VALIDATE_INT;
+
/**
* An arbitrary-size integer.
*
@@ -41,12 +63,6 @@ final readonly class BigInteger extends BigNumber
$this->value = $value;
}
- #[Override]
- protected static function from(BigNumber $number): static
- {
- return $number->toBigInteger();
- }
-
/**
* Creates a number from a string in a given base.
*
@@ -61,27 +77,27 @@ final readonly class BigInteger extends BigNumber
* @param string $number The number to convert, in the given base.
* @param int $base The base of the number, between 2 and 36.
*
- * @throws NumberFormatException If the number is empty, or contains invalid chars for the given base.
- * @throws \InvalidArgumentException If the base is out of range.
+ * @throws NumberFormatException If the number is empty, or contains invalid chars for the given base.
+ * @throws InvalidArgumentException If the base is out of range.
*
* @pure
*/
- public static function fromBase(string $number, int $base) : BigInteger
+ public static function fromBase(string $number, int $base): BigInteger
{
if ($number === '') {
throw new NumberFormatException('The number cannot be empty.');
}
if ($base < 2 || $base > 36) {
- throw new \InvalidArgumentException(\sprintf('Base %d is not in range 2 to 36.', $base));
+ throw new InvalidArgumentException(sprintf('Base %d is not in range 2 to 36.', $base));
}
if ($number[0] === '-') {
$sign = '-';
- $number = \substr($number, 1);
+ $number = substr($number, 1);
} elseif ($number[0] === '+') {
$sign = '';
- $number = \substr($number, 1);
+ $number = substr($number, 1);
} else {
$sign = '';
}
@@ -90,7 +106,7 @@ final readonly class BigInteger extends BigNumber
throw new NumberFormatException('The number cannot be empty.');
}
- $number = \ltrim($number, '0');
+ $number = ltrim($number, '0');
if ($number === '') {
// The result will be the same in any base, avoid further calculation.
@@ -102,10 +118,10 @@ final readonly class BigInteger extends BigNumber
return new BigInteger($sign . '1');
}
- $pattern = '/[^' . \substr(Calculator::ALPHABET, 0, $base) . ']/';
+ $pattern = '/[^' . substr(Calculator::ALPHABET, 0, $base) . ']/';
- if (\preg_match($pattern, \strtolower($number), $matches) === 1) {
- throw new NumberFormatException(\sprintf('"%s" is not a valid character in base %d.', $matches[0], $base));
+ if (preg_match($pattern, strtolower($number), $matches) === 1) {
+ throw new NumberFormatException(sprintf('"%s" is not a valid character in base %d.', $matches[0], $base));
}
if ($base === 10) {
@@ -126,26 +142,26 @@ final readonly class BigInteger extends BigNumber
* @param string $number The number to parse.
* @param string $alphabet The alphabet, for example '01' for base 2, or '01234567' for base 8.
*
- * @throws NumberFormatException If the given number is empty or contains invalid chars for the given alphabet.
- * @throws \InvalidArgumentException If the alphabet does not contain at least 2 chars.
+ * @throws NumberFormatException If the given number is empty or contains invalid chars for the given alphabet.
+ * @throws InvalidArgumentException If the alphabet does not contain at least 2 chars.
*
* @pure
*/
- public static function fromArbitraryBase(string $number, string $alphabet) : BigInteger
+ public static function fromArbitraryBase(string $number, string $alphabet): BigInteger
{
if ($number === '') {
throw new NumberFormatException('The number cannot be empty.');
}
- $base = \strlen($alphabet);
+ $base = strlen($alphabet);
if ($base < 2) {
- throw new \InvalidArgumentException('The alphabet must contain at least 2 chars.');
+ throw new InvalidArgumentException('The alphabet must contain at least 2 chars.');
}
- $pattern = '/[^' . \preg_quote($alphabet, '/') . ']/';
+ $pattern = '/[^' . preg_quote($alphabet, '/') . ']/';
- if (\preg_match($pattern, $number, $matches) === 1) {
+ if (preg_match($pattern, $number, $matches) === 1) {
throw NumberFormatException::charNotInAlphabet($matches[0]);
}
@@ -173,7 +189,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public static function fromBytes(string $value, bool $signed = true) : BigInteger
+ public static function fromBytes(string $value, bool $signed = true): BigInteger
{
if ($value === '') {
throw new NumberFormatException('The byte string must not be empty.');
@@ -182,14 +198,14 @@ final readonly class BigInteger extends BigNumber
$twosComplement = false;
if ($signed) {
- $x = \ord($value[0]);
+ $x = ord($value[0]);
if (($twosComplement = ($x >= 0x80))) {
$value = ~$value;
}
}
- $number = self::fromBase(\bin2hex($value), 16);
+ $number = self::fromBase(bin2hex($value), 16);
if ($twosComplement) {
return $number->plus(1)->negated();
@@ -208,12 +224,12 @@ final readonly class BigInteger extends BigNumber
* a string of random bytes of the given length. Defaults
* to the `random_bytes()` function.
*
- * @throws \InvalidArgumentException If $numBits is negative.
+ * @throws InvalidArgumentException If $numBits is negative.
*/
- public static function randomBits(int $numBits, ?callable $randomBytesGenerator = null) : BigInteger
+ public static function randomBits(int $numBits, ?callable $randomBytesGenerator = null): BigInteger
{
if ($numBits < 0) {
- throw new \InvalidArgumentException('The number of bits cannot be negative.');
+ throw new InvalidArgumentException('The number of bits cannot be negative.');
}
if ($numBits === 0) {
@@ -225,12 +241,12 @@ final readonly class BigInteger extends BigNumber
}
/** @var int<1, max> $byteLength */
- $byteLength = \intdiv($numBits - 1, 8) + 1;
+ $byteLength = intdiv($numBits - 1, 8) + 1;
$extraBits = ($byteLength * 8 - $numBits);
- $bitmask = \chr(0xFF >> $extraBits);
+ $bitmask = chr(0xFF >> $extraBits);
- $randomBytes = $randomBytesGenerator($byteLength);
+ $randomBytes = $randomBytesGenerator($byteLength);
$randomBytes[0] = $randomBytes[0] & $bitmask;
return self::fromBytes($randomBytes, false);
@@ -253,8 +269,8 @@ final readonly class BigInteger extends BigNumber
public static function randomRange(
BigNumber|int|float|string $min,
BigNumber|int|float|string $max,
- ?callable $randomBytesGenerator = null
- ) : BigInteger {
+ ?callable $randomBytesGenerator = null,
+ ): BigInteger {
$min = BigInteger::of($min);
$max = BigInteger::of($max);
@@ -266,7 +282,7 @@ final readonly class BigInteger extends BigNumber
return $min;
}
- $diff = $max->minus($min);
+ $diff = $max->minus($min);
$bitLength = $diff->getBitLength();
// try until the number is in range (50% to 100% chance of success)
@@ -282,7 +298,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public static function zero() : BigInteger
+ public static function zero(): BigInteger
{
/** @var BigInteger|null $zero */
static $zero;
@@ -299,7 +315,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public static function one() : BigInteger
+ public static function one(): BigInteger
{
/** @var BigInteger|null $one */
static $one;
@@ -316,7 +332,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public static function ten() : BigInteger
+ public static function ten(): BigInteger
{
/** @var BigInteger|null $ten */
static $ten;
@@ -355,7 +371,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function plus(BigNumber|int|float|string $that) : BigInteger
+ public function plus(BigNumber|int|float|string $that): BigInteger
{
$that = BigInteger::of($that);
@@ -381,7 +397,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function minus(BigNumber|int|float|string $that) : BigInteger
+ public function minus(BigNumber|int|float|string $that): BigInteger
{
$that = BigInteger::of($that);
@@ -403,7 +419,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function multipliedBy(BigNumber|int|float|string $that) : BigInteger
+ public function multipliedBy(BigNumber|int|float|string $that): BigInteger
{
$that = BigInteger::of($that);
@@ -431,7 +447,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function dividedBy(BigNumber|int|float|string $that, RoundingMode $roundingMode = RoundingMode::UNNECESSARY) : BigInteger
+ public function dividedBy(BigNumber|int|float|string $that, RoundingMode $roundingMode = RoundingMode::UNNECESSARY): BigInteger
{
$that = BigInteger::of($that);
@@ -460,25 +476,25 @@ final readonly class BigInteger extends BigNumber
*
* @throws MathException If min/max are not convertible to a BigInteger.
*/
- public function clamp(BigNumber|int|float|string $min, BigNumber|int|float|string $max) : BigInteger
+ public function clamp(BigNumber|int|float|string $min, BigNumber|int|float|string $max): BigInteger
{
if ($this->isLessThan($min)) {
return BigInteger::of($min);
} elseif ($this->isGreaterThan($max)) {
return BigInteger::of($max);
}
+
return $this;
}
-
/**
* Returns this number exponentiated to the given value.
*
- * @throws \InvalidArgumentException If the exponent is not in the range 0 to 1,000,000.
+ * @throws InvalidArgumentException If the exponent is not in the range 0 to 1,000,000.
*
* @pure
*/
- public function power(int $exponent) : BigInteger
+ public function power(int $exponent): BigInteger
{
if ($exponent === 0) {
return BigInteger::one();
@@ -489,10 +505,10 @@ final readonly class BigInteger extends BigNumber
}
if ($exponent < 0 || $exponent > Calculator::MAX_POWER) {
- throw new \InvalidArgumentException(\sprintf(
+ throw new InvalidArgumentException(sprintf(
'The exponent %d is not in the range 0 to %d.',
$exponent,
- Calculator::MAX_POWER
+ Calculator::MAX_POWER,
));
}
@@ -508,7 +524,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function quotient(BigNumber|int|float|string $that) : BigInteger
+ public function quotient(BigNumber|int|float|string $that): BigInteger
{
$that = BigInteger::of($that);
@@ -536,7 +552,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function remainder(BigNumber|int|float|string $that) : BigInteger
+ public function remainder(BigNumber|int|float|string $that): BigInteger
{
$that = BigInteger::of($that);
@@ -564,7 +580,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function quotientAndRemainder(BigNumber|int|float|string $that) : array
+ public function quotientAndRemainder(BigNumber|int|float|string $that): array
{
$that = BigInteger::of($that);
@@ -576,7 +592,7 @@ final readonly class BigInteger extends BigNumber
return [
new BigInteger($quotient),
- new BigInteger($remainder)
+ new BigInteger($remainder),
];
}
@@ -594,7 +610,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function mod(BigNumber|int|float|string $that) : BigInteger
+ public function mod(BigNumber|int|float|string $that): BigInteger
{
$that = BigInteger::of($that);
@@ -617,7 +633,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function modInverse(BigInteger $m) : BigInteger
+ public function modInverse(BigInteger $m): BigInteger
{
if ($m->value === '0') {
throw DivisionByZeroException::modulusMustNotBeZero();
@@ -653,7 +669,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function modPow(BigNumber|int|float|string $exp, BigNumber|int|float|string $mod) : BigInteger
+ public function modPow(BigNumber|int|float|string $exp, BigNumber|int|float|string $mod): BigInteger
{
$exp = BigInteger::of($exp);
$mod = BigInteger::of($mod);
@@ -680,7 +696,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function gcd(BigNumber|int|float|string $that) : BigInteger
+ public function gcd(BigNumber|int|float|string $that): BigInteger
{
$that = BigInteger::of($that);
@@ -706,7 +722,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function sqrt() : BigInteger
+ public function sqrt(): BigInteger
{
if ($this->value[0] === '-') {
throw new NegativeNumberException('Cannot calculate the square root of a negative number.');
@@ -722,7 +738,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function abs() : BigInteger
+ public function abs(): BigInteger
{
return $this->isNegative() ? $this->negated() : $this;
}
@@ -732,7 +748,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function negated() : BigInteger
+ public function negated(): BigInteger
{
return new BigInteger(CalculatorRegistry::get()->neg($this->value));
}
@@ -746,7 +762,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function and(BigNumber|int|float|string $that) : BigInteger
+ public function and(BigNumber|int|float|string $that): BigInteger
{
$that = BigInteger::of($that);
@@ -762,7 +778,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function or(BigNumber|int|float|string $that) : BigInteger
+ public function or(BigNumber|int|float|string $that): BigInteger
{
$that = BigInteger::of($that);
@@ -778,7 +794,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function xor(BigNumber|int|float|string $that) : BigInteger
+ public function xor(BigNumber|int|float|string $that): BigInteger
{
$that = BigInteger::of($that);
@@ -790,7 +806,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function not() : BigInteger
+ public function not(): BigInteger
{
return $this->negated()->minus(1);
}
@@ -800,14 +816,14 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function shiftedLeft(int $distance) : BigInteger
+ public function shiftedLeft(int $distance): BigInteger
{
if ($distance === 0) {
return $this;
}
if ($distance < 0) {
- return $this->shiftedRight(- $distance);
+ return $this->shiftedRight(-$distance);
}
return $this->multipliedBy(BigInteger::of(2)->power($distance));
@@ -818,14 +834,14 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function shiftedRight(int $distance) : BigInteger
+ public function shiftedRight(int $distance): BigInteger
{
if ($distance === 0) {
return $this;
}
if ($distance < 0) {
- return $this->shiftedLeft(- $distance);
+ return $this->shiftedLeft(-$distance);
}
$operand = BigInteger::of(2)->power($distance);
@@ -845,7 +861,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function getBitLength() : int
+ public function getBitLength(): int
{
if ($this->value === '0') {
return 0;
@@ -855,7 +871,7 @@ final readonly class BigInteger extends BigNumber
return $this->abs()->minus(1)->getBitLength();
}
- return \strlen($this->toBase(2));
+ return strlen($this->toBase(2));
}
/**
@@ -865,7 +881,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function getLowestSetBit() : int
+ public function getLowestSetBit(): int
{
$n = $this;
$bitLength = $this->getBitLength();
@@ -886,9 +902,9 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function isEven() : bool
+ public function isEven(): bool
{
- return \in_array($this->value[-1], ['0', '2', '4', '6', '8'], true);
+ return in_array($this->value[-1], ['0', '2', '4', '6', '8'], true);
}
/**
@@ -896,9 +912,9 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function isOdd() : bool
+ public function isOdd(): bool
{
- return \in_array($this->value[-1], ['1', '3', '5', '7', '9'], true);
+ return in_array($this->value[-1], ['1', '3', '5', '7', '9'], true);
}
/**
@@ -908,21 +924,21 @@ final readonly class BigInteger extends BigNumber
*
* @param int $n The bit to test, 0-based.
*
- * @throws \InvalidArgumentException If the bit to test is negative.
+ * @throws InvalidArgumentException If the bit to test is negative.
*
* @pure
*/
- public function testBit(int $n) : bool
+ public function testBit(int $n): bool
{
if ($n < 0) {
- throw new \InvalidArgumentException('The bit to test cannot be negative.');
+ throw new InvalidArgumentException('The bit to test cannot be negative.');
}
return $this->shiftedRight($n)->isOdd();
}
#[Override]
- public function compareTo(BigNumber|int|float|string $that) : int
+ public function compareTo(BigNumber|int|float|string $that): int
{
$that = BigNumber::of($that);
@@ -930,45 +946,45 @@ final readonly class BigInteger extends BigNumber
return CalculatorRegistry::get()->cmp($this->value, $that->value);
}
- return - $that->compareTo($this);
+ return -$that->compareTo($this);
}
#[Override]
- public function getSign() : int
+ public function getSign(): int
{
return ($this->value === '0') ? 0 : (($this->value[0] === '-') ? -1 : 1);
}
#[Override]
- public function toBigInteger() : BigInteger
+ public function toBigInteger(): BigInteger
{
return $this;
}
#[Override]
- public function toBigDecimal() : BigDecimal
+ public function toBigDecimal(): BigDecimal
{
return self::newBigDecimal($this->value);
}
#[Override]
- public function toBigRational() : BigRational
+ public function toBigRational(): BigRational
{
return self::newBigRational($this, BigInteger::one(), false);
}
#[Override]
- public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal
+ public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::UNNECESSARY): BigDecimal
{
return $this->toBigDecimal()->toScale($scale, $roundingMode);
}
#[Override]
- public function toInt() : int
+ public function toInt(): int
{
- $intValue = (int) $this->value;
+ $intValue = filter_var($this->value, FILTER_VALIDATE_INT);
- if ($this->value !== (string) $intValue) {
+ if ($intValue === false) {
throw IntegerOverflowException::toIntOverflow($this);
}
@@ -976,7 +992,7 @@ final readonly class BigInteger extends BigNumber
}
#[Override]
- public function toFloat() : float
+ public function toFloat(): float
{
return (float) $this->value;
}
@@ -986,18 +1002,18 @@ final readonly class BigInteger extends BigNumber
*
* The output will always be lowercase for bases greater than 10.
*
- * @throws \InvalidArgumentException If the base is out of range.
+ * @throws InvalidArgumentException If the base is out of range.
*
* @pure
*/
- public function toBase(int $base) : string
+ public function toBase(int $base): string
{
if ($base === 10) {
return $this->value;
}
if ($base < 2 || $base > 36) {
- throw new \InvalidArgumentException(\sprintf('Base %d is out of range [2, 36]', $base));
+ throw new InvalidArgumentException(sprintf('Base %d is out of range [2, 36]', $base));
}
return CalculatorRegistry::get()->toBase($this->value, $base);
@@ -1011,17 +1027,17 @@ final readonly class BigInteger extends BigNumber
*
* @param string $alphabet The alphabet, for example '01' for base 2, or '01234567' for base 8.
*
- * @throws NegativeNumberException If this number is negative.
- * @throws \InvalidArgumentException If the given alphabet does not contain at least 2 chars.
+ * @throws NegativeNumberException If this number is negative.
+ * @throws InvalidArgumentException If the given alphabet does not contain at least 2 chars.
*
* @pure
*/
- public function toArbitraryBase(string $alphabet) : string
+ public function toArbitraryBase(string $alphabet): string
{
- $base = \strlen($alphabet);
+ $base = strlen($alphabet);
if ($base < 2) {
- throw new \InvalidArgumentException('The alphabet must contain at least 2 chars.');
+ throw new InvalidArgumentException('The alphabet must contain at least 2 chars.');
}
if ($this->value[0] === '-') {
@@ -1051,7 +1067,7 @@ final readonly class BigInteger extends BigNumber
*
* @pure
*/
- public function toBytes(bool $signed = true) : string
+ public function toBytes(bool $signed = true): string
{
if (! $signed && $this->isNegative()) {
throw new NegativeNumberException('Cannot convert a negative number to a byte string when $signed is false.');
@@ -1059,24 +1075,24 @@ final readonly class BigInteger extends BigNumber
$hex = $this->abs()->toBase(16);
- if (\strlen($hex) % 2 !== 0) {
+ if (strlen($hex) % 2 !== 0) {
$hex = '0' . $hex;
}
- $baseHexLength = \strlen($hex);
+ $baseHexLength = strlen($hex);
if ($signed) {
if ($this->isNegative()) {
- $bin = \hex2bin($hex);
+ $bin = hex2bin($hex);
assert($bin !== false);
- $hex = \bin2hex(~$bin);
+ $hex = bin2hex(~$bin);
$hex = self::fromBase($hex, 16)->plus(1)->toBase(16);
- $hexLength = \strlen($hex);
+ $hexLength = strlen($hex);
if ($hexLength < $baseHexLength) {
- $hex = \str_repeat('0', $baseHexLength - $hexLength) . $hex;
+ $hex = str_repeat('0', $baseHexLength - $hexLength) . $hex;
}
if ($hex[0] < '8') {
@@ -1089,7 +1105,7 @@ final readonly class BigInteger extends BigNumber
}
}
- $result = \hex2bin($hex);
+ $result = hex2bin($hex);
assert($result !== false);
return $result;
@@ -1099,7 +1115,7 @@ final readonly class BigInteger extends BigNumber
* @return numeric-string
*/
#[Override]
- public function __toString() : string
+ public function __toString(): string
{
/** @var numeric-string */
return $this->value;
@@ -1124,16 +1140,22 @@ final readonly class BigInteger extends BigNumber
*
* @param array{value: string} $data
*
- * @throws \LogicException
+ * @throws LogicException
*/
public function __unserialize(array $data): void
{
/** @phpstan-ignore isset.initializedProperty */
if (isset($this->value)) {
- throw new \LogicException('__unserialize() is an internal function, it must not be called directly.');
+ throw new LogicException('__unserialize() is an internal function, it must not be called directly.');
}
/** @phpstan-ignore deadCode.unreachable */
$this->value = $data['value'];
}
+
+ #[Override]
+ protected static function from(BigNumber $number): static
+ {
+ return $number->toBigInteger();
+ }
}
=====================================
vendor/brick/math/src/BigNumber.php
=====================================
@@ -8,7 +8,28 @@ use Brick\Math\Exception\DivisionByZeroException;
use Brick\Math\Exception\MathException;
use Brick\Math\Exception\NumberFormatException;
use Brick\Math\Exception\RoundingNecessaryException;
+use InvalidArgumentException;
+use JsonSerializable;
use Override;
+use Stringable;
+
+use function array_shift;
+use function assert;
+use function filter_var;
+use function is_float;
+use function is_int;
+use function is_nan;
+use function is_null;
+use function ltrim;
+use function preg_match;
+use function str_contains;
+use function str_repeat;
+use function strlen;
+use function substr;
+
+use const FILTER_VALIDATE_INT;
+
+use const PREG_UNMATCHED_AS_NULL;
/**
* Base class for arbitrary-precision numbers.
@@ -18,18 +39,18 @@ use Override;
*
* @phpstan-sealed BigInteger|BigDecimal|BigRational
*/
-abstract readonly class BigNumber implements \JsonSerializable, \Stringable
+abstract readonly class BigNumber implements JsonSerializable, Stringable
{
/**
* The regular expression used to parse integer or decimal numbers.
*/
private const PARSE_REGEXP_NUMERICAL =
'/^' .
- '(?<sign>[\-\+])?' .
- '(?<integral>[0-9]+)?' .
- '(?<point>\.)?' .
- '(?<fractional>[0-9]+)?' .
- '(?:[eE](?<exponent>[\-\+]?[0-9]+))?' .
+ '(?<sign>[\-\+])?' .
+ '(?<integral>[0-9]+)?' .
+ '(?<point>\.)?' .
+ '(?<fractional>[0-9]+)?' .
+ '(?:[eE](?<exponent>[\-\+]?[0-9]+))?' .
'$/';
/**
@@ -37,10 +58,10 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
*/
private const PARSE_REGEXP_RATIONAL =
'/^' .
- '(?<sign>[\-\+])?' .
- '(?<numerator>[0-9]+)' .
- '\/?' .
- '(?<denominator>[0-9]+)' .
+ '(?<sign>[\-\+])?' .
+ '(?<numerator>[0-9]+)' .
+ '\/?' .
+ '(?<denominator>[0-9]+)' .
'$/';
/**
@@ -59,13 +80,13 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
* When of() is called on BigInteger, BigDecimal, or BigRational, the resulting number is converted to an instance
* of the subclass when possible; otherwise a RoundingNecessaryException exception is thrown.
*
- * @throws NumberFormatException If the format of the number is not valid.
- * @throws DivisionByZeroException If the value represents a rational number with a denominator of zero.
+ * @throws NumberFormatException If the format of the number is not valid.
+ * @throws DivisionByZeroException If the value represents a rational number with a denominator of zero.
* @throws RoundingNecessaryException If the value cannot be converted to an instance of the subclass without rounding.
*
* @pure
*/
- final public static function of(BigNumber|int|float|string $value) : static
+ final public static function of(BigNumber|int|float|string $value): static
{
$value = self::_of($value);
@@ -79,135 +100,23 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
}
/**
- * @throws NumberFormatException If the format of the number is not valid.
- * @throws DivisionByZeroException If the value represents a rational number with a denominator of zero.
- *
- * @pure
- */
- private static function _of(BigNumber|int|float|string $value) : BigNumber
- {
- if ($value instanceof BigNumber) {
- return $value;
- }
-
- if (\is_int($value)) {
- return new BigInteger((string) $value);
- }
-
- if (is_float($value)) {
- $value = (string) $value;
- }
-
- if (str_contains($value, '/')) {
- // Rational number
- if (\preg_match(self::PARSE_REGEXP_RATIONAL, $value, $matches, PREG_UNMATCHED_AS_NULL) !== 1) {
- throw NumberFormatException::invalidFormat($value);
- }
-
- $sign = $matches['sign'];
- $numerator = $matches['numerator'];
- $denominator = $matches['denominator'];
-
- $numerator = self::cleanUp($sign, $numerator);
- $denominator = self::cleanUp(null, $denominator);
-
- if ($denominator === '0') {
- throw DivisionByZeroException::denominatorMustNotBeZero();
- }
-
- return new BigRational(
- new BigInteger($numerator),
- new BigInteger($denominator),
- false
- );
- } else {
- // Integer or decimal number
- if (\preg_match(self::PARSE_REGEXP_NUMERICAL, $value, $matches, PREG_UNMATCHED_AS_NULL) !== 1) {
- throw NumberFormatException::invalidFormat($value);
- }
-
- $sign = $matches['sign'];
- $point = $matches['point'];
- $integral = $matches['integral'];
- $fractional = $matches['fractional'];
- $exponent = $matches['exponent'];
-
- if ($integral === null && $fractional === null) {
- throw NumberFormatException::invalidFormat($value);
- }
-
- if ($integral === null) {
- $integral = '0';
- }
-
- if ($point !== null || $exponent !== null) {
- $fractional ??= '';
- $exponent = ($exponent !== null) ? (int)$exponent : 0;
-
- if ($exponent === PHP_INT_MIN || $exponent === PHP_INT_MAX) {
- throw new NumberFormatException('Exponent too large.');
- }
-
- $unscaledValue = self::cleanUp($sign, $integral . $fractional);
-
- $scale = \strlen($fractional) - $exponent;
-
- if ($scale < 0) {
- if ($unscaledValue !== '0') {
- $unscaledValue .= \str_repeat('0', -$scale);
- }
- $scale = 0;
- }
-
- return new BigDecimal($unscaledValue, $scale);
- }
-
- $integral = self::cleanUp($sign, $integral);
-
- return new BigInteger($integral);
- }
- }
-
- /**
- * Overridden by subclasses to convert a BigNumber to an instance of the subclass.
- *
- * @throws RoundingNecessaryException If the value cannot be converted.
+ * Creates a BigNumber of the given value, or returns null if the input is null.
*
- * @pure
- */
- abstract protected static function from(BigNumber $number): static;
-
- /**
- * Proxy method to access BigInteger's protected constructor from sibling classes.
+ * Behaves like of() for non-null values.
*
- * @pure
- * @internal
- */
- final protected function newBigInteger(string $value) : BigInteger
- {
- return new BigInteger($value);
- }
-
- /**
- * Proxy method to access BigDecimal's protected constructor from sibling classes.
+ * @see BigNumber::of()
*
- * @pure
- * @internal
+ * @throws NumberFormatException If the format of the number is not valid.
+ * @throws DivisionByZeroException If the value represents a rational number with a denominator of zero.
+ * @throws RoundingNecessaryException If the value cannot be converted to an instance of the subclass without rounding.
*/
- final protected function newBigDecimal(string $value, int $scale = 0) : BigDecimal
+ public static function ofNullable(BigNumber|int|float|string|null $value): ?static
{
- return new BigDecimal($value, $scale);
- }
+ if (is_null($value)) {
+ return null;
+ }
- /**
- * Proxy method to access BigRational's protected constructor from sibling classes.
- *
- * @pure
- * @internal
- */
- final protected function newBigRational(BigInteger $numerator, BigInteger $denominator, bool $checkDenominator) : BigRational
- {
- return new BigRational($numerator, $denominator, $checkDenominator);
+ return static::of($value);
}
/**
@@ -216,12 +125,12 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
* @param BigNumber|int|float|string ...$values The numbers to compare. All the numbers need to be convertible
* to an instance of the class this method is called on.
*
- * @throws \InvalidArgumentException If no values are given.
- * @throws MathException If an argument is not valid.
+ * @throws InvalidArgumentException If no values are given.
+ * @throws MathException If an argument is not valid.
*
* @pure
*/
- final public static function min(BigNumber|int|float|string ...$values) : static
+ final public static function min(BigNumber|int|float|string ...$values): static
{
$min = null;
@@ -234,7 +143,7 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
}
if ($min === null) {
- throw new \InvalidArgumentException(__METHOD__ . '() expects at least one value.');
+ throw new InvalidArgumentException(__METHOD__ . '() expects at least one value.');
}
return $min;
@@ -246,12 +155,12 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
* @param BigNumber|int|float|string ...$values The numbers to compare. All the numbers need to be convertible
* to an instance of the class this method is called on.
*
- * @throws \InvalidArgumentException If no values are given.
- * @throws MathException If an argument is not valid.
+ * @throws InvalidArgumentException If no values are given.
+ * @throws MathException If an argument is not valid.
*
* @pure
*/
- final public static function max(BigNumber|int|float|string ...$values) : static
+ final public static function max(BigNumber|int|float|string ...$values): static
{
$max = null;
@@ -264,7 +173,7 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
}
if ($max === null) {
- throw new \InvalidArgumentException(__METHOD__ . '() expects at least one value.');
+ throw new InvalidArgumentException(__METHOD__ . '() expects at least one value.');
}
return $max;
@@ -282,17 +191,17 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
* @param BigNumber|int|float|string ...$values The values to add. All values must be convertible to the class on
* which this method is called.
*
- * @throws \InvalidArgumentException If no values are given.
- * @throws MathException If an argument is not valid.
+ * @throws InvalidArgumentException If no values are given.
+ * @throws MathException If an argument is not valid.
*
* @pure
*/
- final public static function sum(BigNumber|int|float|string ...$values) : static
+ final public static function sum(BigNumber|int|float|string ...$values): static
{
$first = array_shift($values);
if ($first === null) {
- throw new \InvalidArgumentException(__METHOD__ . '() expects at least one value.');
+ throw new InvalidArgumentException(__METHOD__ . '() expects at least one value.');
}
$sum = static::of($first);
@@ -306,57 +215,12 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
return $sum;
}
- /**
- * Adds two BigNumber instances in the correct order to avoid a RoundingNecessaryException.
- *
- * @pure
- */
- private static function add(BigNumber $a, BigNumber $b) : BigNumber
- {
- if ($a instanceof BigRational) {
- return $a->plus($b);
- }
-
- if ($b instanceof BigRational) {
- return $b->plus($a);
- }
-
- if ($a instanceof BigDecimal) {
- return $a->plus($b);
- }
-
- if ($b instanceof BigDecimal) {
- return $b->plus($a);
- }
-
- return $a->plus($b);
- }
-
- /**
- * Removes optional leading zeros and applies sign.
- *
- * @param string|null $sign The sign, '+' or '-', optional. Null is allowed for convenience and treated as '+'.
- * @param string $number The number, validated as a string of digits.
- *
- * @pure
- */
- private static function cleanUp(string|null $sign, string $number) : string
- {
- $number = \ltrim($number, '0');
-
- if ($number === '') {
- return '0';
- }
-
- return $sign === '-' ? '-' . $number : $number;
- }
-
/**
* Checks if this number is equal to the given one.
*
* @pure
*/
- final public function isEqualTo(BigNumber|int|float|string $that) : bool
+ final public function isEqualTo(BigNumber|int|float|string $that): bool
{
return $this->compareTo($that) === 0;
}
@@ -366,7 +230,7 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
*
* @pure
*/
- final public function isLessThan(BigNumber|int|float|string $that) : bool
+ final public function isLessThan(BigNumber|int|float|string $that): bool
{
return $this->compareTo($that) < 0;
}
@@ -376,7 +240,7 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
*
* @pure
*/
- final public function isLessThanOrEqualTo(BigNumber|int|float|string $that) : bool
+ final public function isLessThanOrEqualTo(BigNumber|int|float|string $that): bool
{
return $this->compareTo($that) <= 0;
}
@@ -386,7 +250,7 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
*
* @pure
*/
- final public function isGreaterThan(BigNumber|int|float|string $that) : bool
+ final public function isGreaterThan(BigNumber|int|float|string $that): bool
{
return $this->compareTo($that) > 0;
}
@@ -396,7 +260,7 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
*
* @pure
*/
- final public function isGreaterThanOrEqualTo(BigNumber|int|float|string $that) : bool
+ final public function isGreaterThanOrEqualTo(BigNumber|int|float|string $that): bool
{
return $this->compareTo($that) >= 0;
}
@@ -406,7 +270,7 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
*
* @pure
*/
- final public function isZero() : bool
+ final public function isZero(): bool
{
return $this->getSign() === 0;
}
@@ -416,7 +280,7 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
*
* @pure
*/
- final public function isNegative() : bool
+ final public function isNegative(): bool
{
return $this->getSign() < 0;
}
@@ -426,7 +290,7 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
*
* @pure
*/
- final public function isNegativeOrZero() : bool
+ final public function isNegativeOrZero(): bool
{
return $this->getSign() <= 0;
}
@@ -436,7 +300,7 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
*
* @pure
*/
- final public function isPositive() : bool
+ final public function isPositive(): bool
{
return $this->getSign() > 0;
}
@@ -446,7 +310,7 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
*
* @pure
*/
- final public function isPositiveOrZero() : bool
+ final public function isPositiveOrZero(): bool
{
return $this->getSign() >= 0;
}
@@ -460,7 +324,7 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
*
* @pure
*/
- abstract public function getSign() : int;
+ abstract public function getSign(): int;
/**
* Compares this number to the given one.
@@ -473,7 +337,7 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
*
* @pure
*/
- abstract public function compareTo(BigNumber|int|float|string $that) : int;
+ abstract public function compareTo(BigNumber|int|float|string $that): int;
/**
* Converts this number to a BigInteger.
@@ -482,7 +346,7 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
*
* @pure
*/
- abstract public function toBigInteger() : BigInteger;
+ abstract public function toBigInteger(): BigInteger;
/**
* Converts this number to a BigDecimal.
@@ -491,14 +355,14 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
*
* @pure
*/
- abstract public function toBigDecimal() : BigDecimal;
+ abstract public function toBigDecimal(): BigDecimal;
/**
* Converts this number to a BigRational.
*
* @pure
*/
- abstract public function toBigRational() : BigRational;
+ abstract public function toBigRational(): BigRational;
/**
* Converts this number to a BigDecimal with the given scale, using rounding if necessary.
@@ -511,7 +375,7 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
*
* @pure
*/
- abstract public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal;
+ abstract public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::UNNECESSARY): BigDecimal;
/**
* Returns the exact value of this number as a native integer.
@@ -523,7 +387,7 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
*
* @pure
*/
- abstract public function toInt() : int;
+ abstract public function toInt(): int;
/**
* Returns an approximation of this number as a floating-point value.
@@ -536,7 +400,13 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
*
* @pure
*/
- abstract public function toFloat() : float;
+ abstract public function toFloat(): float;
+
+ #[Override]
+ final public function jsonSerialize(): string
+ {
+ return $this->__toString();
+ }
/**
* Returns a string representation of this number.
@@ -546,11 +416,206 @@ abstract readonly class BigNumber implements \JsonSerializable, \Stringable
*
* @pure
*/
- abstract public function __toString() : string;
+ abstract public function __toString(): string;
- #[Override]
- final public function jsonSerialize() : string
+ /**
+ * Overridden by subclasses to convert a BigNumber to an instance of the subclass.
+ *
+ * @throws RoundingNecessaryException If the value cannot be converted.
+ *
+ * @pure
+ */
+ abstract protected static function from(BigNumber $number): static;
+
+ /**
+ * Proxy method to access BigInteger's protected constructor from sibling classes.
+ *
+ * @internal
+ *
+ * @pure
+ */
+ final protected function newBigInteger(string $value): BigInteger
{
- return $this->__toString();
+ return new BigInteger($value);
+ }
+
+ /**
+ * Proxy method to access BigDecimal's protected constructor from sibling classes.
+ *
+ * @internal
+ *
+ * @pure
+ */
+ final protected function newBigDecimal(string $value, int $scale = 0): BigDecimal
+ {
+ return new BigDecimal($value, $scale);
+ }
+
+ /**
+ * Proxy method to access BigRational's protected constructor from sibling classes.
+ *
+ * @internal
+ *
+ * @pure
+ */
+ final protected function newBigRational(BigInteger $numerator, BigInteger $denominator, bool $checkDenominator): BigRational
+ {
+ return new BigRational($numerator, $denominator, $checkDenominator);
+ }
+
+ /**
+ * @throws NumberFormatException If the format of the number is not valid.
+ * @throws DivisionByZeroException If the value represents a rational number with a denominator of zero.
+ *
+ * @pure
+ */
+ private static function _of(BigNumber|int|float|string $value): BigNumber
+ {
+ if ($value instanceof BigNumber) {
+ return $value;
+ }
+
+ if (is_int($value)) {
+ return new BigInteger((string) $value);
+ }
+
+ if (is_float($value)) {
+ if (is_nan($value)) {
+ $value = 'NAN';
+ } else {
+ $value = (string) $value;
+ }
+ }
+
+ if (str_contains($value, '/')) {
+ // Rational number
+ if (preg_match(self::PARSE_REGEXP_RATIONAL, $value, $matches, PREG_UNMATCHED_AS_NULL) !== 1) {
+ throw NumberFormatException::invalidFormat($value);
+ }
+
+ $sign = $matches['sign'];
+ $numerator = $matches['numerator'];
+ $denominator = $matches['denominator'];
+
+ $numerator = self::cleanUp($sign, $numerator);
+ $denominator = self::cleanUp(null, $denominator);
+
+ if ($denominator === '0') {
+ throw DivisionByZeroException::denominatorMustNotBeZero();
+ }
+
+ return new BigRational(
+ new BigInteger($numerator),
+ new BigInteger($denominator),
+ false,
+ );
+ } else {
+ // Integer or decimal number
+ if (preg_match(self::PARSE_REGEXP_NUMERICAL, $value, $matches, PREG_UNMATCHED_AS_NULL) !== 1) {
+ throw NumberFormatException::invalidFormat($value);
+ }
+
+ $sign = $matches['sign'];
+ $point = $matches['point'];
+ $integral = $matches['integral'];
+ $fractional = $matches['fractional'];
+ $exponent = $matches['exponent'];
+
+ if ($integral === null && $fractional === null) {
+ throw NumberFormatException::invalidFormat($value);
+ }
+
+ if ($integral === null) {
+ $integral = '0';
+ }
+
+ if ($point !== null || $exponent !== null) {
+ $fractional ??= '';
+
+ if ($exponent !== null) {
+ if ($exponent[0] === '-') {
+ $exponent = ltrim(substr($exponent, 1), '0') ?: '0';
+ $exponent = filter_var($exponent, FILTER_VALIDATE_INT);
+ if ($exponent !== false) {
+ $exponent = -$exponent;
+ }
+ } else {
+ if ($exponent[0] === '+') {
+ $exponent = substr($exponent, 1);
+ }
+ $exponent = ltrim($exponent, '0') ?: '0';
+ $exponent = filter_var($exponent, FILTER_VALIDATE_INT);
+ }
+ } else {
+ $exponent = 0;
+ }
+
+ if ($exponent === false) {
+ throw new NumberFormatException('Exponent too large.');
+ }
+
+ $unscaledValue = self::cleanUp($sign, $integral . $fractional);
+
+ $scale = strlen($fractional) - $exponent;
+
+ if ($scale < 0) {
+ if ($unscaledValue !== '0') {
+ $unscaledValue .= str_repeat('0', -$scale);
+ }
+ $scale = 0;
+ }
+
+ return new BigDecimal($unscaledValue, $scale);
+ }
+
+ $integral = self::cleanUp($sign, $integral);
+
+ return new BigInteger($integral);
+ }
+ }
+
+ /**
+ * Removes optional leading zeros and applies sign.
+ *
+ * @param string|null $sign The sign, '+' or '-', optional. Null is allowed for convenience and treated as '+'.
+ * @param string $number The number, validated as a string of digits.
+ *
+ * @pure
+ */
+ private static function cleanUp(string|null $sign, string $number): string
+ {
+ $number = ltrim($number, '0');
+
+ if ($number === '') {
+ return '0';
+ }
+
+ return $sign === '-' ? '-' . $number : $number;
+ }
+
+ /**
+ * Adds two BigNumber instances in the correct order to avoid a RoundingNecessaryException.
+ *
+ * @pure
+ */
+ private static function add(BigNumber $a, BigNumber $b): BigNumber
+ {
+ if ($a instanceof BigRational) {
+ return $a->plus($b);
+ }
+
+ if ($b instanceof BigRational) {
+ return $b->plus($a);
+ }
+
+ if ($a instanceof BigDecimal) {
+ return $a->plus($b);
+ }
+
+ if ($b instanceof BigDecimal) {
+ return $b->plus($a);
+ }
+
+ return $a->plus($b);
}
}
=====================================
vendor/brick/math/src/BigRational.php
=====================================
@@ -8,6 +8,8 @@ use Brick\Math\Exception\DivisionByZeroException;
use Brick\Math\Exception\MathException;
use Brick\Math\Exception\NumberFormatException;
use Brick\Math\Exception\RoundingNecessaryException;
+use InvalidArgumentException;
+use LogicException;
use Override;
/**
@@ -46,21 +48,15 @@ final readonly class BigRational extends BigNumber
}
if ($denominator->isNegative()) {
- $numerator = $numerator->negated();
+ $numerator = $numerator->negated();
$denominator = $denominator->negated();
}
}
- $this->numerator = $numerator;
+ $this->numerator = $numerator;
$this->denominator = $denominator;
}
- #[Override]
- protected static function from(BigNumber $number): static
- {
- return $number->toBigRational();
- }
-
/**
* Creates a BigRational out of a numerator and a denominator.
*
@@ -79,8 +75,8 @@ final readonly class BigRational extends BigNumber
public static function nd(
BigNumber|int|float|string $numerator,
BigNumber|int|float|string $denominator,
- ) : BigRational {
- $numerator = BigInteger::of($numerator);
+ ): BigRational {
+ $numerator = BigInteger::of($numerator);
$denominator = BigInteger::of($denominator);
return new BigRational($numerator, $denominator, true);
@@ -91,7 +87,7 @@ final readonly class BigRational extends BigNumber
*
* @pure
*/
- public static function zero() : BigRational
+ public static function zero(): BigRational
{
/** @var BigRational|null $zero */
static $zero;
@@ -108,7 +104,7 @@ final readonly class BigRational extends BigNumber
*
* @pure
*/
- public static function one() : BigRational
+ public static function one(): BigRational
{
/** @var BigRational|null $one */
static $one;
@@ -125,7 +121,7 @@ final readonly class BigRational extends BigNumber
*
* @pure
*/
- public static function ten() : BigRational
+ public static function ten(): BigRational
{
/** @var BigRational|null $ten */
static $ten;
@@ -140,7 +136,7 @@ final readonly class BigRational extends BigNumber
/**
* @pure
*/
- public function getNumerator() : BigInteger
+ public function getNumerator(): BigInteger
{
return $this->numerator;
}
@@ -148,7 +144,7 @@ final readonly class BigRational extends BigNumber
/**
* @pure
*/
- public function getDenominator() : BigInteger
+ public function getDenominator(): BigInteger
{
return $this->denominator;
}
@@ -158,7 +154,7 @@ final readonly class BigRational extends BigNumber
*
* @pure
*/
- public function quotient() : BigInteger
+ public function quotient(): BigInteger
{
return $this->numerator->quotient($this->denominator);
}
@@ -168,7 +164,7 @@ final readonly class BigRational extends BigNumber
*
* @pure
*/
- public function remainder() : BigInteger
+ public function remainder(): BigInteger
{
return $this->numerator->remainder($this->denominator);
}
@@ -180,7 +176,7 @@ final readonly class BigRational extends BigNumber
*
* @pure
*/
- public function quotientAndRemainder() : array
+ public function quotientAndRemainder(): array
{
return $this->numerator->quotientAndRemainder($this->denominator);
}
@@ -194,12 +190,12 @@ final readonly class BigRational extends BigNumber
*
* @pure
*/
- public function plus(BigNumber|int|float|string $that) : BigRational
+ public function plus(BigNumber|int|float|string $that): BigRational
{
$that = BigRational::of($that);
- $numerator = $this->numerator->multipliedBy($that->denominator);
- $numerator = $numerator->plus($that->numerator->multipliedBy($this->denominator));
+ $numerator = $this->numerator->multipliedBy($that->denominator);
+ $numerator = $numerator->plus($that->numerator->multipliedBy($this->denominator));
$denominator = $this->denominator->multipliedBy($that->denominator);
return new BigRational($numerator, $denominator, false);
@@ -214,12 +210,12 @@ final readonly class BigRational extends BigNumber
*
* @pure
*/
- public function minus(BigNumber|int|float|string $that) : BigRational
+ public function minus(BigNumber|int|float|string $that): BigRational
{
$that = BigRational::of($that);
- $numerator = $this->numerator->multipliedBy($that->denominator);
- $numerator = $numerator->minus($that->numerator->multipliedBy($this->denominator));
+ $numerator = $this->numerator->multipliedBy($that->denominator);
+ $numerator = $numerator->minus($that->numerator->multipliedBy($this->denominator));
$denominator = $this->denominator->multipliedBy($that->denominator);
return new BigRational($numerator, $denominator, false);
@@ -234,11 +230,11 @@ final readonly class BigRational extends BigNumber
*
* @pure
*/
- public function multipliedBy(BigNumber|int|float|string $that) : BigRational
+ public function multipliedBy(BigNumber|int|float|string $that): BigRational
{
$that = BigRational::of($that);
- $numerator = $this->numerator->multipliedBy($that->numerator);
+ $numerator = $this->numerator->multipliedBy($that->numerator);
$denominator = $this->denominator->multipliedBy($that->denominator);
return new BigRational($numerator, $denominator, false);
@@ -253,11 +249,11 @@ final readonly class BigRational extends BigNumber
*
* @pure
*/
- public function dividedBy(BigNumber|int|float|string $that) : BigRational
+ public function dividedBy(BigNumber|int|float|string $that): BigRational
{
$that = BigRational::of($that);
- $numerator = $this->numerator->multipliedBy($that->denominator);
+ $numerator = $this->numerator->multipliedBy($that->denominator);
$denominator = $this->denominator->multipliedBy($that->numerator);
return new BigRational($numerator, $denominator, true);
@@ -266,11 +262,11 @@ final readonly class BigRational extends BigNumber
/**
* Returns this number exponentiated to the given value.
*
- * @throws \InvalidArgumentException If the exponent is not in the range 0 to 1,000,000.
+ * @throws InvalidArgumentException If the exponent is not in the range 0 to 1,000,000.
*
* @pure
*/
- public function power(int $exponent) : BigRational
+ public function power(int $exponent): BigRational
{
if ($exponent === 0) {
$one = BigInteger::one();
@@ -285,7 +281,7 @@ final readonly class BigRational extends BigNumber
return new BigRational(
$this->numerator->power($exponent),
$this->denominator->power($exponent),
- false
+ false,
);
}
@@ -298,7 +294,7 @@ final readonly class BigRational extends BigNumber
*
* @pure
*/
- public function reciprocal() : BigRational
+ public function reciprocal(): BigRational
{
return new BigRational($this->denominator, $this->numerator, true);
}
@@ -308,7 +304,7 @@ final readonly class BigRational extends BigNumber
*
* @pure
*/
- public function abs() : BigRational
+ public function abs(): BigRational
{
return new BigRational($this->numerator->abs(), $this->denominator, false);
}
@@ -318,7 +314,7 @@ final readonly class BigRational extends BigNumber
*
* @pure
*/
- public function negated() : BigRational
+ public function negated(): BigRational
{
return new BigRational($this->numerator->negated(), $this->denominator, false);
}
@@ -328,7 +324,7 @@ final readonly class BigRational extends BigNumber
*
* @pure
*/
- public function simplified() : BigRational
+ public function simplified(): BigRational
{
$gcd = $this->numerator->gcd($this->denominator);
@@ -339,19 +335,19 @@ final readonly class BigRational extends BigNumber
}
#[Override]
- public function compareTo(BigNumber|int|float|string $that) : int
+ public function compareTo(BigNumber|int|float|string $that): int
{
return $this->minus($that)->getSign();
}
#[Override]
- public function getSign() : int
+ public function getSign(): int
{
return $this->numerator->getSign();
}
#[Override]
- public function toBigInteger() : BigInteger
+ public function toBigInteger(): BigInteger
{
$simplified = $this->simplified();
@@ -363,40 +359,41 @@ final readonly class BigRational extends BigNumber
}
#[Override]
- public function toBigDecimal() : BigDecimal
+ public function toBigDecimal(): BigDecimal
{
return $this->numerator->toBigDecimal()->exactlyDividedBy($this->denominator);
}
#[Override]
- public function toBigRational() : BigRational
+ public function toBigRational(): BigRational
{
return $this;
}
#[Override]
- public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal
+ public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::UNNECESSARY): BigDecimal
{
return $this->numerator->toBigDecimal()->dividedBy($this->denominator, $scale, $roundingMode);
}
#[Override]
- public function toInt() : int
+ public function toInt(): int
{
return $this->toBigInteger()->toInt();
}
#[Override]
- public function toFloat() : float
+ public function toFloat(): float
{
$simplified = $this->simplified();
+
return $simplified->numerator->toFloat() / $simplified->denominator->toFloat();
}
#[Override]
- public function __toString() : string
+ public function __toString(): string
{
- $numerator = (string) $this->numerator;
+ $numerator = (string) $this->numerator;
$denominator = (string) $this->denominator;
if ($denominator === '1') {
@@ -425,17 +422,23 @@ final readonly class BigRational extends BigNumber
*
* @param array{numerator: BigInteger, denominator: BigInteger} $data
*
- * @throws \LogicException
+ * @throws LogicException
*/
public function __unserialize(array $data): void
{
/** @phpstan-ignore isset.initializedProperty */
if (isset($this->numerator)) {
- throw new \LogicException('__unserialize() is an internal function, it must not be called directly.');
+ throw new LogicException('__unserialize() is an internal function, it must not be called directly.');
}
/** @phpstan-ignore deadCode.unreachable */
$this->numerator = $data['numerator'];
$this->denominator = $data['denominator'];
}
+
+ #[Override]
+ protected static function from(BigNumber $number): static
+ {
+ return $number->toBigRational();
+ }
}
=====================================
vendor/brick/math/src/Exception/DivisionByZeroException.php
=====================================
@@ -12,7 +12,7 @@ final class DivisionByZeroException extends MathException
/**
* @pure
*/
- public static function divisionByZero() : DivisionByZeroException
+ public static function divisionByZero(): DivisionByZeroException
{
return new self('Division by zero.');
}
@@ -20,7 +20,7 @@ final class DivisionByZeroException extends MathException
/**
* @pure
*/
- public static function modulusMustNotBeZero() : DivisionByZeroException
+ public static function modulusMustNotBeZero(): DivisionByZeroException
{
return new self('The modulus must not be zero.');
}
@@ -28,7 +28,7 @@ final class DivisionByZeroException extends MathException
/**
* @pure
*/
- public static function denominatorMustNotBeZero() : DivisionByZeroException
+ public static function denominatorMustNotBeZero(): DivisionByZeroException
{
return new self('The denominator of a rational number cannot be zero.');
}
=====================================
vendor/brick/math/src/Exception/IntegerOverflowException.php
=====================================
@@ -6,6 +6,11 @@ namespace Brick\Math\Exception;
use Brick\Math\BigInteger;
+use function sprintf;
+
+use const PHP_INT_MAX;
+use const PHP_INT_MIN;
+
/**
* Exception thrown when an integer overflow occurs.
*/
@@ -14,10 +19,10 @@ final class IntegerOverflowException extends MathException
/**
* @pure
*/
- public static function toIntOverflow(BigInteger $value) : IntegerOverflowException
+ public static function toIntOverflow(BigInteger $value): IntegerOverflowException
{
$message = '%s is out of range %d to %d and cannot be represented as an integer.';
- return new self(\sprintf($message, (string) $value, PHP_INT_MIN, PHP_INT_MAX));
+ return new self(sprintf($message, (string) $value, PHP_INT_MIN, PHP_INT_MAX));
}
}
=====================================
vendor/brick/math/src/Exception/MathException.php
=====================================
@@ -4,9 +4,11 @@ declare(strict_types=1);
namespace Brick\Math\Exception;
+use RuntimeException;
+
/**
* Base class for all math exceptions.
*/
-class MathException extends \RuntimeException
+class MathException extends RuntimeException
{
}
=====================================
vendor/brick/math/src/Exception/NumberFormatException.php
=====================================
@@ -4,6 +4,11 @@ declare(strict_types=1);
namespace Brick\Math\Exception;
+use function dechex;
+use function ord;
+use function sprintf;
+use function strtoupper;
+
/**
* Exception thrown when attempting to create a number from a string with an invalid format.
*/
@@ -12,9 +17,9 @@ final class NumberFormatException extends MathException
/**
* @pure
*/
- public static function invalidFormat(string $value) : self
+ public static function invalidFormat(string $value): self
{
- return new self(\sprintf(
+ return new self(sprintf(
'The given value "%s" does not represent a valid number.',
$value,
));
@@ -25,12 +30,12 @@ final class NumberFormatException extends MathException
*
* @pure
*/
- public static function charNotInAlphabet(string $char) : self
+ public static function charNotInAlphabet(string $char): self
{
- $ord = \ord($char);
+ $ord = ord($char);
if ($ord < 32 || $ord > 126) {
- $char = \strtoupper(\dechex($ord));
+ $char = strtoupper(dechex($ord));
if ($ord < 10) {
$char = '0' . $char;
@@ -39,6 +44,6 @@ final class NumberFormatException extends MathException
$char = '"' . $char . '"';
}
- return new self(\sprintf('Char %s is not a valid character in the given alphabet.', $char));
+ return new self(sprintf('Char %s is not a valid character in the given alphabet.', $char));
}
}
=====================================
vendor/brick/math/src/Exception/RoundingNecessaryException.php
=====================================
@@ -12,7 +12,7 @@ final class RoundingNecessaryException extends MathException
/**
* @pure
*/
- public static function roundingNecessary() : RoundingNecessaryException
+ public static function roundingNecessary(): RoundingNecessaryException
{
return new self('Rounding is necessary to represent the result of the operation at this scale.');
}
=====================================
vendor/brick/math/src/Internal/Calculator.php
=====================================
@@ -7,6 +7,16 @@ namespace Brick\Math\Internal;
use Brick\Math\Exception\RoundingNecessaryException;
use Brick\Math\RoundingMode;
+use function chr;
+use function ltrim;
+use function ord;
+use function str_repeat;
+use function strlen;
+use function strpos;
+use function strrev;
+use function strtolower;
+use function substr;
+
/**
* Performs basic operations on arbitrary size integers.
*
@@ -30,32 +40,14 @@ abstract readonly class Calculator
*/
public const ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz';
- /**
- * Extracts the sign & digits of the operands.
- *
- * @return array{bool, bool, string, string} Whether $a and $b are negative, followed by their digits.
- *
- * @pure
- */
- final protected function init(string $a, string $b) : array
- {
- return [
- $aNeg = ($a[0] === '-'),
- $bNeg = ($b[0] === '-'),
-
- $aNeg ? \substr($a, 1) : $a,
- $bNeg ? \substr($b, 1) : $b,
- ];
- }
-
/**
* Returns the absolute value of a number.
*
* @pure
*/
- final public function abs(string $n) : string
+ final public function abs(string $n): string
{
- return ($n[0] === '-') ? \substr($n, 1) : $n;
+ return ($n[0] === '-') ? substr($n, 1) : $n;
}
/**
@@ -63,14 +55,14 @@ abstract readonly class Calculator
*
* @pure
*/
- final public function neg(string $n) : string
+ final public function neg(string $n): string
{
if ($n === '0') {
return '0';
}
if ($n[0] === '-') {
- return \substr($n, 1);
+ return substr($n, 1);
}
return '-' . $n;
@@ -85,7 +77,7 @@ abstract readonly class Calculator
*
* @pure
*/
- final public function cmp(string $a, string $b) : int
+ final public function cmp(string $a, string $b): int
{
[$aNeg, $bNeg, $aDig, $bDig] = $this->init($a, $b);
@@ -97,8 +89,8 @@ abstract readonly class Calculator
return 1;
}
- $aLen = \strlen($aDig);
- $bLen = \strlen($bDig);
+ $aLen = strlen($aDig);
+ $bLen = strlen($bDig);
if ($aLen < $bLen) {
$result = -1;
@@ -116,21 +108,21 @@ abstract readonly class Calculator
*
* @pure
*/
- abstract public function add(string $a, string $b) : string;
+ abstract public function add(string $a, string $b): string;
/**
* Subtracts two numbers.
*
* @pure
*/
- abstract public function sub(string $a, string $b) : string;
+ abstract public function sub(string $a, string $b): string;
/**
* Multiplies two numbers.
*
* @pure
*/
- abstract public function mul(string $a, string $b) : string;
+ abstract public function mul(string $a, string $b): string;
/**
* Returns the quotient of the division of two numbers.
@@ -142,7 +134,7 @@ abstract readonly class Calculator
*
* @pure
*/
- abstract public function divQ(string $a, string $b) : string;
+ abstract public function divQ(string $a, string $b): string;
/**
* Returns the remainder of the division of two numbers.
@@ -154,7 +146,7 @@ abstract readonly class Calculator
*
* @pure
*/
- abstract public function divR(string $a, string $b) : string;
+ abstract public function divR(string $a, string $b): string;
/**
* Returns the quotient and remainder of the division of two numbers.
@@ -166,7 +158,7 @@ abstract readonly class Calculator
*
* @pure
*/
- abstract public function divQR(string $a, string $b) : array;
+ abstract public function divQR(string $a, string $b): array;
/**
* Exponentiates a number.
@@ -178,14 +170,14 @@ abstract readonly class Calculator
*
* @pure
*/
- abstract public function pow(string $a, int $e) : string;
+ abstract public function pow(string $a, int $e): string;
/**
* @param string $b The modulus; must not be zero.
*
* @pure
*/
- public function mod(string $a, string $b) : string
+ public function mod(string $a, string $b): string
{
return $this->divR($this->add($this->divR($a, $b), $b), $b);
}
@@ -201,7 +193,7 @@ abstract readonly class Calculator
*
* @pure
*/
- public function modInverse(string $x, string $m) : ?string
+ public function modInverse(string $x, string $m): ?string
{
if ($m === '1') {
return '0';
@@ -231,7 +223,7 @@ abstract readonly class Calculator
*
* @pure
*/
- abstract public function modPow(string $base, string $exp, string $mod) : string;
+ abstract public function modPow(string $base, string $exp, string $mod): string;
/**
* Returns the greatest common divisor of the two numbers.
@@ -243,7 +235,7 @@ abstract readonly class Calculator
*
* @pure
*/
- public function gcd(string $a, string $b) : string
+ public function gcd(string $a, string $b): string
{
if ($a === '0') {
return $this->abs($b);
@@ -256,25 +248,6 @@ abstract readonly class Calculator
return $this->gcd($b, $this->divR($a, $b));
}
- /**
- * @return array{string, string, string} GCD, X, Y
- *
- * @pure
- */
- private function gcdExtended(string $a, string $b) : array
- {
- if ($a === '0') {
- return [$b, '0', '1'];
- }
-
- [$gcd, $x1, $y1] = $this->gcdExtended($this->mod($b, $a), $a);
-
- $x = $this->sub($y1, $this->mul($this->divQ($b, $a), $x1));
- $y = $x1;
-
- return [$gcd, $x, $y];
- }
-
/**
* Returns the square root of the given number, rounded down.
*
@@ -283,7 +256,7 @@ abstract readonly class Calculator
*
* @pure
*/
- abstract public function sqrt(string $n) : string;
+ abstract public function sqrt(string $n): string;
/**
* Converts a number from an arbitrary base.
@@ -298,9 +271,9 @@ abstract readonly class Calculator
*
* @pure
*/
- public function fromBase(string $number, int $base) : string
+ public function fromBase(string $number, int $base): string
{
- return $this->fromArbitraryBase(\strtolower($number), self::ALPHABET, $base);
+ return $this->fromArbitraryBase(strtolower($number), self::ALPHABET, $base);
}
/**
@@ -316,12 +289,12 @@ abstract readonly class Calculator
*
* @pure
*/
- public function toBase(string $number, int $base) : string
+ public function toBase(string $number, int $base): string
{
$negative = ($number[0] === '-');
if ($negative) {
- $number = \substr($number, 1);
+ $number = substr($number, 1);
}
$number = $this->toArbitraryBase($number, self::ALPHABET, $base);
@@ -345,10 +318,10 @@ abstract readonly class Calculator
*
* @pure
*/
- final public function fromArbitraryBase(string $number, string $alphabet, int $base) : string
+ final public function fromArbitraryBase(string $number, string $alphabet, int $base): string
{
// remove leading "zeros"
- $number = \ltrim($number, $alphabet[0]);
+ $number = ltrim($number, $alphabet[0]);
if ($number === '') {
return '0';
@@ -364,13 +337,13 @@ abstract readonly class Calculator
$base = (string) $base;
- for ($i = \strlen($number) - 1; $i >= 0; $i--) {
- $index = \strpos($alphabet, $number[$i]);
+ for ($i = strlen($number) - 1; $i >= 0; $i--) {
+ $index = strpos($alphabet, $number[$i]);
if ($index !== 0) {
- $result = $this->add($result, ($index === 1)
- ? $power
- : $this->mul($power, (string) $index)
+ $result = $this->add(
+ $result,
+ ($index === 1) ? $power : $this->mul($power, (string) $index),
);
}
@@ -393,7 +366,7 @@ abstract readonly class Calculator
*
* @pure
*/
- final public function toArbitraryBase(string $number, string $alphabet, int $base) : string
+ final public function toArbitraryBase(string $number, string $alphabet, int $base): string
{
if ($number === '0') {
return $alphabet[0];
@@ -409,7 +382,7 @@ abstract readonly class Calculator
$result .= $alphabet[$remainder];
}
- return \strrev($result);
+ return strrev($result);
}
/**
@@ -425,14 +398,14 @@ abstract readonly class Calculator
*
* @pure
*/
- final public function divRound(string $a, string $b, RoundingMode $roundingMode) : string
+ final public function divRound(string $a, string $b, RoundingMode $roundingMode): string
{
[$quotient, $remainder] = $this->divQR($a, $b);
$hasDiscardedFraction = ($remainder !== '0');
$isPositiveOrZero = ($a[0] === '-') === ($b[0] === '-');
- $discardedFractionSign = function() use ($remainder, $b) : int {
+ $discardedFractionSign = function () use ($remainder, $b): int {
$r = $this->abs($this->mul($remainder, '2'));
$b = $this->abs($b);
@@ -446,10 +419,12 @@ abstract readonly class Calculator
if ($hasDiscardedFraction) {
throw RoundingNecessaryException::roundingNecessary();
}
+
break;
case RoundingMode::UP:
$increment = $hasDiscardedFraction;
+
break;
case RoundingMode::DOWN:
@@ -457,32 +432,39 @@ abstract readonly class Calculator
case RoundingMode::CEILING:
$increment = $hasDiscardedFraction && $isPositiveOrZero;
+
break;
case RoundingMode::FLOOR:
$increment = $hasDiscardedFraction && ! $isPositiveOrZero;
+
break;
case RoundingMode::HALF_UP:
$increment = $discardedFractionSign() >= 0;
+
break;
case RoundingMode::HALF_DOWN:
$increment = $discardedFractionSign() > 0;
+
break;
case RoundingMode::HALF_CEILING:
$increment = $isPositiveOrZero ? $discardedFractionSign() >= 0 : $discardedFractionSign() > 0;
+
break;
case RoundingMode::HALF_FLOOR:
$increment = $isPositiveOrZero ? $discardedFractionSign() > 0 : $discardedFractionSign() >= 0;
+
break;
case RoundingMode::HALF_EVEN:
$lastDigit = (int) $quotient[-1];
$lastDigitIsEven = ($lastDigit % 2 === 0);
$increment = $lastDigitIsEven ? $discardedFractionSign() > 0 : $discardedFractionSign() >= 0;
+
break;
}
@@ -501,7 +483,7 @@ abstract readonly class Calculator
*
* @pure
*/
- public function and(string $a, string $b) : string
+ public function and(string $a, string $b): string
{
return $this->bitwise('and', $a, $b);
}
@@ -514,7 +496,7 @@ abstract readonly class Calculator
*
* @pure
*/
- public function or(string $a, string $b) : string
+ public function or(string $a, string $b): string
{
return $this->bitwise('or', $a, $b);
}
@@ -527,11 +509,48 @@ abstract readonly class Calculator
*
* @pure
*/
- public function xor(string $a, string $b) : string
+ public function xor(string $a, string $b): string
{
return $this->bitwise('xor', $a, $b);
}
+ /**
+ * Extracts the sign & digits of the operands.
+ *
+ * @return array{bool, bool, string, string} Whether $a and $b are negative, followed by their digits.
+ *
+ * @pure
+ */
+ final protected function init(string $a, string $b): array
+ {
+ return [
+ $aNeg = ($a[0] === '-'),
+ $bNeg = ($b[0] === '-'),
+
+ $aNeg ? substr($a, 1) : $a,
+ $bNeg ? substr($b, 1) : $b,
+ ];
+ }
+
+ /**
+ * @return array{string, string, string} GCD, X, Y
+ *
+ * @pure
+ */
+ private function gcdExtended(string $a, string $b): array
+ {
+ if ($a === '0') {
+ return [$b, '0', '1'];
+ }
+
+ [$gcd, $x1, $y1] = $this->gcdExtended($this->mod($b, $a), $a);
+
+ $x = $this->sub($y1, $this->mul($this->divQ($b, $a), $x1));
+ $y = $x1;
+
+ return [$gcd, $x, $y];
+ }
+
/**
* Performs a bitwise operation on a decimal number.
*
@@ -541,20 +560,20 @@ abstract readonly class Calculator
*
* @pure
*/
- private function bitwise(string $operator, string $a, string $b) : string
+ private function bitwise(string $operator, string $a, string $b): string
{
[$aNeg, $bNeg, $aDig, $bDig] = $this->init($a, $b);
$aBin = $this->toBinary($aDig);
$bBin = $this->toBinary($bDig);
- $aLen = \strlen($aBin);
- $bLen = \strlen($bBin);
+ $aLen = strlen($aBin);
+ $bLen = strlen($bBin);
if ($aLen > $bLen) {
- $bBin = \str_repeat("\x00", $aLen - $bLen) . $bBin;
+ $bBin = str_repeat("\x00", $aLen - $bLen) . $bBin;
} elseif ($bLen > $aLen) {
- $aBin = \str_repeat("\x00", $bLen - $aLen) . $aBin;
+ $aBin = str_repeat("\x00", $bLen - $aLen) . $aBin;
}
if ($aNeg) {
@@ -590,17 +609,18 @@ abstract readonly class Calculator
*
* @pure
*/
- private function twosComplement(string $number) : string
+ private function twosComplement(string $number): string
{
- $xor = \str_repeat("\xff", \strlen($number));
+ $xor = str_repeat("\xff", strlen($number));
$number ^= $xor;
- for ($i = \strlen($number) - 1; $i >= 0; $i--) {
- $byte = \ord($number[$i]);
+ for ($i = strlen($number) - 1; $i >= 0; $i--) {
+ $byte = ord($number[$i]);
if (++$byte !== 256) {
- $number[$i] = \chr($byte);
+ $number[$i] = chr($byte);
+
break;
}
@@ -621,16 +641,16 @@ abstract readonly class Calculator
*
* @pure
*/
- private function toBinary(string $number) : string
+ private function toBinary(string $number): string
{
$result = '';
while ($number !== '0') {
[$number, $remainder] = $this->divQR($number, '256');
- $result .= \chr((int) $remainder);
+ $result .= chr((int) $remainder);
}
- return \strrev($result);
+ return strrev($result);
}
/**
@@ -640,18 +660,18 @@ abstract readonly class Calculator
*
* @pure
*/
- private function toDecimal(string $bytes) : string
+ private function toDecimal(string $bytes): string
{
$result = '0';
$power = '1';
- for ($i = \strlen($bytes) - 1; $i >= 0; $i--) {
- $index = \ord($bytes[$i]);
+ for ($i = strlen($bytes) - 1; $i >= 0; $i--) {
+ $index = ord($bytes[$i]);
if ($index !== 0) {
- $result = $this->add($result, ($index === 1)
- ? $power
- : $this->mul($power, (string) $index)
+ $result = $this->add(
+ $result,
+ ($index === 1) ? $power : $this->mul($power, (string) $index),
);
}
=====================================
vendor/brick/math/src/Internal/Calculator/BcMathCalculator.php
=====================================
@@ -7,6 +7,15 @@ namespace Brick\Math\Internal\Calculator;
use Brick\Math\Internal\Calculator;
use Override;
+use function bcadd;
+use function bcdiv;
+use function bcmod;
+use function bcmul;
+use function bcpow;
+use function bcpowmod;
+use function bcsqrt;
+use function bcsub;
+
/**
* Calculator implementation built around the bcmath library.
*
@@ -15,59 +24,59 @@ use Override;
final readonly class BcMathCalculator extends Calculator
{
#[Override]
- public function add(string $a, string $b) : string
+ public function add(string $a, string $b): string
{
- return \bcadd($a, $b, 0);
+ return bcadd($a, $b, 0);
}
#[Override]
- public function sub(string $a, string $b) : string
+ public function sub(string $a, string $b): string
{
- return \bcsub($a, $b, 0);
+ return bcsub($a, $b, 0);
}
#[Override]
- public function mul(string $a, string $b) : string
+ public function mul(string $a, string $b): string
{
- return \bcmul($a, $b, 0);
+ return bcmul($a, $b, 0);
}
#[Override]
- public function divQ(string $a, string $b) : string
+ public function divQ(string $a, string $b): string
{
- return \bcdiv($a, $b, 0);
+ return bcdiv($a, $b, 0);
}
#[Override]
- public function divR(string $a, string $b) : string
+ public function divR(string $a, string $b): string
{
- return \bcmod($a, $b, 0);
+ return bcmod($a, $b, 0);
}
#[Override]
- public function divQR(string $a, string $b) : array
+ public function divQR(string $a, string $b): array
{
- $q = \bcdiv($a, $b, 0);
- $r = \bcmod($a, $b, 0);
+ $q = bcdiv($a, $b, 0);
+ $r = bcmod($a, $b, 0);
return [$q, $r];
}
#[Override]
- public function pow(string $a, int $e) : string
+ public function pow(string $a, int $e): string
{
- return \bcpow($a, (string) $e, 0);
+ return bcpow($a, (string) $e, 0);
}
#[Override]
- public function modPow(string $base, string $exp, string $mod) : string
+ public function modPow(string $base, string $exp, string $mod): string
{
- return \bcpowmod($base, $exp, $mod, 0);
+ return bcpowmod($base, $exp, $mod, 0);
}
#[Override]
- public function sqrt(string $n) : string
+ public function sqrt(string $n): string
{
- return \bcsqrt($n, 0);
+ return bcsqrt($n, 0);
}
}
=====================================
vendor/brick/math/src/Internal/Calculator/GmpCalculator.php
=====================================
@@ -8,6 +8,23 @@ use Brick\Math\Internal\Calculator;
use GMP;
use Override;
+use function gmp_add;
+use function gmp_and;
+use function gmp_div_q;
+use function gmp_div_qr;
+use function gmp_div_r;
+use function gmp_gcd;
+use function gmp_init;
+use function gmp_invert;
+use function gmp_mul;
+use function gmp_or;
+use function gmp_pow;
+use function gmp_powm;
+use function gmp_sqrt;
+use function gmp_strval;
+use function gmp_sub;
+use function gmp_xor;
+
/**
* Calculator implementation built around the GMP library.
*
@@ -16,113 +33,113 @@ use Override;
final readonly class GmpCalculator extends Calculator
{
#[Override]
- public function add(string $a, string $b) : string
+ public function add(string $a, string $b): string
{
- return \gmp_strval(\gmp_add($a, $b));
+ return gmp_strval(gmp_add($a, $b));
}
#[Override]
- public function sub(string $a, string $b) : string
+ public function sub(string $a, string $b): string
{
- return \gmp_strval(\gmp_sub($a, $b));
+ return gmp_strval(gmp_sub($a, $b));
}
#[Override]
- public function mul(string $a, string $b) : string
+ public function mul(string $a, string $b): string
{
- return \gmp_strval(\gmp_mul($a, $b));
+ return gmp_strval(gmp_mul($a, $b));
}
#[Override]
- public function divQ(string $a, string $b) : string
+ public function divQ(string $a, string $b): string
{
- return \gmp_strval(\gmp_div_q($a, $b));
+ return gmp_strval(gmp_div_q($a, $b));
}
#[Override]
- public function divR(string $a, string $b) : string
+ public function divR(string $a, string $b): string
{
- return \gmp_strval(\gmp_div_r($a, $b));
+ return gmp_strval(gmp_div_r($a, $b));
}
#[Override]
- public function divQR(string $a, string $b) : array
+ public function divQR(string $a, string $b): array
{
- [$q, $r] = \gmp_div_qr($a, $b);
+ [$q, $r] = gmp_div_qr($a, $b);
/**
* @var GMP $q
* @var GMP $r
*/
return [
- \gmp_strval($q),
- \gmp_strval($r)
+ gmp_strval($q),
+ gmp_strval($r),
];
}
#[Override]
- public function pow(string $a, int $e) : string
+ public function pow(string $a, int $e): string
{
- return \gmp_strval(\gmp_pow($a, $e));
+ return gmp_strval(gmp_pow($a, $e));
}
#[Override]
- public function modInverse(string $x, string $m) : ?string
+ public function modInverse(string $x, string $m): ?string
{
- $result = \gmp_invert($x, $m);
+ $result = gmp_invert($x, $m);
if ($result === false) {
return null;
}
- return \gmp_strval($result);
+ return gmp_strval($result);
}
#[Override]
- public function modPow(string $base, string $exp, string $mod) : string
+ public function modPow(string $base, string $exp, string $mod): string
{
- return \gmp_strval(\gmp_powm($base, $exp, $mod));
+ return gmp_strval(gmp_powm($base, $exp, $mod));
}
#[Override]
- public function gcd(string $a, string $b) : string
+ public function gcd(string $a, string $b): string
{
- return \gmp_strval(\gmp_gcd($a, $b));
+ return gmp_strval(gmp_gcd($a, $b));
}
#[Override]
- public function fromBase(string $number, int $base) : string
+ public function fromBase(string $number, int $base): string
{
- return \gmp_strval(\gmp_init($number, $base));
+ return gmp_strval(gmp_init($number, $base));
}
#[Override]
- public function toBase(string $number, int $base) : string
+ public function toBase(string $number, int $base): string
{
- return \gmp_strval($number, $base);
+ return gmp_strval($number, $base);
}
#[Override]
- public function and(string $a, string $b) : string
+ public function and(string $a, string $b): string
{
- return \gmp_strval(\gmp_and($a, $b));
+ return gmp_strval(gmp_and($a, $b));
}
#[Override]
- public function or(string $a, string $b) : string
+ public function or(string $a, string $b): string
{
- return \gmp_strval(\gmp_or($a, $b));
+ return gmp_strval(gmp_or($a, $b));
}
#[Override]
- public function xor(string $a, string $b) : string
+ public function xor(string $a, string $b): string
{
- return \gmp_strval(\gmp_xor($a, $b));
+ return gmp_strval(gmp_xor($a, $b));
}
#[Override]
- public function sqrt(string $n) : string
+ public function sqrt(string $n): string
{
- return \gmp_strval(\gmp_sqrt($n));
+ return gmp_strval(gmp_sqrt($n));
}
}
=====================================
vendor/brick/math/src/Internal/Calculator/NativeCalculator.php
=====================================
@@ -7,6 +7,20 @@ namespace Brick\Math\Internal\Calculator;
use Brick\Math\Internal\Calculator;
use Override;
+use function assert;
+use function in_array;
+use function intdiv;
+use function is_int;
+use function ltrim;
+use function str_pad;
+use function str_repeat;
+use function strcmp;
+use function strlen;
+use function substr;
+
+use const PHP_INT_SIZE;
+use const STR_PAD_LEFT;
+
/**
* Calculator implementation using only native PHP code.
*
@@ -26,6 +40,7 @@ final readonly class NativeCalculator extends Calculator
/**
* @pure
+ *
* @codeCoverageIgnore
*/
public function __construct()
@@ -37,7 +52,7 @@ final readonly class NativeCalculator extends Calculator
}
#[Override]
- public function add(string $a, string $b) : string
+ public function add(string $a, string $b): string
{
/**
* @var numeric-string $a
@@ -69,13 +84,13 @@ final readonly class NativeCalculator extends Calculator
}
#[Override]
- public function sub(string $a, string $b) : string
+ public function sub(string $a, string $b): string
{
return $this->add($a, $this->neg($b));
}
#[Override]
- public function mul(string $a, string $b) : string
+ public function mul(string $a, string $b): string
{
/**
* @var numeric-string $a
@@ -119,7 +134,7 @@ final readonly class NativeCalculator extends Calculator
}
#[Override]
- public function divQ(string $a, string $b) : string
+ public function divQ(string $a, string $b): string
{
return $this->divQR($a, $b)[0];
}
@@ -131,7 +146,7 @@ final readonly class NativeCalculator extends Calculator
}
#[Override]
- public function divQR(string $a, string $b) : array
+ public function divQR(string $a, string $b): array
{
if ($a === '0') {
return ['0', '0'];
@@ -164,7 +179,7 @@ final readonly class NativeCalculator extends Calculator
return [
(string) $q,
- (string) $r
+ (string) $r,
];
}
}
@@ -185,7 +200,7 @@ final readonly class NativeCalculator extends Calculator
}
#[Override]
- public function pow(string $a, int $e) : string
+ public function pow(string $a, int $e): string
{
if ($e === 0) {
return '1';
@@ -210,10 +225,10 @@ final readonly class NativeCalculator extends Calculator
}
/**
- * Algorithm from: https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/
+ * Algorithm from: https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/.
*/
#[Override]
- public function modPow(string $base, string $exp, string $mod) : string
+ public function modPow(string $base, string $exp, string $mod): string
{
// special case: the algorithm below fails with 0 power 0 mod 1 (returns 1 instead of 0)
if ($base === '0' && $exp === '0' && $mod === '1') {
@@ -245,21 +260,21 @@ final readonly class NativeCalculator extends Calculator
}
/**
- * Adapted from https://cp-algorithms.com/num_methods/roots_newton.html
+ * Adapted from https://cp-algorithms.com/num_methods/roots_newton.html.
*/
#[Override]
- public function sqrt(string $n) : string
+ public function sqrt(string $n): string
{
if ($n === '0') {
return '0';
}
// initial approximation
- $x = \str_repeat('9', \intdiv(\strlen($n), 2) ?: 1);
+ $x = str_repeat('9', intdiv(strlen($n), 2) ?: 1);
$decreased = false;
- for (;;) {
+ for (; ;) {
$nx = $this->divQ($this->add($x, $this->divQ($n, $x)), '2');
if ($x === $nx || $this->cmp($nx, $x) > 0 && $decreased) {
@@ -278,14 +293,14 @@ final readonly class NativeCalculator extends Calculator
*
* @pure
*/
- private function doAdd(string $a, string $b) : string
+ private function doAdd(string $a, string $b): string
{
[$a, $b, $length] = $this->pad($a, $b);
$carry = 0;
$result = '';
- for ($i = $length - $this->maxDigits;; $i -= $this->maxDigits) {
+ for ($i = $length - $this->maxDigits; ; $i -= $this->maxDigits) {
$blockLength = $this->maxDigits;
if ($i < 0) {
@@ -294,20 +309,20 @@ final readonly class NativeCalculator extends Calculator
}
/** @var numeric-string $blockA */
- $blockA = \substr($a, $i, $blockLength);
+ $blockA = substr($a, $i, $blockLength);
/** @var numeric-string $blockB */
- $blockB = \substr($b, $i, $blockLength);
+ $blockB = substr($b, $i, $blockLength);
$sum = (string) ($blockA + $blockB + $carry);
- $sumLength = \strlen($sum);
+ $sumLength = strlen($sum);
if ($sumLength > $blockLength) {
- $sum = \substr($sum, 1);
+ $sum = substr($sum, 1);
$carry = 1;
} else {
if ($sumLength < $blockLength) {
- $sum = \str_repeat('0', $blockLength - $sumLength) . $sum;
+ $sum = str_repeat('0', $blockLength - $sumLength) . $sum;
}
$carry = 0;
}
@@ -331,7 +346,7 @@ final readonly class NativeCalculator extends Calculator
*
* @pure
*/
- private function doSub(string $a, string $b) : string
+ private function doSub(string $a, string $b): string
{
if ($a === $b) {
return '0';
@@ -355,7 +370,7 @@ final readonly class NativeCalculator extends Calculator
$complement = 10 ** $this->maxDigits;
- for ($i = $length - $this->maxDigits;; $i -= $this->maxDigits) {
+ for ($i = $length - $this->maxDigits; ; $i -= $this->maxDigits) {
$blockLength = $this->maxDigits;
if ($i < 0) {
@@ -364,10 +379,10 @@ final readonly class NativeCalculator extends Calculator
}
/** @var numeric-string $blockA */
- $blockA = \substr($a, $i, $blockLength);
+ $blockA = substr($a, $i, $blockLength);
/** @var numeric-string $blockB */
- $blockB = \substr($b, $i, $blockLength);
+ $blockB = substr($b, $i, $blockLength);
$sum = $blockA - $blockB - $carry;
@@ -379,10 +394,10 @@ final readonly class NativeCalculator extends Calculator
}
$sum = (string) $sum;
- $sumLength = \strlen($sum);
+ $sumLength = strlen($sum);
if ($sumLength < $blockLength) {
- $sum = \str_repeat('0', $blockLength - $sumLength) . $sum;
+ $sum = str_repeat('0', $blockLength - $sumLength) . $sum;
}
$result = $sum . $result;
@@ -395,7 +410,7 @@ final readonly class NativeCalculator extends Calculator
// Carry cannot be 1 when the loop ends, as a > b
assert($carry === 0);
- $result = \ltrim($result, '0');
+ $result = ltrim($result, '0');
if ($invert) {
$result = $this->neg($result);
@@ -409,17 +424,17 @@ final readonly class NativeCalculator extends Calculator
*
* @pure
*/
- private function doMul(string $a, string $b) : string
+ private function doMul(string $a, string $b): string
{
- $x = \strlen($a);
- $y = \strlen($b);
+ $x = strlen($a);
+ $y = strlen($b);
- $maxDigits = \intdiv($this->maxDigits, 2);
+ $maxDigits = intdiv($this->maxDigits, 2);
$complement = 10 ** $maxDigits;
$result = '0';
- for ($i = $x - $maxDigits;; $i -= $maxDigits) {
+ for ($i = $x - $maxDigits; ; $i -= $maxDigits) {
$blockALength = $maxDigits;
if ($i < 0) {
@@ -427,12 +442,12 @@ final readonly class NativeCalculator extends Calculator
$i = 0;
}
- $blockA = (int) \substr($a, $i, $blockALength);
+ $blockA = (int) substr($a, $i, $blockALength);
$line = '';
$carry = 0;
- for ($j = $y - $maxDigits;; $j -= $maxDigits) {
+ for ($j = $y - $maxDigits; ; $j -= $maxDigits) {
$blockBLength = $maxDigits;
if ($j < 0) {
@@ -440,14 +455,14 @@ final readonly class NativeCalculator extends Calculator
$j = 0;
}
- $blockB = (int) \substr($b, $j, $blockBLength);
+ $blockB = (int) substr($b, $j, $blockBLength);
$mul = $blockA * $blockB + $carry;
$value = $mul % $complement;
$carry = ($mul - $value) / $complement;
$value = (string) $value;
- $value = \str_pad($value, $maxDigits, '0', STR_PAD_LEFT);
+ $value = str_pad($value, $maxDigits, '0', STR_PAD_LEFT);
$line = $value . $line;
@@ -460,10 +475,10 @@ final readonly class NativeCalculator extends Calculator
$line = $carry . $line;
}
- $line = \ltrim($line, '0');
+ $line = ltrim($line, '0');
if ($line !== '') {
- $line .= \str_repeat('0', $x - $blockALength - $i);
+ $line .= str_repeat('0', $x - $blockALength - $i);
$result = $this->add($result, $line);
}
@@ -482,7 +497,7 @@ final readonly class NativeCalculator extends Calculator
*
* @pure
*/
- private function doDiv(string $a, string $b) : array
+ private function doDiv(string $a, string $b): array
{
$cmp = $this->doCmp($a, $b);
@@ -490,8 +505,8 @@ final readonly class NativeCalculator extends Calculator
return ['0', $a];
}
- $x = \strlen($a);
- $y = \strlen($b);
+ $x = strlen($a);
+ $y = strlen($b);
// we now know that a >= b && x >= y
@@ -503,20 +518,20 @@ final readonly class NativeCalculator extends Calculator
$nb = $b * 1; // cast to number
// performance optimization in cases where the remainder will never cause int overflow
if (is_int(($nb - 1) * 10 + 9)) {
- $r = (int) \substr($a, 0, $z - 1);
+ $r = (int) substr($a, 0, $z - 1);
for ($i = $z - 1; $i < $x; $i++) {
$n = $r * 10 + (int) $a[$i];
/** @var int $nb */
- $q .= \intdiv($n, $nb);
+ $q .= intdiv($n, $nb);
$r = $n % $nb;
}
- return [\ltrim($q, '0') ?: '0', (string) $r];
+ return [ltrim($q, '0') ?: '0', (string) $r];
}
- for (;;) {
- $focus = \substr($a, 0, $z);
+ for (; ;) {
+ $focus = substr($a, 0, $z);
$cmp = $this->doCmp($focus, $b);
@@ -528,7 +543,7 @@ final readonly class NativeCalculator extends Calculator
$z++;
}
- $zeros = \str_repeat('0', $x - $z);
+ $zeros = str_repeat('0', $x - $z);
$q = $this->add($q, '1' . $zeros);
$a = $this->sub($a, $b . $zeros);
@@ -539,7 +554,7 @@ final readonly class NativeCalculator extends Calculator
break;
}
- $x = \strlen($a);
+ $x = strlen($a);
if ($x < $y) { // remainder < dividend
break;
@@ -558,10 +573,10 @@ final readonly class NativeCalculator extends Calculator
*
* @pure
*/
- private function doCmp(string $a, string $b) : int
+ private function doCmp(string $a, string $b): int
{
- $x = \strlen($a);
- $y = \strlen($b);
+ $x = strlen($a);
+ $y = strlen($b);
$cmp = $x <=> $y;
@@ -569,7 +584,7 @@ final readonly class NativeCalculator extends Calculator
return $cmp;
}
- return \strcmp($a, $b) <=> 0; // enforce -1|0|1
+ return strcmp($a, $b) <=> 0; // enforce -1|0|1
}
/**
@@ -581,19 +596,19 @@ final readonly class NativeCalculator extends Calculator
*
* @pure
*/
- private function pad(string $a, string $b) : array
+ private function pad(string $a, string $b): array
{
- $x = \strlen($a);
- $y = \strlen($b);
+ $x = strlen($a);
+ $y = strlen($b);
if ($x > $y) {
- $b = \str_repeat('0', $x - $y) . $b;
+ $b = str_repeat('0', $x - $y) . $b;
return [$a, $b, $x];
}
if ($x < $y) {
- $a = \str_repeat('0', $y - $x) . $a;
+ $a = str_repeat('0', $y - $x) . $a;
return [$a, $b, $y];
}
=====================================
vendor/brick/math/src/Internal/CalculatorRegistry.php
=====================================
@@ -25,7 +25,7 @@ final class CalculatorRegistry
*
* @param Calculator|null $calculator The calculator instance, or null to revert to autodetect.
*/
- final public static function set(?Calculator $calculator) : void
+ final public static function set(?Calculator $calculator): void
{
self::$instance = $calculator;
}
@@ -40,7 +40,7 @@ final class CalculatorRegistry
*
* @pure
*/
- final public static function get() : Calculator
+ final public static function get(): Calculator
{
/** @phpstan-ignore impure.staticPropertyAccess */
if (self::$instance === null) {
@@ -56,9 +56,10 @@ final class CalculatorRegistry
* Returns the fastest available Calculator implementation.
*
* @pure
+ *
* @codeCoverageIgnore
*/
- private static function detect() : Calculator
+ private static function detect(): Calculator
{
if (extension_loaded('gmp')) {
return new Calculator\GmpCalculator();
=====================================
vendor/brick/math/tools/ecs/composer.json
=====================================
@@ -0,0 +1,10 @@
+{
+ "require": {
+ "brick/coding-standard": "v2"
+ },
+ "config": {
+ "allow-plugins": {
+ "dealerdirect/phpcodesniffer-composer-installer": false
+ }
+ }
+}
=====================================
vendor/brick/math/tools/ecs/ecs.php
=====================================
@@ -0,0 +1,33 @@
+<?php
+
+declare(strict_types=1);
+
+use PhpCsFixer\Fixer\ClassNotation\OrderedTypesFixer;
+use PhpCsFixer\Fixer\Phpdoc\PhpdocTypesOrderFixer;
+use SlevomatCodingStandard\Sniffs\Whitespaces\DuplicateSpacesSniff;
+use Symplify\EasyCodingStandard\Config\ECSConfig;
+
+return static function (ECSConfig $ecsConfig): void {
+ $ecsConfig->import(__DIR__ . '/vendor/brick/coding-standard/ecs.php');
+
+ $libRootPath = realpath(__DIR__ . '/../..');
+
+ $ecsConfig->paths(
+ [
+ $libRootPath . '/src',
+ $libRootPath . '/tests',
+ $libRootPath . '/phpunit.php',
+ $libRootPath . '/random-tests.php',
+ __FILE__,
+ ],
+ );
+
+ $ecsConfig->skip([
+ // Allows alignment in test providers
+ DuplicateSpacesSniff::class => [$libRootPath . '/tests'],
+
+ // We want to keep BigNumber|int|float|string order
+ OrderedTypesFixer::class => null,
+ PhpdocTypesOrderFixer::class => null,
+ ]);
+};
=====================================
vendor/composer/installed.json
=====================================
@@ -2,17 +2,17 @@
"packages": [
{
"name": "brick/math",
- "version": "0.14.0",
- "version_normalized": "0.14.0.0",
+ "version": "0.14.1",
+ "version_normalized": "0.14.1.0",
"source": {
"type": "git",
"url": "https://github.com/brick/math.git",
- "reference": "113a8ee2656b882d4c3164fa31aa6e12cbb7aaa2"
+ "reference": "f05858549e5f9d7bb45875a75583240a38a281d0"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/brick/math/zipball/113a8ee2656b882d4c3164fa31aa6e12cbb7aaa2",
- "reference": "113a8ee2656b882d4c3164fa31aa6e12cbb7aaa2",
+ "url": "https://api.github.com/repos/brick/math/zipball/f05858549e5f9d7bb45875a75583240a38a281d0",
+ "reference": "f05858549e5f9d7bb45875a75583240a38a281d0",
"shasum": ""
},
"require": {
@@ -23,7 +23,7 @@
"phpstan/phpstan": "2.1.22",
"phpunit/phpunit": "^11.5"
},
- "time": "2025-08-29T12:40:03+00:00",
+ "time": "2025-11-24T14:40:29+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
@@ -53,7 +53,7 @@
],
"support": {
"issues": "https://github.com/brick/math/issues",
- "source": "https://github.com/brick/math/tree/0.14.0"
+ "source": "https://github.com/brick/math/tree/0.14.1"
},
"funding": [
{
@@ -489,17 +489,17 @@
},
{
"name": "ipl/html",
- "version": "v0.9.0",
- "version_normalized": "0.9.0.0",
+ "version": "v0.9.1",
+ "version_normalized": "0.9.1.0",
"source": {
"type": "git",
"url": "https://github.com/Icinga/ipl-html.git",
- "reference": "4ab3fb11794434d455b9db5b6c81901df34e10cf"
+ "reference": "a0cbfa405f9be9650141fd5eee894e423e3e4999"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/Icinga/ipl-html/zipball/4ab3fb11794434d455b9db5b6c81901df34e10cf",
- "reference": "4ab3fb11794434d455b9db5b6c81901df34e10cf",
+ "url": "https://api.github.com/repos/Icinga/ipl-html/zipball/a0cbfa405f9be9650141fd5eee894e423e3e4999",
+ "reference": "a0cbfa405f9be9650141fd5eee894e423e3e4999",
"shasum": ""
},
"require": {
@@ -515,7 +515,7 @@
"ipl/stdlib": "dev-main",
"ipl/validator": "dev-main"
},
- "time": "2025-11-13T15:18:42+00:00",
+ "time": "2025-11-27T15:07:15+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
@@ -534,7 +534,7 @@
],
"support": {
"issues": "https://github.com/Icinga/ipl-html/issues",
- "source": "https://github.com/Icinga/ipl-html/tree/v0.9.0"
+ "source": "https://github.com/Icinga/ipl-html/tree/v0.9.1"
},
"install-path": "../ipl/html"
},
=====================================
vendor/composer/installed.php
=====================================
@@ -11,9 +11,9 @@
),
'versions' => array(
'brick/math' => array(
- 'pretty_version' => '0.14.0',
- 'version' => '0.14.0.0',
- 'reference' => '113a8ee2656b882d4c3164fa31aa6e12cbb7aaa2',
+ 'pretty_version' => '0.14.1',
+ 'version' => '0.14.1.0',
+ 'reference' => 'f05858549e5f9d7bb45875a75583240a38a281d0',
'type' => 'library',
'install_path' => __DIR__ . '/../brick/math',
'aliases' => array(),
@@ -83,9 +83,9 @@
'dev_requirement' => false,
),
'ipl/html' => array(
- 'pretty_version' => 'v0.9.0',
- 'version' => '0.9.0.0',
- 'reference' => '4ab3fb11794434d455b9db5b6c81901df34e10cf',
+ 'pretty_version' => 'v0.9.1',
+ 'version' => '0.9.1.0',
+ 'reference' => 'a0cbfa405f9be9650141fd5eee894e423e3e4999',
'type' => 'library',
'install_path' => __DIR__ . '/../ipl/html',
'aliases' => array(),
=====================================
vendor/ipl/html/src/FormElement/BaseFormElement.php
=====================================
@@ -130,8 +130,15 @@ abstract class BaseFormElement extends BaseHtmlElement implements FormElement, V
{
$this->name = $name;
- // Name is always escaped
- $this->escapedName = Form::escapeReservedChars($name);
+ // TODO: phpdoc always expressed that only strings are accepted, but some usages passed null despite that.
+ // The isset check is only a compatibility measure to not break BC. Remove once the interface actually
+ // requires a string. And don't ever dare to allow null (`?string`) due to this check!!!1
+ if (isset($this->name)) {
+ // Name is always escaped
+ $this->escapedName = Form::escapeReservedChars($name);
+ } else {
+ $this->escapedName = '';
+ }
return $this;
}
View it on GitLab: https://salsa.debian.org/nagios-team/icinga-php-library/-/compare/c1e2e9cd7dc54fa6b243ece38569715094b3c413...b4fb234f6caa5bbd1158c8f2f3112029d8c8f2f1
--
View it on GitLab: https://salsa.debian.org/nagios-team/icinga-php-library/-/compare/c1e2e9cd7dc54fa6b243ece38569715094b3c413...b4fb234f6caa5bbd1158c8f2f3112029d8c8f2f1
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-nagios-changes/attachments/20251127/62b31db0/attachment-0001.htm>
More information about the pkg-nagios-changes
mailing list