File tree Expand file tree Collapse file tree 3 files changed +8
-0
lines changed
Expand file tree Collapse file tree 3 files changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -515,6 +515,8 @@ class MyPrinter extends Nette\PhpGenerator\Printer
515515 public bool $bracesOnNextLine = true;
516516 // place one parameter in one line, even if it has an attribute or is promoted
517517 public bool $singleParameterOnOneLine = false;
518+ // omits namespaces that do not contain any class or function
519+ public bool $omitEmptyNamespaces = true;
518520 // separator between the right parenthesis and return type of functions and methods
519521 public string $returnTypeColon = ': ';
520522}
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ class Printer
2626 public string $ returnTypeColon = ': ' ;
2727 public bool $ bracesOnNextLine = true ;
2828 public bool $ singleParameterOnOneLine = false ;
29+ public bool $ omitEmptyNamespaces = true ;
2930 protected ?PhpNamespace $ namespace = null ;
3031 protected ?Dumper $ dumper ;
3132 private bool $ resolveTypes = true ;
@@ -276,6 +277,10 @@ public function printNamespace(PhpNamespace $namespace): string
276277 $ items [] = $ this ->printFunction ($ function , $ namespace );
277278 }
278279
280+ if (!$ items && $ this ->omitEmptyNamespaces ) {
281+ return '' ;
282+ }
283+
279284 $ body = ($ uses ? $ uses . "\n" : '' )
280285 . implode ("\n" , $ items );
281286
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ require __DIR__ . '/../bootstrap.php';
99
1010
1111$ printer = new Printer ;
12+ $ printer ->omitEmptyNamespaces = false ;
1213$ namespace = new PhpNamespace ('Foo ' );
1314$ namespace ->addUse ('Example\Foo\EmailAlias\Bar ' );
1415$ namespace ->addUse ('Example\Foo\Email\Test ' );
You can’t perform that action at this time.
0 commit comments