From aaae75bc93b38f4ac2778d97a6c7983d8c58074d Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 13 Sep 2022 12:47:30 +0300 Subject: [PATCH] feat(expressions): types fixes --- .../core/Parsers/Expressions/MathExpression.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/flextype/core/Parsers/Expressions/MathExpression.php b/src/flextype/core/Parsers/Expressions/MathExpression.php index 2a526294..abe7ca5b 100644 --- a/src/flextype/core/Parsers/Expressions/MathExpression.php +++ b/src/flextype/core/Parsers/Expressions/MathExpression.php @@ -20,15 +20,26 @@ use Symfony\Component\ExpressionLanguage\ExpressionFunction; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; use function Flextype\registry; +use const PHP_ROUND_HALF_EVEN; use const PHP_ROUND_HALF_UP; +use const PHP_ROUND_HALF_DOWN; +use const PHP_ROUND_HALF_ODD; +/** + * @phpstan-param self::ROUND_* $mode + */ class MathExpression implements ExpressionFunctionProviderInterface { + public const ROUND_HALF_EVEN = PHP_ROUND_HALF_EVEN; + public const ROUND_HALF_DOWN = PHP_ROUND_HALF_DOWN; + public const ROUND_HALF_ODD = PHP_ROUND_HALF_ODD; + public const ROUND_HALF_UP = PHP_ROUND_HALF_UP; + public function getFunctions() { return [ new ExpressionFunction('abs', static fn (int|float $num) => '\abs($num)', static fn (array $arguments, int|float $num): mixed => \abs($num)), - new ExpressionFunction('round', static fn (int|float $num, int $precision = 0, int $mode = PHP_ROUND_HALF_UP): mixed => '\round($num, $precision, $mode)', static fn (array $arguments, int|float $num, int $precision = 0, int $mode = PHP_ROUND_HALF_UP): mixed => \round($num, $precision, $mode)), + new ExpressionFunction('round', static fn (int|float $num, int $precision = 0, int $mode = self::PHP_ROUND_HALF_UP): mixed => '\round($num, $precision, $mode)', static fn (array $arguments, int|float $num, int $precision = 0, int $mode = self::PHP_ROUND_HALF_UP): mixed => \round($num, $precision, $mode)), new ExpressionFunction('ceil', static fn (int|float $num) => '\ceil($num)', static fn (array $arguments, int|float $num): mixed => \ceil($num)), new ExpressionFunction('floor', static fn (int|float $num) => '\floor($num)', static fn (array $arguments, int|float $num): mixed => \floor($num)), new ExpressionFunction('min', static fn (mixed ...$values) => '\min($values)', static fn (array $arguments, mixed ...$values): mixed => \min($values)),