Skip to content

Commit 5fc8c1a

Browse files
Replace ParametersAcceptorSelector::selectSingle() with ParametersAcceptorSelectorVariantsWrapper::select() when possible (rectorphp#3361)
* Replace ParametersAcceptorSelector::selectSingle() with ParametersAcceptorSelectorVariantsWrapper::select() when possible * [ci-review] Rector Rectify --------- Co-authored-by: GitHub Action <[email protected]>
1 parent a3bc2dc commit 5fc8c1a

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

packages/NodeTypeResolver/MethodParameterTypeResolver.php

+5-11
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PHPStan\Analyser\Scope;
1010
use PHPStan\Reflection\MethodReflection;
1111
use PHPStan\Reflection\Native\NativeMethodReflection;
12-
use PHPStan\Reflection\ParametersAcceptorSelector;
1312
use PHPStan\Type\Type;
1413
use Rector\Core\Reflection\ReflectionResolver;
1514
use Rector\NodeTypeResolver\Node\AttributeKey;
@@ -61,19 +60,14 @@ private function provideParameterTypesFromMethodReflection(
6160
}
6261

6362
$parameterTypes = [];
63+
$scope = $node->getAttribute(AttributeKey::SCOPE);
6464

65-
if ($node instanceof ClassMethod) {
66-
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants());
67-
} else {
68-
$scope = $node->getAttribute(AttributeKey::SCOPE);
69-
70-
if (! $scope instanceof Scope) {
71-
return [];
72-
}
73-
74-
$parametersAcceptor = ParametersAcceptorSelectorVariantsWrapper::select($methodReflection, $node, $scope);
65+
if (! $scope instanceof Scope) {
66+
return [];
7567
}
7668

69+
$parametersAcceptor = ParametersAcceptorSelectorVariantsWrapper::select($methodReflection, $node, $scope);
70+
7771
foreach ($parametersAcceptor->getParameters() as $parameterReflection) {
7872
$parameterTypes[] = $parameterReflection->getType();
7973
}

packages/PhpDocParser/TypeAnalyzer/ClassMethodReturnTypeResolver.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
use PHPStan\Analyser\Scope;
99
use PHPStan\Reflection\ClassReflection;
1010
use PHPStan\Reflection\FunctionVariant;
11-
use PHPStan\Reflection\ParametersAcceptorSelector;
1211
use PHPStan\Type\MixedType;
1312
use PHPStan\Type\Type;
13+
use Rector\NodeTypeResolver\PHPStan\ParametersAcceptorSelectorVariantsWrapper;
1414

1515
/**
1616
* @api
@@ -28,7 +28,11 @@ public function resolve(ClassMethod $classMethod, Scope $scope): Type
2828

2929
$extendedMethodReflection = $classReflection->getMethod($methodName, $scope);
3030

31-
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($extendedMethodReflection->getVariants());
31+
$parametersAcceptor = ParametersAcceptorSelectorVariantsWrapper::select(
32+
$extendedMethodReflection,
33+
$classMethod,
34+
$scope
35+
);
3236
if (! $parametersAcceptor instanceof FunctionVariant) {
3337
return new MixedType();
3438
}

0 commit comments

Comments
 (0)