Skip to content

Commit

Permalink
Printer: promoted parameters / parameter with attributes are always m…
Browse files Browse the repository at this point in the history
…ultiline
  • Loading branch information
dg committed Mar 13, 2023
1 parent c4e433f commit cd40df5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
7 changes: 4 additions & 3 deletions src/PhpGenerator/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ protected function printParameters(Closure|GlobalFunction|Method $function, int
{
$params = [];
$list = $function->getParameters();
$special = false;
$multiline = false;

foreach ($list as $param) {
$param->validate();
Expand All @@ -344,12 +344,13 @@ protected function printParameters(Closure|GlobalFunction|Method $function, int
. '$' . $param->getName()
. ($param->hasDefaultValue() && !$variadic ? ' = ' . $this->dump($param->getDefaultValue()) : '');

$special = $special || $promoted || $attrs;
$multiline = $multiline || $promoted || $attrs;
}

$line = implode(', ', $params);
$multiline = $multiline || count($params) > 1 && (strlen($line) + $column > $this->wrapLength);

return count($params) > 1 && ($special || strlen($line) + $column > $this->wrapLength)
return $multiline
? "(\n" . $this->indent(implode(",\n", $params)) . ",\n)"
: "($line)";
}
Expand Down
5 changes: 3 additions & 2 deletions tests/PhpGenerator/expected/ClassType.attributes.expect
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class Example
* Returns file handle.
*/
#[ExampleAttribute]
public function getHandle(#[ExampleAttribute, WithArguments(123)] $mode)
{
public function getHandle(
#[ExampleAttribute, WithArguments(123)] $mode,
) {
}
}
5 changes: 3 additions & 2 deletions tests/PhpGenerator/expected/ClassType.from.expect
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ class Class9
* Returns file handle
*/
#[ExampleAttribute]
public function getHandle(#[WithArguments(123)] $mode)
{
public function getHandle(
#[WithArguments(123)] $mode,
) {
}
}

Expand Down
5 changes: 3 additions & 2 deletions tests/PhpGenerator/expected/Extractor.classes.81.expect
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ class Class12
private readonly string $bar;


public function __construct(private readonly string $foo)
{
public function __construct(
private readonly string $foo,
) {
$this->bar = "foobar";
}
}
5 changes: 3 additions & 2 deletions tests/PhpGenerator/expected/Extractor.classes.expect
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ class Class9
* Returns file handle
*/
#[ExampleAttribute]
public function getHandle(#[WithArguments(123)] $mode)
{
public function getHandle(
#[WithArguments(123)] $mode,
) {
}
}

Expand Down

0 comments on commit cd40df5

Please sign in to comment.