Skip to content

Commit 9fdf3ec

Browse files
authored
Force numeric-string return type in BigDecimal::__toString() and BigInteger::__toString() (#90)
1 parent efe64d2 commit 9fdf3ec

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/BigDecimal.php

+5
Original file line numberDiff line numberDiff line change
@@ -689,15 +689,20 @@ public function toFloat() : float
689689
return (float) (string) $this;
690690
}
691691

692+
/**
693+
* @return numeric-string
694+
*/
692695
#[Override]
693696
public function __toString() : string
694697
{
695698
if ($this->scale === 0) {
699+
/** @var numeric-string */
696700
return $this->value;
697701
}
698702

699703
$value = $this->getUnscaledValueWithLeadingZeros();
700704

705+
/** @var numeric-string */
701706
return \substr($value, 0, -$this->scale) . '.' . \substr($value, -$this->scale);
702707
}
703708

src/BigInteger.php

+4
Original file line numberDiff line numberDiff line change
@@ -1023,9 +1023,13 @@ public function toBytes(bool $signed = true) : string
10231023
return \hex2bin($hex);
10241024
}
10251025

1026+
/**
1027+
* @return numeric-string
1028+
*/
10261029
#[Override]
10271030
public function __toString() : string
10281031
{
1032+
/** @var numeric-string */
10291033
return $this->value;
10301034
}
10311035

0 commit comments

Comments
 (0)