@@ -35,10 +35,19 @@ class Printer
35
35
/** @var ?PhpNamespace */
36
36
protected $ namespace ;
37
37
38
+ /** @var ?Dumper */
39
+ protected $ dumper ;
40
+
38
41
/** @var bool */
39
42
private $ resolveTypes = true ;
40
43
41
44
45
+ public function __construct ()
46
+ {
47
+ $ this ->dumper = new Dumper ;
48
+ }
49
+
50
+
42
51
public function printFunction (GlobalFunction $ function , PhpNamespace $ namespace = null ): string
43
52
{
44
53
$ this ->namespace = $ this ->resolveTypes ? $ namespace : null ;
@@ -63,7 +72,7 @@ public function printClosure(Closure $closure, PhpNamespace $namespace = null):
63
72
foreach ($ closure ->getUses () as $ param ) {
64
73
$ uses [] = ($ param ->isReference () ? '& ' : '' ) . '$ ' . $ param ->getName ();
65
74
}
66
- $ useStr = strlen ($ tmp = implode (', ' , $ uses )) > ( new Dumper ) ->wrapLength && count ($ uses ) > 1
75
+ $ useStr = strlen ($ tmp = implode (', ' , $ uses )) > $ this -> dumper ->wrapLength && count ($ uses ) > 1
67
76
? "\n" . $ this ->indentation . implode (", \n" . $ this ->indentation , $ uses ) . "\n"
68
77
: $ tmp ;
69
78
@@ -270,7 +279,7 @@ protected function indent(string $s): string
270
279
271
280
protected function dump ($ var , int $ column = 0 ): string
272
281
{
273
- return ( new Dumper ) ->dump ($ var , $ column );
282
+ return $ this -> dumper ->dump ($ var , $ column );
274
283
}
275
284
276
285
@@ -321,7 +330,7 @@ public function printParameters($function, int $column = 0): string
321
330
322
331
$ line = implode (', ' , $ params );
323
332
324
- return count ($ params ) > 1 && ($ special || strlen ($ line ) + $ column > ( new Dumper ) ->wrapLength )
333
+ return count ($ params ) > 1 && ($ special || strlen ($ line ) + $ column > $ this -> dumper ->wrapLength )
325
334
? "( \n" . $ this ->indent (implode (", \n" , $ params )) . ($ special ? ', ' : '' ) . "\n) "
326
335
: "( $ line) " ;
327
336
}
@@ -362,7 +371,7 @@ private function printAttributes(array $attrs, bool $inline = false): string
362
371
}
363
372
$ items = [];
364
373
foreach ($ attrs as $ attr ) {
365
- $ args = ( new Dumper ) ->format ('...?: ' , $ attr ->getArguments ());
374
+ $ args = $ this -> dumper ->format ('...?: ' , $ attr ->getArguments ());
366
375
$ items [] = $ this ->printType ($ attr ->getName (), false ) . ($ args ? "( $ args) " : '' );
367
376
}
368
377
return $ inline
0 commit comments