Skip to content

Commit 5a256b6

Browse files
committed
Fixes after PHPStan update
1 parent c903386 commit 5a256b6

8 files changed

+33
-16
lines changed

src/Reflection/Nette/NetteObjectClassReflectionExtension.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use PHPStan\Reflection\ClassReflection;
88
use PHPStan\Reflection\MethodReflection;
99
use PHPStan\Reflection\MethodsClassReflectionExtension;
10-
use PHPStan\Reflection\ParametersAcceptorSelector;
1110
use PHPStan\Reflection\PropertiesClassReflectionExtension;
1211
use PHPStan\Reflection\PropertyReflection;
1312
use function array_merge;
@@ -53,7 +52,7 @@ public function getProperty(ClassReflection $classReflection, string $propertyNa
5352
{
5453
/** @var MethodReflection $getterMethod */
5554
$getterMethod = $this->getMethodByProperty($classReflection, $propertyName);
56-
return new NetteObjectPropertyReflection($classReflection, ParametersAcceptorSelector::selectSingle($getterMethod->getVariants())->getReturnType());
55+
return new NetteObjectPropertyReflection($classReflection, $getterMethod->getVariants()[0]->getReturnType());
5756
}
5857

5958
public function hasMethod(ClassReflection $classReflection, string $methodName): bool

src/Type/Nette/ComponentGetPresenterDynamicReturnTypeExtension.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
2626

2727
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
2828
{
29-
$methodDefinition = ParametersAcceptorSelector::selectSingle(
29+
$methodDefinition = ParametersAcceptorSelector::selectFromArgs(
30+
$scope,
31+
$methodCall->getArgs(),
3032
$methodReflection->getVariants(),
3133
);
3234
$defaultReturnType = $methodDefinition->getReturnType();

src/Type/Nette/ComponentLookupDynamicReturnTypeExtension.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
2626

2727
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
2828
{
29-
$defaultReturnType = ParametersAcceptorSelector::selectSingle(
29+
$defaultReturnType = ParametersAcceptorSelector::selectFromArgs(
30+
$scope,
31+
$methodCall->getArgs(),
3032
$methodReflection->getVariants(),
3133
)->getReturnType();
3234
if (count($methodCall->getArgs()) < 2) {

src/Type/Nette/ComponentModelArrayAccessDynamicReturnTypeExtension.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PHPStan\Type\Nette;
44

5+
use PhpParser\Node\Arg;
56
use PhpParser\Node\Expr\MethodCall;
7+
use PhpParser\Node\Scalar\String_;
68
use PHPStan\Analyser\Scope;
79
use PHPStan\Reflection\MethodReflection;
810
use PHPStan\Reflection\ParametersAcceptorSelector;
@@ -38,13 +40,13 @@ public function getTypeFromMethodCall(
3840
): Type
3941
{
4042
$calledOnType = $scope->getType($methodCall->var);
41-
$defaultType = ParametersAcceptorSelector::selectSingle($calledOnType->getMethod('createComponent', $scope)->getVariants())->getReturnType();
43+
$defaultType = $calledOnType->getMethod('createComponent', $scope)->getVariants()[0]->getReturnType();
4244
$defaultType = TypeCombinator::remove($defaultType, new NullType());
4345
if ($defaultType->isSuperTypeOf(new ObjectType('Nette\ComponentModel\IComponent'))->yes()) {
4446
$defaultType = new MixedType(false, new NullType());
4547
}
4648
$args = $methodCall->getArgs();
47-
if (count($args) !== 1) {
49+
if (count($args) < 1) {
4850
return $defaultType;
4951
}
5052

@@ -64,7 +66,11 @@ public function getTypeFromMethodCall(
6466

6567
$method = $calledOnType->getMethod($methodName, $scope);
6668

67-
$types[] = ParametersAcceptorSelector::selectSingle($method->getVariants())->getReturnType();
69+
$types[] = ParametersAcceptorSelector::selectFromArgs(
70+
$scope,
71+
[new Arg(new String_($componentName))],
72+
$method->getVariants(),
73+
)->getReturnType();
6874
}
6975

7076
return TypeCombinator::union(...$types);

src/Type/Nette/ComponentModelDynamicReturnTypeExtension.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PHPStan\Type\Nette;
44

5+
use PhpParser\Node\Arg;
56
use PhpParser\Node\Expr\MethodCall;
7+
use PhpParser\Node\Scalar\String_;
68
use PHPStan\Analyser\Scope;
79
use PHPStan\Reflection\MethodReflection;
810
use PHPStan\Reflection\ParametersAcceptorSelector;
@@ -38,7 +40,7 @@ public function getTypeFromMethodCall(
3840
): Type
3941
{
4042
$calledOnType = $scope->getType($methodCall->var);
41-
$defaultType = ParametersAcceptorSelector::selectSingle($calledOnType->getMethod('createComponent', $scope)->getVariants())->getReturnType();
43+
$defaultType = $calledOnType->getMethod('createComponent', $scope)->getVariants()[0]->getReturnType();
4244
if ($defaultType->isSuperTypeOf(new ObjectType('Nette\ComponentModel\IComponent'))->yes()) {
4345
$defaultType = new MixedType();
4446
}
@@ -75,7 +77,11 @@ public function getTypeFromMethodCall(
7577

7678
$method = $calledOnType->getMethod($methodName, $scope);
7779

78-
$types[] = ParametersAcceptorSelector::selectSingle($method->getVariants())->getReturnType();
80+
$types[] = ParametersAcceptorSelector::selectFromArgs(
81+
$scope,
82+
[new Arg(new String_($componentName))],
83+
$method->getVariants(),
84+
)->getReturnType();
7985
}
8086

8187
return TypeCombinator::union(...$types);

src/Type/Nette/FormContainerUnsafeValuesDynamicReturnTypeExtension.php

+3-4
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\DynamicMethodReturnTypeExtension;
1110
use PHPStan\Type\MixedType;
@@ -27,10 +26,10 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
2726
return $methodReflection->getName() === 'getUnsafeValues';
2827
}
2928

30-
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
29+
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): ?Type
3130
{
3231
if (count($methodCall->getArgs()) === 0) {
33-
return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
32+
return null;
3433
}
3534

3635
$arg = $methodCall->getArgs()[0]->value;
@@ -43,7 +42,7 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
4342
return new ArrayType(new StringType(), new MixedType());
4443
}
4544

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

4948
}

src/Type/Nette/FormsBaseControlDynamicReturnTypeExtension.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ public function getTypeFromMethodCall(
3131
Scope $scope
3232
): Type
3333
{
34-
$returnType = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
34+
$returnType = ParametersAcceptorSelector::selectFromArgs(
35+
$scope,
36+
$methodCall->getArgs(),
37+
$methodReflection->getVariants(),
38+
)->getReturnType();
3539
$referencedClasses = $returnType->getReferencedClasses();
3640
if (
3741
count($referencedClasses) === 1

tests/Reflection/Nette/HtmlClassReflectionExtensionTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Nette\Utils\Html;
66
use PHPStan\Broker\Broker;
7-
use PHPStan\Reflection\ParametersAcceptorSelector;
87
use PHPStan\Testing\PHPStanTestCase;
98
use PHPStan\Type\VerbosityLevel;
109
use stdClass;
@@ -52,7 +51,7 @@ public function testGetMethod(): void
5251
{
5352
$classReflection = $this->broker->getClass(Html::class);
5453
$methodReflection = $this->extension->getMethod($classReflection, 'href');
55-
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants());
54+
$parametersAcceptor = $methodReflection->getVariants()[0];
5655
self::assertSame('href', $methodReflection->getName());
5756
self::assertSame($classReflection, $methodReflection->getDeclaringClass());
5857
self::assertFalse($methodReflection->isStatic());

0 commit comments

Comments
 (0)