Skip to content

Commit f90358c

Browse files
committed
final touch: handle as Arg
1 parent a378b0d commit f90358c

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

rules/Php74/Rector/Closure/ClosureToArrowFunctionRector.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,17 @@ public function refactor(Node $node): ?Node
7373
return null;
7474
}
7575

76+
$attributes = $node->getAttributes();
77+
unset($attributes[AttributeKey::ORIGINAL_NODE]);
78+
7679
$arrowFunction = new ArrowFunction(
7780
[
7881
'params' => $node->params,
7982
'returnType' => $node->returnType,
8083
'byRef' => $node->byRef,
8184
'expr' => $returnExpr,
82-
]
85+
],
86+
$attributes
8387
);
8488

8589
if ($node->static) {

src/PhpParser/Printer/BetterStandardPrinter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,15 @@ protected function pExpr_ArrowFunction(ArrowFunction $arrowFunction, int $preced
177177
}
178178

179179
$isMaxPrecedence = $precedence === self::MAX_PRECEDENCE;
180+
$isNewLineAndIndent = $arrowFunction->getAttribute(AttributeKey::IS_ARG_VALUE) === true;
180181
$indent = $this->resolveIndentSpaces($isMaxPrecedence);
181182

182183
$text = $isMaxPrecedence ? '' : "\n" . $indent;
184+
if ($isNewLineAndIndent) {
185+
$indent = $this->resolveIndentSpaces();
186+
$text = "\n" . $indent;
187+
}
188+
183189
foreach ($comments as $key => $comment) {
184190
$commentText = $key > 0 ? $indent . $comment->getText() : $comment->getText();
185191
$text .= $commentText . "\n";

0 commit comments

Comments
 (0)