Skip to content

Commit

Permalink
feat(dev): Container::call() return type detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
LastDragon-ru committed Jun 3, 2024
1 parent 024f9c5 commit 1a924a3
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/dev/src/PhpStan/Container/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\Type;

Expand Down Expand Up @@ -36,7 +37,7 @@ public function getClass(): string {

#[Override]
public function isMethodSupported(MethodReflection $methodReflection): bool {
return in_array($methodReflection->getName(), ['make', 'makeWith', 'resolve'], true);
return in_array($methodReflection->getName(), ['make', 'makeWith', 'resolve', 'call'], true);
}

#[Override]
Expand All @@ -56,8 +57,18 @@ public function getTypeFromMethodCall(

// Return
return match (true) {
$argType->isClassStringType()->yes() => $argType->getClassStringObjectType(),
default => null,
$methodReflection->getName() === 'call' => match (true) {
$argType->isCallable()->yes() => ParametersAcceptorSelector
::selectSingle(
$argType->getCallableParametersAcceptors($scope),
)
->getReturnType(),
default => null,
},
default => match (true) {
$argType->isClassStringType()->yes() => $argType->getClassStringObjectType(),
default => null,
},
};
}
}

0 comments on commit 1a924a3

Please sign in to comment.