Skip to content

Commit 0279c00

Browse files
authored
Add first class callable support to CallUserFuncArrayToVariadicRector (#7428)
1 parent 0e2401b commit 0279c00

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodingStyle\Rector\FuncCall\CallUserFuncArrayToVariadicRector\Fixture;
4+
5+
use Rector\Tests\CodingStyle\Rector\FuncCall\CallUserFuncArrayToVariadicRector\Source\Redirector;
6+
7+
final class FirstClassCallable
8+
{
9+
private $redirector;
10+
11+
public function __construct()
12+
{
13+
$this->redirector = new Redirector();
14+
}
15+
16+
public function run()
17+
{
18+
$args = \func_get_args();
19+
call_user_func_array($this->redirector->redirect(...), $args);
20+
}
21+
}
22+
23+
?>
24+
-----
25+
<?php
26+
27+
namespace Rector\Tests\CodingStyle\Rector\FuncCall\CallUserFuncArrayToVariadicRector\Fixture;
28+
29+
use Rector\Tests\CodingStyle\Rector\FuncCall\CallUserFuncArrayToVariadicRector\Source\Redirector;
30+
31+
final class FirstClassCallable
32+
{
33+
private $redirector;
34+
35+
public function __construct()
36+
{
37+
$this->redirector = new Redirector();
38+
}
39+
40+
public function run()
41+
{
42+
$args = \func_get_args();
43+
$this->redirector->redirect(...$args);
44+
}
45+
}
46+
47+
?>

rules-tests/CodingStyle/Rector/FuncCall/CallUserFuncArrayToVariadicRector/config/configured_rule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Rector\ValueObject\PhpVersion;
88

99
return static function (RectorConfig $rectorConfig): void {
10-
$rectorConfig->phpVersion(PhpVersion::PHP_74);
10+
$rectorConfig->phpVersion(PhpVersion::PHP_80);
1111

1212
$rectorConfig->rule(CallUserFuncArrayToVariadicRector::class);
1313
};

rules/CodingStyle/Rector/FuncCall/CallUserFuncArrayToVariadicRector.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ public function refactor(Node $node): ?Node
9393
return $this->createMethodCall($firstArgValue, $secondArgValue);
9494
}
9595

96+
if ($firstArgValue instanceof MethodCall && $firstArgValue->isFirstClassCallable()) {
97+
$firstArgValue->args = [$this->createUnpackedArg($secondArgValue)];
98+
99+
return $firstArgValue;
100+
}
101+
96102
return null;
97103
}
98104

rules/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ public function refactor(Node $node): ?Node
110110
}
111111
}
112112

113-
if ($this->isName($classMethod, MethodName::__GET) && $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::MIXED_TYPE) && ! $classMethod->returnType instanceof Node) {
113+
if ($this->isName($classMethod, MethodName::__GET) && $this->phpVersionProvider->isAtLeastPhpVersion(
114+
PhpVersionFeature::MIXED_TYPE
115+
) && ! $classMethod->returnType instanceof Node) {
114116
$classMethod->returnType = new Identifier('mixed');
115117
$hasChanged = true;
116118
}

0 commit comments

Comments
 (0)