diff --git a/rules-tests/Php74/Rector/Closure/ClosureToArrowFunctionRector/Fixture/keep_docblock_on_return.php.inc b/rules-tests/Php74/Rector/Closure/ClosureToArrowFunctionRector/Fixture/keep_docblock_on_return.php.inc index 810e66e27d1..d3463cd084a 100644 --- a/rules-tests/Php74/Rector/Closure/ClosureToArrowFunctionRector/Fixture/keep_docblock_on_return.php.inc +++ b/rules-tests/Php74/Rector/Closure/ClosureToArrowFunctionRector/Fixture/keep_docblock_on_return.php.inc @@ -28,15 +28,11 @@ class KeepDocblockOnReturn { public function run() { - - /** @psalm-suppress UndefinedFunction */ - - fn() => ff(); - - - // @psalm-suppress UndefinedFunction + /** @psalm-suppress UndefinedFunction */ + fn() => ff(); - fn() => ff(); + // @psalm-suppress UndefinedFunction + fn() => ff(); } } diff --git a/rules-tests/Php74/Rector/Closure/ClosureToArrowFunctionRector/Fixture/with_equal_var_doc_type.php.inc b/rules-tests/Php74/Rector/Closure/ClosureToArrowFunctionRector/Fixture/with_equal_var_doc_type.php.inc index f7b0535b810..d21f587edd5 100644 --- a/rules-tests/Php74/Rector/Closure/ClosureToArrowFunctionRector/Fixture/with_equal_var_doc_type.php.inc +++ b/rules-tests/Php74/Rector/Closure/ClosureToArrowFunctionRector/Fixture/with_equal_var_doc_type.php.inc @@ -23,10 +23,8 @@ class WithEqualVarDocType { public function run() { - - /** @var string $var */ - - fn(string $var) => $var; + /** @var string $var */ + fn(string $var) => $var; } } diff --git a/src/PhpParser/Printer/BetterStandardPrinter.php b/src/PhpParser/Printer/BetterStandardPrinter.php index 97543ea602d..5dcc34b72e7 100644 --- a/src/PhpParser/Printer/BetterStandardPrinter.php +++ b/src/PhpParser/Printer/BetterStandardPrinter.php @@ -176,15 +176,15 @@ protected function pExpr_ArrowFunction(ArrowFunction $arrowFunction, int $preced return parent::pExpr_ArrowFunction($arrowFunction, $precedence, $lhsPrecedence); } - $indent = $this->resolveIndentSpaces(); + $indentOnlyLevel = $this->resolveIndentSpaces(true); - $text = "\n" . $indent; + $text = ""; foreach ($comments as $key => $comment) { - $commentText = $key > 0 ? $indent . $comment->getText() : $comment->getText(); + $commentText = $key > 0 ? $indentOnlyLevel . $comment->getText() : $comment->getText(); $text .= $commentText . "\n"; } - return $text . "\n" . $indent . parent::pExpr_ArrowFunction($arrowFunction, $precedence, $lhsPrecedence); + return $text . $indentOnlyLevel . parent::pExpr_ArrowFunction($arrowFunction, $precedence, $lhsPrecedence); } /** @@ -502,10 +502,14 @@ private function cleanStartIndentationOnHeredocNowDoc(string $content): string return implode("\n", $trimmedLines); } - private function resolveIndentSpaces(): string + private function resolveIndentSpaces(bool $onlyLevel = false): string { $indentSize = SimpleParameterProvider::provideIntParameter(Option::INDENT_SIZE); + if ($onlyLevel) { + return str_repeat($this->getIndentCharacter(), $this->indentLevel); + } + return str_repeat($this->getIndentCharacter(), $this->indentLevel) . str_repeat($this->getIndentCharacter(), $indentSize); }