Skip to content

Commit 3eb61a0

Browse files
committed
Fixes after PHPStan update
1 parent bd9efb7 commit 3eb61a0

10 files changed

+41
-42
lines changed

src/Type/Symfony/Config/ArrayNodeDefinitionPrototypeDynamicReturnTypeExtension.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ public function getTypeFromMethodCall(
5555
{
5656
$calledOnType = $scope->getType($methodCall->var);
5757

58-
$defaultType = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
58+
$defaultType = ParametersAcceptorSelector::selectFromArgs(
59+
$scope,
60+
$methodCall->getArgs(),
61+
$methodReflection->getVariants(),
62+
)->getReturnType();
5963

6064
if ($methodReflection->getName() === 'prototype') {
6165
if (!isset($methodCall->getArgs()[0])) {

src/Type/Symfony/Config/PassParentObjectDynamicReturnTypeExtension.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ public function getTypeFromMethodCall(
4747
{
4848
$calledOnType = $scope->getType($methodCall->var);
4949

50-
$defaultType = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
50+
$defaultType = ParametersAcceptorSelector::selectFromArgs(
51+
$scope,
52+
$methodCall->getArgs(),
53+
$methodReflection->getVariants(),
54+
)->getReturnType();
5155

5256
return new ParentObjectType($defaultType->describe(VerbosityLevel::typeOnly()), $calledOnType);
5357
}

src/Type/Symfony/Config/ReturnParentDynamicReturnTypeExtension.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use PhpParser\Node\Expr\MethodCall;
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\MethodReflection;
8-
use PHPStan\Reflection\ParametersAcceptorSelector;
98
use PHPStan\Type\DynamicMethodReturnTypeExtension;
109
use PHPStan\Type\Symfony\Config\ValueObject\ParentObjectType;
1110
use PHPStan\Type\Type;
@@ -42,14 +41,14 @@ public function getTypeFromMethodCall(
4241
MethodReflection $methodReflection,
4342
MethodCall $methodCall,
4443
Scope $scope
45-
): Type
44+
): ?Type
4645
{
4746
$calledOnType = $scope->getType($methodCall->var);
4847
if ($calledOnType instanceof ParentObjectType) {
4948
return $calledOnType->getParent();
5049
}
5150

52-
return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
51+
return null;
5352
}
5453

5554
}

src/Type/Symfony/Config/TreeBuilderGetRootNodeDynamicReturnTypeExtension.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use PhpParser\Node\Expr\MethodCall;
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\MethodReflection;
8-
use PHPStan\Reflection\ParametersAcceptorSelector;
98
use PHPStan\Type\DynamicMethodReturnTypeExtension;
109
use PHPStan\Type\Symfony\Config\ValueObject\ParentObjectType;
1110
use PHPStan\Type\Symfony\Config\ValueObject\TreeBuilderType;
@@ -28,20 +27,17 @@ public function getTypeFromMethodCall(
2827
MethodReflection $methodReflection,
2928
MethodCall $methodCall,
3029
Scope $scope
31-
): Type
30+
): ?Type
3231
{
3332
$calledOnType = $scope->getType($methodCall->var);
34-
35-
$defaultType = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
36-
3733
if ($calledOnType instanceof TreeBuilderType) {
3834
return new ParentObjectType(
3935
$calledOnType->getRootNodeClassName(),
4036
$calledOnType,
4137
);
4238
}
4339

44-
return $defaultType;
40+
return null;
4541
}
4642

4743
}

src/Type/Symfony/HeaderBagDynamicReturnTypeExtension.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use PhpParser\Node\Expr\MethodCall;
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\MethodReflection;
8-
use PHPStan\Reflection\ParametersAcceptorSelector;
98
use PHPStan\Type\ArrayType;
109
use PHPStan\Type\Constant\ConstantBooleanType;
1110
use PHPStan\Type\DynamicMethodReturnTypeExtension;
@@ -32,7 +31,7 @@ public function getTypeFromMethodCall(
3231
MethodReflection $methodReflection,
3332
MethodCall $methodCall,
3433
Scope $scope
35-
): Type
34+
): ?Type
3635
{
3736
$firstArgType = isset($methodCall->getArgs()[2]) ? $scope->getType($methodCall->getArgs()[2]->value) : new ConstantBooleanType(true);
3837
$isTrueType = (new ConstantBooleanType(true))->isSuperTypeOf($firstArgType);
@@ -48,7 +47,7 @@ public function getTypeFromMethodCall(
4847
return new ArrayType(new IntegerType(), new StringType());
4948
}
5049

51-
return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
50+
return null;
5251
}
5352

5453
}

src/Type/Symfony/InputBagDynamicReturnTypeExtension.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function getTypeFromMethodCall(
3737
MethodReflection $methodReflection,
3838
MethodCall $methodCall,
3939
Scope $scope
40-
): Type
40+
): ?Type
4141
{
4242
if ($methodReflection->getName() === 'get') {
4343
return $this->getGetTypeFromMethodCall($methodReflection, $methodCall, $scope);
@@ -54,17 +54,21 @@ private function getGetTypeFromMethodCall(
5454
MethodReflection $methodReflection,
5555
MethodCall $methodCall,
5656
Scope $scope
57-
): Type
57+
): ?Type
5858
{
5959
if (isset($methodCall->getArgs()[1])) {
6060
$argType = $scope->getType($methodCall->getArgs()[1]->value);
6161
$isNull = (new NullType())->isSuperTypeOf($argType);
6262
if ($isNull->no()) {
63-
return TypeCombinator::removeNull(ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType());
63+
return TypeCombinator::removeNull(ParametersAcceptorSelector::selectFromArgs(
64+
$scope,
65+
$methodCall->getArgs(),
66+
$methodReflection->getVariants(),
67+
)->getReturnType());
6468
}
6569
}
6670

67-
return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
71+
return null;
6872
}
6973

7074
private function getAllTypeFromMethodCall(

src/Type/Symfony/KernelInterfaceDynamicReturnTypeExtension.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use PhpParser\Node\Expr\MethodCall;
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\MethodReflection;
8-
use PHPStan\Reflection\ParametersAcceptorSelector;
98
use PHPStan\Type\ArrayType;
109
use PHPStan\Type\Constant\ConstantBooleanType;
1110
use PHPStan\Type\DynamicMethodReturnTypeExtension;
@@ -30,7 +29,7 @@ public function getTypeFromMethodCall(
3029
MethodReflection $methodReflection,
3130
MethodCall $methodCall,
3231
Scope $scope
33-
): Type
32+
): ?Type
3433
{
3534
$firstArgType = isset($methodCall->getArgs()[2]) ? $scope->getType($methodCall->getArgs()[2]->value) : new ConstantBooleanType(true);
3635
$isTrueType = (new ConstantBooleanType(true))->isSuperTypeOf($firstArgType);
@@ -44,7 +43,7 @@ public function getTypeFromMethodCall(
4443
return new ArrayType(new IntegerType(), new StringType());
4544
}
4645

47-
return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
46+
return null;
4847
}
4948

5049
}

src/Type/Symfony/ParameterDynamicReturnTypeExtension.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PHPStan\Analyser\Scope;
77
use PHPStan\PhpDoc\TypeStringResolver;
88
use PHPStan\Reflection\MethodReflection;
9-
use PHPStan\Reflection\ParametersAcceptorSelector;
109
use PHPStan\ShouldNotHappenException;
1110
use PHPStan\Symfony\Configuration;
1211
use PHPStan\Symfony\ParameterMap;
@@ -85,7 +84,7 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
8584
return in_array($methodReflection->getName(), $methods, true);
8685
}
8786

88-
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
87+
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): ?Type
8988
{
9089
switch ($methodReflection->getName()) {
9190
case $this->methodGet:
@@ -206,16 +205,15 @@ private function getHasTypeFromMethodCall(
206205
MethodReflection $methodReflection,
207206
MethodCall $methodCall,
208207
Scope $scope
209-
): Type
208+
): ?Type
210209
{
211-
$defaultReturnType = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
212210
if (!isset($methodCall->getArgs()[0]) || !$this->constantHassers) {
213-
return $defaultReturnType;
211+
return null;
214212
}
215213

216214
$parameterKeys = $this->parameterMap::getParameterKeysFromNode($methodCall->getArgs()[0]->value, $scope);
217215
if ($parameterKeys === []) {
218-
return $defaultReturnType;
216+
return null;
219217
}
220218

221219
$has = null;
@@ -228,7 +226,7 @@ private function getHasTypeFromMethodCall(
228226
($has === true && $parameter === null)
229227
|| ($has === false && $parameter !== null)
230228
) {
231-
return $defaultReturnType;
229+
return null;
232230
}
233231
}
234232

src/Type/Symfony/RequestDynamicReturnTypeExtension.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use PhpParser\Node\Expr\MethodCall;
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\MethodReflection;
8-
use PHPStan\Reflection\ParametersAcceptorSelector;
98
use PHPStan\Type\Constant\ConstantBooleanType;
109
use PHPStan\Type\DynamicMethodReturnTypeExtension;
1110
use PHPStan\Type\ResourceType;
@@ -29,7 +28,7 @@ public function getTypeFromMethodCall(
2928
MethodReflection $methodReflection,
3029
MethodCall $methodCall,
3130
Scope $scope
32-
): Type
31+
): ?Type
3332
{
3433
if (!isset($methodCall->getArgs()[0])) {
3534
return new StringType();
@@ -46,7 +45,7 @@ public function getTypeFromMethodCall(
4645
return new StringType();
4746
}
4847

49-
return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
48+
return null;
5049
}
5150

5251
}

src/Type/Symfony/ServiceDynamicReturnTypeExtension.php

+8-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use PhpParser\Node\Expr\MethodCall;
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\MethodReflection;
8-
use PHPStan\Reflection\ParametersAcceptorSelector;
98
use PHPStan\ShouldNotHappenException;
109
use PHPStan\Symfony\Configuration;
1110
use PHPStan\Symfony\ParameterMap;
@@ -56,7 +55,7 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
5655
return in_array($methodReflection->getName(), ['get', 'has'], true);
5756
}
5857

59-
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
58+
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): ?Type
6059
{
6160
switch ($methodReflection->getName()) {
6261
case 'get':
@@ -71,16 +70,15 @@ private function getGetTypeFromMethodCall(
7170
MethodReflection $methodReflection,
7271
MethodCall $methodCall,
7372
Scope $scope
74-
): Type
73+
): ?Type
7574
{
76-
$returnType = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
7775
if (!isset($methodCall->getArgs()[0])) {
78-
return $returnType;
76+
return null;
7977
}
8078

8179
$parameterBag = $this->tryGetParameterBag();
8280
if ($parameterBag === null) {
83-
return $returnType;
81+
return null;
8482
}
8583

8684
$serviceId = $this->serviceMap::getServiceIdFromNode($methodCall->getArgs()[0]->value, $scope);
@@ -91,7 +89,7 @@ private function getGetTypeFromMethodCall(
9189
}
9290
}
9391

94-
return $returnType;
92+
return null;
9593
}
9694

9795
private function tryGetParameterBag(): ?ParameterBag
@@ -122,11 +120,10 @@ private function getHasTypeFromMethodCall(
122120
MethodReflection $methodReflection,
123121
MethodCall $methodCall,
124122
Scope $scope
125-
): Type
123+
): ?Type
126124
{
127-
$returnType = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
128125
if (!isset($methodCall->getArgs()[0]) || !$this->constantHassers) {
129-
return $returnType;
126+
return null;
130127
}
131128

132129
$serviceId = $this->serviceMap::getServiceIdFromNode($methodCall->getArgs()[0]->value, $scope);
@@ -135,7 +132,7 @@ private function getHasTypeFromMethodCall(
135132
return new ConstantBooleanType($service !== null && $service->isPublic());
136133
}
137134

138-
return $returnType;
135+
return null;
139136
}
140137

141138
private function determineServiceClass(ParameterBag $parameterBag, ServiceDefinition $service): ?string

0 commit comments

Comments
 (0)