Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix
  • Loading branch information
VincentLanglet committed Apr 7, 2026
commit 904c51ce0f9fd8338271e694a632dab7926f7e95
17 changes: 14 additions & 3 deletions src/Type/Php/DateTimeModifyReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\NeverType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use Throwable;
Expand Down Expand Up @@ -41,7 +42,7 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): ?Type
{
$args = $methodCall->getArgs();
if (count($methodCall->getArgs()) < 1) {
if (count($args) < 1) {
return null;
}

Expand Down Expand Up @@ -79,9 +80,19 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method

return null;
} elseif ($hasDateTime) {
$variant = ParametersAcceptorSelector::selectFromArgs($scope, $args, $methodReflection->getVariants());
$callerType = $scope->getType($methodCall->var);
Comment thread
VincentLanglet marked this conversation as resolved.

return TypeCombinator::remove($variant->getReturnType(), new ConstantBooleanType(false));
$dateTimeInterfaceType = new ObjectType(DateTimeInterface::class);
if ($dateTimeInterfaceType->isSuperTypeOf($callerType)->yes()) {
return $callerType;
}
foreach ($callerType->getObjectClassNames() as $className) {
if (!$dateTimeInterfaceType->isSuperTypeOf(new ObjectType($className))->yes()) {
$callerType = TypeCombinator::remove($callerType, new ObjectType($className));
}
}

return $callerType;
}

if ($this->phpVersion->hasDateTimeExceptions()) {
Expand Down