Skip to content

Commit 9a8110c

Browse files
authored
[Php81] Skip as argument unpack on ArrayToFirstClassCallableRector (#8081)
* [Php81] Skip as ReflectionMethod argument unpack * final touch: rename fixture
1 parent a181f3f commit 9a8110c

4 files changed

Lines changed: 26 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php81\Rector\Array_\ArrayToFirstClassCallableRector\Fixture;
4+
5+
use ReflectionMethod;
6+
7+
class SkipInReflectionMethodAsArgumentUnpack
8+
{
9+
function methodInjection()
10+
{}
11+
12+
public function get()
13+
{
14+
return new ReflectionMethod(...[$this, 'methodInjection']);
15+
}
16+
}

‎rules/Php81/Rector/Array_/ArrayToFirstClassCallableRector.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ public function refactor(Node $node): StaticCall|MethodCall|null
118118
return null;
119119
}
120120

121+
if ($node->getAttribute(AttributeKey::IS_UNPACKED_ARG_VALUE)) {
122+
return null;
123+
}
124+
121125
$args = [new VariadicPlaceholder()];
122126
if ($callerExpr instanceof ClassConstFetch) {
123127
$type = $this->getType($callerExpr->class);

‎src/NodeTypeResolver/Node/AttributeKey.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ final class AttributeKey
129129

130130
public const string IS_ARG_VALUE = 'is_arg_value';
131131

132+
public const string IS_UNPACKED_ARG_VALUE = 'is_unpacked_arg_value';
133+
132134
public const string IS_PARAM_VAR = 'is_param_var';
133135

134136
public const string IS_PARAM_DEFAULT = 'is_param_default';

‎src/PhpParser/NodeVisitor/ContextNodeVisitor.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ public function enterNode(Node $node): ?Node
9494

9595
if ($node instanceof Arg) {
9696
$node->value->setAttribute(AttributeKey::IS_ARG_VALUE, true);
97+
if ($node->unpack) {
98+
$node->value->setAttribute(AttributeKey::IS_UNPACKED_ARG_VALUE, true);
99+
}
100+
97101
return null;
98102
}
99103

0 commit comments

Comments
 (0)