Skip to content

Commit

Permalink
Fix internal ServiceLocatorDynamicReturnTypeExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Aug 30, 2023
1 parent c1ad4ce commit 373e8cc
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions build/PHPStan/Build/ServiceLocatorDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;

Expand Down Expand Up @@ -34,10 +33,14 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method

$returnType = ParametersAcceptorSelector::selectFromArgs($scope, $methodCall->getArgs(), $methodReflection->getVariants())->getReturnType();

if ($methodReflection->getName() === 'getByType' && count($methodCall->getArgs()) >= 2) {
$argType = $scope->getType($methodCall->getArgs()[1]->value);
if ($argType->isTrue()->yes()) {
$returnType = TypeCombinator::addNull($returnType);
if ($methodReflection->getName() === 'getByType') {
if (count($methodCall->getArgs()) < 2) {
$returnType = TypeCombinator::removeNull($returnType);
} else {
$argType = $scope->getType($methodCall->getArgs()[1]->value);
if ($argType->isTrue()->yes()) {
$returnType = TypeCombinator::removeNull($returnType);
}
}
}

Expand Down

0 comments on commit 373e8cc

Please sign in to comment.