Skip to content

Commit e973ad0

Browse files
committed
PhpNamespace::addUse() ignores names in current namespace [Closes #96]
1 parent 19941d7 commit e973ad0

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

src/PhpGenerator/PhpNamespace.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ public function addUseConstant(string $name, string $alias = null): self
152152
public function getUses(string $of = self::NAME_NORMAL): array
153153
{
154154
asort($this->aliases[$of]);
155-
return $this->aliases[$of];
155+
return array_filter(
156+
$this->aliases[$of],
157+
function ($name, $alias) { return strcasecmp(($this->name ? $this->name . '\\' : '') . $alias, $name); },
158+
ARRAY_FILTER_USE_BOTH
159+
);
156160
}
157161

158162

tests/PhpGenerator/expected/PhpFile.globalNamespace.expect

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
use A;
43
use B as C;
54

65
class CA

tests/PhpGenerator/expected/Printer.namespace.expect

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace Foo;
22

33
use Bar\C;
4-
use Foo\D;
54
use Foo\D as E;
65

76
/**

tests/PhpGenerator/expected/Printer.namespace.unresolved.expect

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace Foo;
22

33
use Bar\C;
4-
use Foo\D;
54
use Foo\D as E;
65

76
/**

0 commit comments

Comments
 (0)