Skip to content

Commit a07ca20

Browse files
Improvements
1 parent 15ca5a8 commit a07ca20

2 files changed

Lines changed: 20 additions & 20 deletions

File tree

src/Analyser/ExprHandler/Helper/MethodCallReturnTypeHelper.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,23 @@ public function methodCallReturnType(
9393
}
9494

9595
if (count($resolvedTypes) > 0) {
96-
$remainingType = $typeWithMethod;
97-
foreach ($handledClassNames as $handledClassName) {
98-
$remainingType = TypeCombinator::remove($remainingType, new ObjectType($handledClassName));
99-
}
100-
if ($remainingType->hasMethod($methodName)->yes()) {
101-
$remainingMethod = $remainingType->getMethod($methodName, $scope);
102-
$remainingParametersAcceptor = ParametersAcceptorSelector::selectFromArgs(
103-
$scope,
104-
$methodCall->getArgs(),
105-
$remainingMethod->getVariants(),
106-
$remainingMethod->getNamedArgumentsVariants(),
107-
);
108-
$resolvedTypes[] = $remainingParametersAcceptor->getReturnType();
96+
if (count($allClassNames) !== count($handledClassNames)) {
97+
$remainingType = $typeWithMethod;
98+
foreach ($handledClassNames as $handledClassName) {
99+
$remainingType = TypeCombinator::remove($remainingType, new ObjectType($handledClassName));
100+
}
101+
if ($remainingType->hasMethod($methodName)->yes()) {
102+
$remainingMethod = $remainingType->getMethod($methodName, $scope);
103+
$remainingParametersAcceptor = ParametersAcceptorSelector::selectFromArgs(
104+
$scope,
105+
$methodCall->getArgs(),
106+
$remainingMethod->getVariants(),
107+
$remainingMethod->getNamedArgumentsVariants(),
108+
);
109+
$resolvedTypes[] = $remainingParametersAcceptor->getReturnType();
110+
}
109111
}
112+
110113
return VoidToNullTypeTransformer::transform(TypeCombinator::union(...$resolvedTypes), $methodCall);
111114
}
112115

src/Type/Php/DateTimeModifyReturnTypeExtension.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,10 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
7878

7979
return null;
8080
} elseif ($hasDateTime) {
81-
$callerType = TypeCombinator::intersect($scope->getType($methodCall->var), new ObjectType(DateTimeInterface::class));
82-
83-
if ($callerType instanceof NeverType) {
84-
return null;
85-
}
86-
87-
return $callerType;
81+
return TypeCombinator::intersect(
82+
$scope->getType($methodCall->var),
83+
new ObjectType(DateTimeInterface::class),
84+
);
8885
}
8986

9087
if ($this->phpVersion->hasDateTimeExceptions()) {

0 commit comments

Comments
 (0)