Skip to content

Commit 89c84c4

Browse files
authored
[fix] Fix ParamTypeByMethodCallTypeRector for nested call (#7734)
1 parent 3b46948 commit 89c84c4

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector\Fixture;
4+
5+
use Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector\Source\SomeTypedService;
6+
7+
final class AvoidNestedCall
8+
{
9+
public function __construct(
10+
private SomeTypedService $someTypedService
11+
) {
12+
}
13+
14+
public function go($value)
15+
{
16+
$result = function ($value) {
17+
$this->someTypedService->run($value);
18+
};
19+
}
20+
}
21+
22+
?>
23+
-----
24+
<?php
25+
26+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector\Fixture;
27+
28+
use Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector\Source\SomeTypedService;
29+
30+
final class AvoidNestedCall
31+
{
32+
public function __construct(
33+
private SomeTypedService $someTypedService
34+
) {
35+
}
36+
37+
public function go($value)
38+
{
39+
$result = function (string $value) {
40+
$this->someTypedService->run($value);
41+
};
42+
}
43+
}
44+
45+
?>

rules/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ public function refactor(Node $node): ?Node
111111
}
112112

113113
/** @var array<StaticCall|MethodCall|FuncCall> $callers */
114-
$callers = $this->betterNodeFinder->findInstancesOf(
115-
$node,
114+
$callers = $this->betterNodeFinder->findInstancesOfScoped(
115+
[$node],
116116
[StaticCall::class, MethodCall::class, FuncCall::class]
117117
);
118118

0 commit comments

Comments
 (0)