File tree Expand file tree Collapse file tree 3 files changed +42
-3
lines changed Expand file tree Collapse file tree 3 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -75,11 +75,14 @@ public function __toString()
75
75
. 'function '
76
76
. ($ this ->returnReference ? '& ' : '' )
77
77
. $ this ->name
78
- . $ this ->parametersToString ()
78
+ . ( $ params = $ this ->parametersToString () )
79
79
. $ this ->returnTypeToString ()
80
80
. ($ this ->abstract || $ this ->body === false
81
81
? '; '
82
- : "\n{ \n" . Nette \Utils \Strings::indent (ltrim (rtrim ($ this ->body ) . "\n" ), 1 ) . '} ' );
82
+ : (strpos ($ params , "\n" ) === false ? "\n" : ' ' )
83
+ . "{ \n"
84
+ . Nette \Utils \Strings::indent (ltrim (rtrim ($ this ->body ) . "\n" ), 1 )
85
+ . '} ' );
83
86
}
84
87
85
88
Original file line number Diff line number Diff line change @@ -216,7 +216,10 @@ protected function parametersToString()
216
216
. '$ ' . $ param ->getName ()
217
217
. ($ param ->hasDefaultValue () && !$ variadic ? ' = ' . Helpers::dump ($ param ->defaultValue ) : '' );
218
218
}
219
- return '( ' . implode (', ' , $ params ) . ') ' ;
219
+
220
+ return strlen ($ tmp = implode (', ' , $ params )) > Helpers::WRAP_LENGTH
221
+ ? "( \n\t" . implode (", \n\t" , $ params ) . "\n) "
222
+ : "( $ tmp) " ;
220
223
}
221
224
222
225
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Nette \PhpGenerator \Method ;
4
+ use Tester \Assert ;
5
+
6
+ require __DIR__ . '/../bootstrap.php ' ;
7
+
8
+
9
+ $ method = (new Method ('create ' ))
10
+ ->setBody ('return null; ' );
11
+
12
+ for ($ name = 'a ' ; $ name < 'm ' ; $ name ++) {
13
+ $ method ->addParameter ($ name )->setTypeHint ('string ' );
14
+ }
15
+
16
+ Assert::match (
17
+ 'function create(
18
+ string $a,
19
+ string $b,
20
+ string $c,
21
+ string $d,
22
+ string $e,
23
+ string $f,
24
+ string $g,
25
+ string $h,
26
+ string $i,
27
+ string $j,
28
+ string $k,
29
+ string $l
30
+ ) {
31
+ return null;
32
+ }
33
+ ' , (string ) $ method );
You can’t perform that action at this time.
0 commit comments