From 8aa6d4c6048b58097aa75127e4d9f873934fef6f Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 16 Nov 2021 15:34:00 +0100 Subject: [PATCH] PhpNamespace::addUse() ignores names in current namespace [Closes #96] --- src/PhpGenerator/PhpNamespace.php | 6 +++++- tests/PhpGenerator/expected/PhpFile.globalNamespace.expect | 1 - tests/PhpGenerator/expected/Printer.namespace.expect | 1 - .../expected/Printer.namespace.unresolved.expect | 1 - 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/PhpGenerator/PhpNamespace.php b/src/PhpGenerator/PhpNamespace.php index cbca0fc1..55fb6a46 100644 --- a/src/PhpGenerator/PhpNamespace.php +++ b/src/PhpGenerator/PhpNamespace.php @@ -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, + ); } diff --git a/tests/PhpGenerator/expected/PhpFile.globalNamespace.expect b/tests/PhpGenerator/expected/PhpFile.globalNamespace.expect index 606f1b0b..396ce925 100644 --- a/tests/PhpGenerator/expected/PhpFile.globalNamespace.expect +++ b/tests/PhpGenerator/expected/PhpFile.globalNamespace.expect @@ -1,6 +1,5 @@