Skip to content

Commit f20fcb6

Browse files
authored
Merge pull request #41 from xp-framework/feature/declared-name
Add lang.reflection.Type::declaredName()
2 parents 20e8ec0 + 37b662a commit f20fcb6

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use org\example\{Base, Inject, Fixture};
2929
$type= Reflection::type(Fixture::class);
3030

3131
$type->name(); // org.example.Fixture
32+
$type->declaredName(); // Fixture
3233
$type->literal(); // Fixture::class
3334
$type->modifiers(); // Modifiers<public>
3435
$type->comment(); // (api doc comment)

src/main/php/lang/reflection/Type.class.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public function __construct($reflect) {
2020
/** Returns type name (in dotted form) */
2121
public function name(): string { return strtr($this->reflect->name, '\\', '.'); }
2222

23+
/** Returns declared name (without namespace) */
24+
public function declaredName(): string { return $this->reflect->getShortName(); }
25+
2326
/** Returns type literal (in namespaced form) */
2427
public function literal(): string { return $this->reflect->name; }
2528

src/test/php/lang/reflection/unittest/TypeTest.class.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ public function package() {
4949
Assert::equals(new Package(__NAMESPACE__), $this->fixture->package());
5050
}
5151

52+
#[Test]
53+
public function declaredName() {
54+
$qualified= nameof($this).'Fixture';
55+
Assert::equals(substr($qualified, strrpos($qualified, '.') + 1), $this->fixture->declaredName());
56+
}
57+
5258
#[Test]
5359
public function global_namespace() {
5460
Assert::equals(new Package(), Reflection::of(\Throwable::class)->package());

0 commit comments

Comments
 (0)