Skip to content

Commit 3e7b3ee

Browse files
committed
Updated PHPStan
1 parent f4447e6 commit 3e7b3ee

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
includes:
22
- extension.neon
33
- rules.neon
4-
- vendor/phpstan/phpstan-strict-rules/rules.neon
4+
#- vendor/phpstan/phpstan-strict-rules/rules.neon
55

66
parameters:
77
excludes_analyse:

src/Type/PHPUnit/CreateMockDynamicReturnTypeExtension.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PhpParser\Node\Expr\MethodCall;
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\MethodReflection;
8+
use PHPStan\Reflection\ParametersAcceptorSelector;
89
use PHPStan\Type\Constant\ConstantStringType;
910
use PHPStan\Type\ObjectType;
1011
use PHPStan\Type\Type;
@@ -36,19 +37,20 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
3637
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
3738
{
3839
$argumentIndex = $this->methods[$methodReflection->getName()];
40+
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants());
3941
if (!isset($methodCall->args[$argumentIndex])) {
40-
return $methodReflection->getReturnType();
42+
return $parametersAcceptor->getReturnType();
4143
}
4244
$argType = $scope->getType($methodCall->args[$argumentIndex]->value);
4345
if (!$argType instanceof ConstantStringType) {
44-
return $methodReflection->getReturnType();
46+
return $parametersAcceptor->getReturnType();
4547
}
4648

4749
$class = $argType->getValue();
4850

4951
return TypeCombinator::intersect(
5052
new ObjectType($class),
51-
$methodReflection->getReturnType()
53+
$parametersAcceptor->getReturnType()
5254
);
5355
}
5456

src/Type/PHPUnit/GetMockBuilderDynamicReturnTypeExtension.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PhpParser\Node\Expr\MethodCall;
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\MethodReflection;
8+
use PHPStan\Reflection\ParametersAcceptorSelector;
89
use PHPStan\Type\Constant\ConstantStringType;
910
use PHPStan\Type\Type;
1011
use PHPStan\Type\TypeWithClassName;
@@ -24,7 +25,8 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
2425

2526
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
2627
{
27-
$mockBuilderType = $methodReflection->getReturnType();
28+
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants());
29+
$mockBuilderType = $parametersAcceptor->getReturnType();
2830
if (count($methodCall->args) === 0) {
2931
return $mockBuilderType;
3032
}

src/Type/PHPUnit/MockBuilderDynamicReturnTypeExtension.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Broker\Broker;
88
use PHPStan\Reflection\MethodReflection;
9+
use PHPStan\Reflection\ParametersAcceptorSelector;
910
use PHPStan\Type\ObjectType;
1011
use PHPStan\Type\Type;
1112
use PHPStan\Type\TypeCombinator;
@@ -25,7 +26,9 @@ public function setBroker(Broker $broker): void
2526
public function getClass(): string
2627
{
2728
$testCase = $this->broker->getClass(\PHPUnit\Framework\TestCase::class);
28-
$mockBuilderType = $testCase->getNativeMethod('getMockBuilder')->getReturnType();
29+
$mockBuilderType = ParametersAcceptorSelector::selectSingle(
30+
$testCase->getNativeMethod('getMockBuilder')->getVariants()
31+
)->getReturnType();
2932
if (!$mockBuilderType instanceof TypeWithClassName) {
3033
throw new \PHPStan\ShouldNotHappenException();
3134
}
@@ -52,13 +55,15 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
5255
return $calledOnType;
5356
}
5457

58+
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants());
59+
5560
if (!$calledOnType instanceof MockBuilderType) {
56-
return $methodReflection->getReturnType();
61+
return $parametersAcceptor->getReturnType();
5762
}
5863

5964
return TypeCombinator::intersect(
6065
new ObjectType($calledOnType->getMockedClass()),
61-
$methodReflection->getReturnType()
66+
$parametersAcceptor->getReturnType()
6267
);
6368
}
6469

0 commit comments

Comments
 (0)