From b472246cc1ff58fb25b9b53df2013dbf09269f42 Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Thu, 28 Mar 2024 20:07:37 +0100 Subject: [PATCH] Adjust lang.reflection.Type::package() to return Package() for global classes --- src/main/php/lang/reflection/Type.class.php | 7 +++---- src/test/php/lang/reflection/unittest/TypeTest.class.php | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/php/lang/reflection/Type.class.php b/src/main/php/lang/reflection/Type.class.php index 60f97af..9803d6f 100755 --- a/src/main/php/lang/reflection/Type.class.php +++ b/src/main/php/lang/reflection/Type.class.php @@ -83,13 +83,12 @@ public function is($type): bool { } /** - * Returns this type's package, or NULL if this type is in the global namespace. + * Returns this type's package * - * @return ?lang.reflection.Package + * @return lang.reflection.Package */ public function package() { - $name= $this->reflect->getNamespaceName(); - return $name ? new Package($name) : null; + return new Package($this->reflect->getNamespaceName()); } /** diff --git a/src/test/php/lang/reflection/unittest/TypeTest.class.php b/src/test/php/lang/reflection/unittest/TypeTest.class.php index ee25e8b..3fe9e25 100755 --- a/src/test/php/lang/reflection/unittest/TypeTest.class.php +++ b/src/test/php/lang/reflection/unittest/TypeTest.class.php @@ -51,7 +51,7 @@ public function package() { #[Test] public function global_namespace() { - Assert::null(Reflection::of(\Throwable::class)->package()); + Assert::equals(new Package(), Reflection::of(\Throwable::class)->package()); } #[Test]