Always use pMaybeMultiline() for function parameters

Closes GH-861.
This commit is contained in:
Anton
2022-07-21 08:18:46 +03:00
committed by Nikita Popov
parent 34d8681488
commit ea9d6b2238
2 changed files with 56 additions and 3 deletions

View File

@@ -622,7 +622,7 @@ class Standard extends PrettyPrinterAbstract
return $this->pAttrGroups($node->attrGroups, true)
. ($node->static ? 'static ' : '')
. 'function ' . ($node->byRef ? '&' : '')
. '(' . $this->pCommaSeparated($node->params) . ')'
. '(' . $this->pMaybeMultiline($node->params) . ')'
. (!empty($node->uses) ? ' use (' . $this->pCommaSeparated($node->uses) . ')' : '')
. (null !== $node->returnType ? ': ' . $this->p($node->returnType) : '')
. ' {' . $this->pStmts($node->stmts) . $this->nl . '}';
@@ -644,7 +644,7 @@ class Standard extends PrettyPrinterAbstract
return $this->pAttrGroups($node->attrGroups, true)
. ($node->static ? 'static ' : '')
. 'fn' . ($node->byRef ? '&' : '')
. '(' . $this->pCommaSeparated($node->params) . ')'
. '(' . $this->pMaybeMultiline($node->params) . ')'
. (null !== $node->returnType ? ': ' . $this->p($node->returnType) : '')
. ' => '
. $this->p($node->expr);
@@ -813,7 +813,7 @@ class Standard extends PrettyPrinterAbstract
protected function pStmt_Function(Stmt\Function_ $node) {
return $this->pAttrGroups($node->attrGroups)
. 'function ' . ($node->byRef ? '&' : '') . $node->name
. '(' . $this->pCommaSeparated($node->params) . ')'
. '(' . $this->pMaybeMultiline($node->params) . ')'
. (null !== $node->returnType ? ': ' . $this->p($node->returnType) : '')
. $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}';
}

View File

@@ -0,0 +1,53 @@
Comments on function parameters
-----
<?php
class Test {
function test(
// Comment
$param
) {
}
}
function test(
// Comment
$param
) {
}
function(
// Comment
$param
) {
};
fn(
// Comment
$param
) => 42;
-----
class Test
{
function test(
// Comment
$param
)
{
}
}
function test(
// Comment
$param
)
{
}
function (
// Comment
$param
) {
};
fn(
// Comment
$param
) => 42;