From 73ea74149ce5cab49c4d24f12e24fd3b5f1620a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C3=B8=20Lonyai?= Date: Wed, 17 Jun 2026 16:01:18 +0200 Subject: [PATCH] Improves PHP 8.5 compatibility --- php-toolkit/Common/RationalNumber.php | 10 +++++----- .../Doctrine/ORM/EntitySerializer/EntitySerializer.php | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/php-toolkit/Common/RationalNumber.php b/php-toolkit/Common/RationalNumber.php index ef630d0..700bbde 100644 --- a/php-toolkit/Common/RationalNumber.php +++ b/php-toolkit/Common/RationalNumber.php @@ -131,12 +131,12 @@ public static function fromRational(Rational $rational): static */ public function round(int $precision = 0): static { - $rollIn = pow(10, $precision + 1); + $rollIn = 10 ** ($precision + 1); $roundInc = ($this->getWholePart() + $this->getNumerator() < 0) ? -5 : 5; $integralPart = $this->getWholePart(); // this should in principle reduce the chance of overflow ... $fractional = $this->sub($integralPart); - return new static($integralPart, intdiv($fractional->mul($rollIn)->whole + $roundInc, 10), $rollIn / 10); + return new static($integralPart, intdiv((int)($fractional->mul($rollIn)->whole + $roundInc), 10), (int)($rollIn / 10)); } /** @@ -189,8 +189,8 @@ public function toDecimal(int $scale = -1, int $precision = 0):string $result .= '.' . $fractionalPart; return $sign < 0 ? '-' . $result : $result; } - $rollIn = pow(10, $scale + 1); - $fixedPoint = str_pad(intdiv($abs->mul($rollIn)->whole + 5, 10), $scale + 1, '0', STR_PAD_LEFT); + $rollIn = 10 ** ($scale + 1); + $fixedPoint = str_pad((string)intdiv((int)($abs->mul($rollIn)->whole + 5), 10), $scale + 1, '0', STR_PAD_LEFT); $integralPart = substr($fixedPoint, 0, -$scale); $fractionalPart = substr($fixedPoint, -$scale); $result = $integralPart . '.' . $fractionalPart; @@ -229,7 +229,7 @@ public static function fromDecimal(string|int $decimal): static $sign = $matches[1][0] == '-' ? -1 : 1; $integralPart = empty($matches[2]) ? 0 : (int)$matches[2][0]; $numerator = empty($matches[3]) ? 0 : (int)$matches[3][0]; - $denominator = pow(10, strlen($matches[3][0] ?? '')); + $denominator = 10 ** strlen($matches[3][0] ?? ''); return new static($sign * $integralPart, $sign * $numerator, $denominator); } diff --git a/php-toolkit/Doctrine/ORM/EntitySerializer/EntitySerializer.php b/php-toolkit/Doctrine/ORM/EntitySerializer/EntitySerializer.php index ed70a95..0404e91 100644 --- a/php-toolkit/Doctrine/ORM/EntitySerializer/EntitySerializer.php +++ b/php-toolkit/Doctrine/ORM/EntitySerializer/EntitySerializer.php @@ -159,6 +159,7 @@ private function stripCommonPrefix(string $entityName): string if (str_starts_with($entityName, $this->commonPrefix)) { return substr($entityName, strlen($this->commonPrefix)); } + return $this->commonPrefix; } /**