diff --git a/src/Type/Php/IdateFunctionReturnTypeHelper.php b/src/Type/Php/IdateFunctionReturnTypeHelper.php index 00541b75b5..c9c0f90c6e 100644 --- a/src/Type/Php/IdateFunctionReturnTypeHelper.php +++ b/src/Type/Php/IdateFunctionReturnTypeHelper.php @@ -29,13 +29,16 @@ public function getTypeFromFormatType(Type $formatType): ?Type public function buildReturnTypeFromFormat(string $formatString): Type { - // see https://www.php.net/idate + // see https://www.php.net/idate and https://www.php.net/manual/de/datetime.format switch ($formatString) { case 'd': + case 'j': return IntegerRangeType::fromInterval(1, 31); case 'h': + case 'g': return IntegerRangeType::fromInterval(1, 12); case 'H': + case 'G': return IntegerRangeType::fromInterval(0, 23); case 'i': return IntegerRangeType::fromInterval(0, 59); @@ -44,6 +47,7 @@ public function buildReturnTypeFromFormat(string $formatString): Type case 'L': return IntegerRangeType::fromInterval(0, 1); case 'm': + case 'n': return IntegerRangeType::fromInterval(1, 12); case 'N': return IntegerRangeType::fromInterval(1, 7); diff --git a/tests/PHPStan/Analyser/nsrt/idate.php b/tests/PHPStan/Analyser/nsrt/idate.php index 74b3e363b1..9bf55364ee 100644 --- a/tests/PHPStan/Analyser/nsrt/idate.php +++ b/tests/PHPStan/Analyser/nsrt/idate.php @@ -13,6 +13,7 @@ class Foo */ public function doFoo(string $string, string $hour, string $format): void { + assertType('int<1, 31>', idate('j')); assertType('int<1, 7>', idate('N')); assertType('int', idate('Y')); assertType('false', idate('wrong'));