Permalink
Browse files

Printer: fixed use statements generation

  • Loading branch information...
dg committed Nov 27, 2018
1 parent 9ecd301 commit 7c5e08e2bcd081529890eabe8346302c0c58bf03
@@ -139,9 +139,7 @@ public function printNamespace(PhpNamespace $namespace): string
$uses = [];
foreach ($namespace->getUses() as $alias => $original) {
$useNamespace = Helpers::extractNamespace($original);
if ($name !== $useNamespace) {
if ($original !== ($name ? $name . '\\' . $alias : $alias)) {
if ($alias === $original || substr($original, -(strlen($alias) + 1)) === '\\' . $alias) {
$uses[] = "use $original;";
} else {
@@ -13,6 +13,8 @@ $printer = new Printer;
$namespace = new PhpNamespace('Foo');
$namespace->addUse('Bar\C');
$namespace->addUse('Foo\D');
$namespace->addUse('Foo\D', 'E');
$class = $namespace->addClass('A')
->setFinal(true)
@@ -1,6 +1,7 @@
namespace Foo;
use Bar\C;
use Foo\D as E;
/**
* Description of class.

0 comments on commit 7c5e08e

Please sign in to comment.