diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/DateTimeModifyReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/DateTimeModifyReturnTypeProvider.php index 83d32a7ca..b693d788f 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/DateTimeModifyReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/DateTimeModifyReturnTypeProvider.php @@ -8,7 +8,6 @@ use Psalm\Plugin\EventHandler\Event\MethodReturnTypeProviderEvent; use Psalm\Plugin\EventHandler\MethodReturnTypeProviderInterface; use Psalm\Type; use Psalm\Type\Atomic\TLiteralString; -use Psalm\Type\Atomic\TNamedObject; use Psalm\Type\Union; /** @@ -57,11 +56,7 @@ class DateTimeModifyReturnTypeProvider implements MethodReturnTypeProviderInterf return Type::getFalse(); } if ($has_date_time && !$has_false) { - return Type::intersectUnionTypes( - Type::parseString($event->getCalledFqClasslikeName() ?? $event->getFqClasslikeName()), - new Union([new TNamedObject('static')]), - $statements_source->getCodebase(), - ); + return Type::parseString($event->getCalledFqClasslikeName() ?? $event->getFqClasslikeName()); } return null; diff --git a/tests/DateTimeTest.php b/tests/DateTimeTest.php index 3d6405684..afaede82e 100644 --- a/tests/DateTimeTest.php +++ b/tests/DateTimeTest.php @@ -44,8 +44,8 @@ class DateTimeTest extends TestCase $b = $dateTimeImmutable->modify(getString()); ', 'assertions' => [ - '$a' => 'DateTime&static', - '$b' => 'DateTimeImmutable&static', + '$a' => 'DateTime', + '$b' => 'DateTimeImmutable', ], ], 'modifyWithInvalidConstant' => [ @@ -88,6 +88,18 @@ class DateTimeTest extends TestCase '$b' => 'DateTimeImmutable|false', ], ], + 'otherMethodAfterModify' => [ + 'code' => 'modify("+1 day")->setTime(0, 0); + $b = $dateTimeImmutable->modify("+1 day")->setTime(0, 0); + ', + 'assertions' => [ + '$a' => 'DateTime|false', + '$b' => 'DateTimeImmutable', + ], + ], 'modifyStaticReturn' => [ 'code' => 'modify("+7 days"); ', 'assertions' => [ - '$mod' => 'Subclass&static', + '$mod' => 'Subclass', + ], + ], + 'otherMethodAfterModifyStaticReturn' => [ + 'code' => 'modify("+1 day")->setTime(0, 0); + ', + 'assertions' => [ + '$mod' => 'Subclass', + ], + ], + 'formatAfterModify' => [ + 'code' => 'modify("+1 day")->format("Y-m-d"); + $b = $dateTimeImmutable->modify("+1 day")->format("Y-m-d"); + ', + 'assertions' => [ + '$a' => 'false|string', + '$b' => 'string', + ], + ], + 'formatAfterModifyStaticReturn' => [ + 'code' => 'modify("+1 day")->format("Y-m-d"); + ', + 'assertions' => [ + '$format' => 'string', ], ], ]; diff --git a/tests/MethodCallTest.php b/tests/MethodCallTest.php index e2030863f..c5dd9c762 100644 --- a/tests/MethodCallTest.php +++ b/tests/MethodCallTest.php @@ -263,7 +263,7 @@ class MethodCallTest extends TestCase $b = (new DateTimeImmutable())->modify("+3 hours");', 'assertions' => [ '$yesterday' => 'MyDate', - '$b' => 'DateTimeImmutable&static', + '$b' => 'DateTimeImmutable', ], ], 'magicCall' => [