From 3abfc169ce42a723ccdc15257ed6412e82e951f8 Mon Sep 17 00:00:00 2001 From: Julien Falque Date: Fri, 26 Jul 2024 10:27:36 +0200 Subject: [PATCH] fixup! Improve `abs()` return type --- tests/PHPStan/Analyser/nsrt/abs.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/PHPStan/Analyser/nsrt/abs.php b/tests/PHPStan/Analyser/nsrt/abs.php index 69c7a08a0c..eb644eb4bd 100644 --- a/tests/PHPStan/Analyser/nsrt/abs.php +++ b/tests/PHPStan/Analyser/nsrt/abs.php @@ -92,6 +92,10 @@ public function constantInteger(int $int): void /** @var -1 $int */ assertType('1', abs($int)); + + assertType('123', abs(123)); + + assertType('123', abs(-123)); } public function mixedIntegerUnion(int $int): void @@ -119,6 +123,10 @@ public function constantFloat(float $float): void /** @var -1.0 $float */ assertType('1.0', abs($float)); + + assertType('123.4', abs(123.4)); + + assertType('123.4', abs(-123.4)); } public function string(string $string): void @@ -134,6 +142,19 @@ public function string(string $string): void /** @var '-1'|'-2.0'|'3.0'|'4' $string */ assertType('1|2.0|3.0|4', abs($string)); + + /** @var literal-string $string */ + assertType('float|int<0, max>', abs($string)); + + assertType('123', abs('123')); + + assertType('123', abs('-123')); + + assertType('123.0', abs('123.0')); + + assertType('123.0', abs('-123.0')); + + assertType('float|int<0, max>', abs('foo')); } public function mixedUnion(mixed $value): void @@ -182,6 +203,13 @@ public function invalidType(mixed $nonInt): void /** @var \DateTime $nonInt */ assertType('float|int<0, max>', abs($nonInt)); + + /** @var null $nonInt */ + assertType('0', abs($nonInt)); + + assertType('float|int<0, max>', abs('foo')); + + assertType('0', abs(null)); } }