Skip to content

Commit 87d6892

Browse files
committed
fix
1 parent 0d08948 commit 87d6892

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

rules/Php81/Rector/Array_/ArrayToFirstClassCallableRector.php

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

116+
if ($node->getAttribute(AttributeKey::IS_PARAM_DEFAULT)) {
117+
return null;
118+
}
119+
116120
$args = [new VariadicPlaceholder()];
117121
if ($callerExpr instanceof ClassConstFetch) {
118122
$type = $this->getType($callerExpr->class);

src/DependencyInjection/LazyContainerFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
use Rector\PhpParser\NodeVisitor\ContextNodeVisitor;
126126
use Rector\PhpParser\NodeVisitor\GlobalVariableNodeVisitor;
127127
use Rector\PhpParser\NodeVisitor\NameNodeVisitor;
128+
use Rector\PhpParser\NodeVisitor\ParamDefaultNodeVisitor;
128129
use Rector\PhpParser\NodeVisitor\PhpVersionConditionNodeVisitor;
129130
use Rector\PhpParser\NodeVisitor\PropertyOrClassConstDefaultNodeVisitor;
130131
use Rector\PhpParser\NodeVisitor\StaticVariableNodeVisitor;
@@ -253,6 +254,7 @@ final class LazyContainerFactory
253254
NameNodeVisitor::class,
254255
StaticVariableNodeVisitor::class,
255256
PropertyOrClassConstDefaultNodeVisitor::class,
257+
ParamDefaultNodeVisitor::class,
256258
ClassConstFetchNodeVisitor::class,
257259
];
258260

src/NodeTypeResolver/Node/AttributeKey.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ final class AttributeKey
217217
*/
218218
public const IS_PARAM_VAR = 'is_param_var';
219219

220+
/**
221+
* @var string
222+
*/
223+
public const IS_PARAM_DEFAULT = 'is_param_default';
224+
220225
/**
221226
* @var string
222227
*/
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\PhpParser\NodeVisitor;
6+
7+
use PhpParser\Node;
8+
use PhpParser\Node\Expr;
9+
use PhpParser\Node\Param;
10+
use PhpParser\NodeVisitorAbstract;
11+
use Rector\Contract\PhpParser\DecoratingNodeVisitorInterface;
12+
use Rector\NodeTypeResolver\Node\AttributeKey;
13+
use Rector\PhpParser\NodeTraverser\SimpleNodeTraverser;
14+
15+
final class ParamDefaultNodeVisitor extends NodeVisitorAbstract implements DecoratingNodeVisitorInterface
16+
{
17+
public function enterNode(Node $node): ?Node
18+
{
19+
if (! $node instanceof Param) {
20+
return null;
21+
}
22+
23+
if (! $node->default instanceof Expr) {
24+
return null;
25+
}
26+
27+
SimpleNodeTraverser::decorateWithAttributeValue(
28+
$node->default,
29+
AttributeKey::IS_PARAM_DEFAULT,
30+
true
31+
);
32+
33+
return null;
34+
}
35+
}

0 commit comments

Comments
 (0)