Skip to content

Commit 6e0809f

Browse files
committed
[Php74] Skip closure in attribute on ClosureToArrowFunctionRector
1 parent 760eb16 commit 6e0809f

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

rules/Php74/Rector/Closure/ClosureToArrowFunctionRector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public function refactor(Node $node): ?Node
7373
return null;
7474
}
7575

76+
if ($node->getAttribute(AttributeKey::IS_CLOSURE_IN_ATTRIBUTE) === true) {
77+
return null;
78+
}
79+
7680
$attributes = $node->getAttributes();
7781
unset($attributes[AttributeKey::ORIGINAL_NODE]);
7882

src/NodeTypeResolver/Node/AttributeKey.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ final class AttributeKey
187187
*/
188188
public const IS_ARRAY_IN_ATTRIBUTE = 'is_array_in_attribute';
189189

190+
/**
191+
* @var string
192+
*/
193+
public const IS_CLOSURE_IN_ATTRIBUTE = 'is_closure_in_attribute';
194+
190195
/**
191196
* @var string
192197
*/

src/PhpParser/NodeVisitor/ContextNodeVisitor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ static function (Node $subNode): null {
145145
$subNode->setAttribute(AttributeKey::IS_ARRAY_IN_ATTRIBUTE, true);
146146
}
147147

148+
if ($subNode instanceof Closure) {
149+
$subNode->setAttribute(AttributeKey::IS_CLOSURE_IN_ATTRIBUTE, true);
150+
}
151+
148152
return null;
149153
}
150154
);

0 commit comments

Comments
 (0)