Skip to content

Commit

Permalink
fixup! Improve abs() return type
Browse files Browse the repository at this point in the history
  • Loading branch information
julienfalque committed Jul 26, 2024
1 parent 076ead6 commit 3abfc16
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/PHPStan/Analyser/nsrt/abs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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));
}

}

0 comments on commit 3abfc16

Please sign in to comment.