File tree Expand file tree Collapse file tree 3 files changed +44
-3
lines changed Expand file tree Collapse file tree 3 files changed +44
-3
lines changed Original file line number Diff line number Diff line change @@ -67,11 +67,14 @@ public function __toString(): string
67
67
. 'function '
68
68
. ($ this ->returnReference ? '& ' : '' )
69
69
. $ this ->name
70
- . $ this ->parametersToString ()
70
+ . ( $ params = $ this ->parametersToString () )
71
71
. $ this ->returnTypeToString ()
72
72
. ($ this ->abstract || $ this ->body === null
73
73
? '; '
74
- : "\n{ \n" . Nette \Utils \Strings::indent (ltrim (rtrim ($ this ->body ) . "\n" ), 1 ) . '} ' );
74
+ : (strpos ($ params , "\n" ) === false ? "\n" : ' ' )
75
+ . "{ \n"
76
+ . Nette \Utils \Strings::indent (ltrim (rtrim ($ this ->body ) . "\n" ), 1 )
77
+ . '} ' );
75
78
}
76
79
77
80
Original file line number Diff line number Diff line change @@ -193,7 +193,10 @@ protected function parametersToString(): string
193
193
. '$ ' . $ param ->getName ()
194
194
. ($ param ->hasDefaultValue () && !$ variadic ? ' = ' . Helpers::dump ($ param ->getDefaultValue ()) : '' );
195
195
}
196
- return '( ' . implode (', ' , $ params ) . ') ' ;
196
+
197
+ return strlen ($ tmp = implode (', ' , $ params )) > Helpers::WRAP_LENGTH
198
+ ? "( \n\t" . implode (", \n\t" , $ params ) . "\n) "
199
+ : "( $ tmp) " ;
197
200
}
198
201
199
202
Original file line number Diff line number Diff line change
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
+ return null;
34
+ }
35
+ ' , (string ) $ method );
You can’t perform that action at this time.
0 commit comments