Skip to content

Commit cd40df5

Browse files
committed
Printer: promoted parameters / parameter with attributes are always multiline
1 parent c4e433f commit cd40df5

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

src/PhpGenerator/Printer.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ protected function printParameters(Closure|GlobalFunction|Method $function, int
324324
{
325325
$params = [];
326326
$list = $function->getParameters();
327-
$special = false;
327+
$multiline = false;
328328

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

347-
$special = $special || $promoted || $attrs;
347+
$multiline = $multiline || $promoted || $attrs;
348348
}
349349

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

352-
return count($params) > 1 && ($special || strlen($line) + $column > $this->wrapLength)
353+
return $multiline
353354
? "(\n" . $this->indent(implode(",\n", $params)) . ",\n)"
354355
: "($line)";
355356
}

tests/PhpGenerator/expected/ClassType.attributes.expect

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class Example
2020
* Returns file handle.
2121
*/
2222
#[ExampleAttribute]
23-
public function getHandle(#[ExampleAttribute, WithArguments(123)] $mode)
24-
{
23+
public function getHandle(
24+
#[ExampleAttribute, WithArguments(123)] $mode,
25+
) {
2526
}
2627
}

tests/PhpGenerator/expected/ClassType.from.expect

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ class Class9
138138
* Returns file handle
139139
*/
140140
#[ExampleAttribute]
141-
public function getHandle(#[WithArguments(123)] $mode)
142-
{
141+
public function getHandle(
142+
#[WithArguments(123)] $mode,
143+
) {
143144
}
144145
}
145146

tests/PhpGenerator/expected/Extractor.classes.81.expect

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ class Class12
3333
private readonly string $bar;
3434

3535

36-
public function __construct(private readonly string $foo)
37-
{
36+
public function __construct(
37+
private readonly string $foo,
38+
) {
3839
$this->bar = "foobar";
3940
}
4041
}

tests/PhpGenerator/expected/Extractor.classes.expect

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ class Class9
148148
* Returns file handle
149149
*/
150150
#[ExampleAttribute]
151-
public function getHandle(#[WithArguments(123)] $mode)
152-
{
151+
public function getHandle(
152+
#[WithArguments(123)] $mode,
153+
) {
153154
}
154155
}
155156

0 commit comments

Comments
 (0)