| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace ApiGen\Info\Expr; |
| 4: | |
| 5: | use ApiGen\Info\ExprInfo; |
| 6: | |
| 7: | use function is_finite; |
| 8: | use function json_encode; |
| 9: | use function str_contains; |
| 10: | |
| 11: | use const JSON_THROW_ON_ERROR; |
| 12: | |
| 13: | |
| 14: | class FloatExprInfo implements ExprInfo |
| 15: | { |
| 16: | public function __construct( |
| 17: | public float $value, |
| 18: | public string $raw, |
| 19: | ) { |
| 20: | } |
| 21: | |
| 22: | |
| 23: | public function toString(): string |
| 24: | { |
| 25: | if (!is_finite($this->value)) { |
| 26: | return (string) $this->value; |
| 27: | } |
| 28: | |
| 29: | $json = json_encode($this->value, JSON_THROW_ON_ERROR); |
| 30: | return str_contains($json, '.') ? $json : "$json.0"; |
| 31: | } |
| 32: | } |
| 33: | |