File tree Expand file tree Collapse file tree 4 files changed +46
-0
lines changed
rules/Php81/Rector/Array_ Expand file tree Collapse file tree 4 files changed +46
-0
lines changed Original file line number Diff line number Diff 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 );
Original file line number Diff line number Diff line change 125125use Rector \PhpParser \NodeVisitor \ContextNodeVisitor ;
126126use Rector \PhpParser \NodeVisitor \GlobalVariableNodeVisitor ;
127127use Rector \PhpParser \NodeVisitor \NameNodeVisitor ;
128+ use Rector \PhpParser \NodeVisitor \ParamDefaultNodeVisitor ;
128129use Rector \PhpParser \NodeVisitor \PhpVersionConditionNodeVisitor ;
129130use Rector \PhpParser \NodeVisitor \PropertyOrClassConstDefaultNodeVisitor ;
130131use 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
Original file line number Diff line number Diff 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 */
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments