Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Type/Php/IdateFunctionReturnTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/nsrt/idate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Loading