Skip to content

Commit

Permalink
PhpNamespace::addUse() ignores names in current namespace [Closes #96]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 22, 2021
1 parent 666b591 commit 8aa6d4c
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/PhpGenerator/PhpNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ public function addUseConstant(string $name, string $alias = null): self
public function getUses(string $of = self::NAME_NORMAL): array
{
asort($this->aliases[$of]);
return $this->aliases[$of];
return array_filter(
$this->aliases[$of],
function ($name, $alias) { return strcasecmp(($this->name ? $this->name . '\\' : '') . $alias, $name); },
ARRAY_FILTER_USE_BOTH,
);
}


Expand Down
1 change: 0 additions & 1 deletion tests/PhpGenerator/expected/PhpFile.globalNamespace.expect
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use A;
use B as C;

class CA
Expand Down
1 change: 0 additions & 1 deletion tests/PhpGenerator/expected/Printer.namespace.expect
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace Foo;

use Bar\C;
use Foo\D;
use Foo\D as E;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace Foo;

use Bar\C;
use Foo\D;
use Foo\D as E;

/**
Expand Down

0 comments on commit 8aa6d4c

Please sign in to comment.