Skip to content

Commit d4dbd39

Browse files
committed
FunctionLike: wraps parameters when are longer than WRAP_LENGTH [Closes #28]
1 parent e2939de commit d4dbd39

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/PhpGenerator/Traits/FunctionLike.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,11 @@ protected function parametersToString(): string
193193
. '$' . $param->getName()
194194
. ($param->hasDefaultValue() && !$variadic ? ' = ' . Helpers::dump($param->getDefaultValue()) : '');
195195
}
196-
return '(' . implode(', ', $params) . ')';
196+
197+
$s = implode(', ', $params);
198+
return strlen($s) > Helpers::WRAP_LENGTH
199+
? "(\n\t" . implode(",\n\t", $params) . "\n)"
200+
: "($s)";
197201
}
198202

199203

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Nette\PhpGenerator\Method;
6+
use Tester\Assert;
7+
8+
require __DIR__ . '/../bootstrap.php';
9+
10+
11+
$method = (new Method('create'))
12+
->setBody('return null;');
13+
14+
for ($name = 'a'; $name < 'm'; $name++) {
15+
$method->addParameter($name)->setTypeHint('string');
16+
}
17+
18+
Assert::match(
19+
'function create(
20+
string $a,
21+
string $b,
22+
string $c,
23+
string $d,
24+
string $e,
25+
string $f,
26+
string $g,
27+
string $h,
28+
string $i,
29+
string $j,
30+
string $k,
31+
string $l
32+
)
33+
{
34+
return null;
35+
}
36+
', (string) $method);

0 commit comments

Comments
 (0)