Skip to content

Commit eafbe16

Browse files
authored
add local call fixture (#543)
1 parent 73ce281 commit eafbe16

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\ScalarArgumentToExpectedParamTypeRector\Fixture;
4+
5+
use Behat\Behat\Context\Context;
6+
use Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\ScalarArgumentToExpectedParamTypeRector\Source\SomeClassWithSetter;
7+
8+
final class LocalCall implements Context
9+
{
10+
public function test()
11+
{
12+
$result = $this->sumUp('1', '2');
13+
}
14+
15+
private function sumUp(int $a, int $b): int
16+
{
17+
return $a + $b;
18+
}
19+
}
20+
21+
?>
22+
-----
23+
<?php
24+
25+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\ScalarArgumentToExpectedParamTypeRector\Fixture;
26+
27+
use Behat\Behat\Context\Context;
28+
use Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\ScalarArgumentToExpectedParamTypeRector\Source\SomeClassWithSetter;
29+
30+
final class LocalCall implements Context
31+
{
32+
public function test()
33+
{
34+
$result = $this->sumUp(1, 2);
35+
}
36+
37+
private function sumUp(int $a, int $b): int
38+
{
39+
return $a + $b;
40+
}
41+
}
42+
43+
?>

rules/CodeQuality/Reflection/MethodParametersAndReturnTypesResolver.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPStan\Type\MixedType;
1515
use PHPStan\Type\ObjectType;
1616
use PHPStan\Type\StaticType;
17+
use PHPStan\Type\ThisType;
1718
use PHPStan\Type\Type;
1819
use Rector\Enum\ClassName;
1920
use Rector\NodeTypeResolver\NodeTypeResolver;
@@ -72,6 +73,10 @@ public function resolveCallParameterTypes(MethodCall|StaticCall $call): ?array
7273
$methodName = $call->name->toString();
7374

7475
$callerType = $this->nodeTypeResolver->getType($call instanceof MethodCall ? $call->var : $call->class);
76+
if ($callerType instanceof ThisType) {
77+
$callerType = $callerType->getStaticObjectType();
78+
}
79+
7580
if (! $callerType instanceof ObjectType) {
7681
return null;
7782
}

0 commit comments

Comments
 (0)