diff --git a/rules-tests/CodeQuality/Rector/MethodCall/ScalarArgumentToExpectedParamTypeRector/Fixture/local_call.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/ScalarArgumentToExpectedParamTypeRector/Fixture/local_call.php.inc new file mode 100644 index 00000000..8839ed5e --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/ScalarArgumentToExpectedParamTypeRector/Fixture/local_call.php.inc @@ -0,0 +1,43 @@ +sumUp('1', '2'); + } + + private function sumUp(int $a, int $b): int + { + return $a + $b; + } +} + +?> +----- +sumUp(1, 2); + } + + private function sumUp(int $a, int $b): int + { + return $a + $b; + } +} + +?> diff --git a/rules/CodeQuality/Reflection/MethodParametersAndReturnTypesResolver.php b/rules/CodeQuality/Reflection/MethodParametersAndReturnTypesResolver.php index 00afac20..e4a7b2f6 100644 --- a/rules/CodeQuality/Reflection/MethodParametersAndReturnTypesResolver.php +++ b/rules/CodeQuality/Reflection/MethodParametersAndReturnTypesResolver.php @@ -14,6 +14,7 @@ use PHPStan\Type\MixedType; use PHPStan\Type\ObjectType; use PHPStan\Type\StaticType; +use PHPStan\Type\ThisType; use PHPStan\Type\Type; use Rector\Enum\ClassName; use Rector\NodeTypeResolver\NodeTypeResolver; @@ -72,6 +73,10 @@ public function resolveCallParameterTypes(MethodCall|StaticCall $call): ?array $methodName = $call->name->toString(); $callerType = $this->nodeTypeResolver->getType($call instanceof MethodCall ? $call->var : $call->class); + if ($callerType instanceof ThisType) { + $callerType = $callerType->getStaticObjectType(); + } + if (! $callerType instanceof ObjectType) { return null; }