Skip to content

Commit

Permalink
Add raw decimal value
Browse files Browse the repository at this point in the history
  • Loading branch information
SerafimArts committed Nov 9, 2024
1 parent 504821f commit ad32a85
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/Node/Literal/IntLiteralNode.php
Original file line number Diff line number Diff line change
@@ -13,26 +13,39 @@
*/
class IntLiteralNode extends LiteralNode implements ParsableLiteralNodeInterface
{
/**
* @var numeric-string
*/
public readonly string $decimal;

/**
* @param numeric-string|null $decimal
*/
public function __construct(
public readonly int $value,
?string $raw = null,
?string $decimal = null,
) {
$this->decimal = $decimal ?? (string) $this->value;

parent::__construct($raw ?? (string) $this->value);
}

public static function parse(string $value): static
{
[$negative, $numeric] = self::split($value);
[$negative, $decimal] = self::split($value);

$converted = '-' . $decimal;

if ($negative) {
if ((string) \PHP_INT_MIN === '-' . $numeric) {
return new static(\PHP_INT_MIN, $value);
if ((string) \PHP_INT_MIN === '-' . $decimal) {
return new static(\PHP_INT_MIN, $value, $converted);
}

return new static((int) ('-' . $numeric), $value);
return new static((int) ('-' . $decimal), $value, $converted);
}

return new static((int) $numeric, $value);
return new static((int) $decimal, $value, $converted);
}

/**
@@ -65,6 +78,14 @@ private static function split(string $literal): array
return [$negative, $literal];
}

/**
* @return numeric-string
*/
public function getValueAsDecimalString(): string
{
return $this->decimal;
}

public function getValue(): int
{
return $this->value;

0 comments on commit ad32a85

Please sign in to comment.