Skip to content

Commit 253cee4

Browse files
committed
bug #150 make entity, related class without namespace (LeJeanbono)
This PR was merged into the 1.0-dev branch. Discussion ---------- make entity, related class without namespace For #148 Commits ------- 5e5e5e6 make entity, related class without namespace
2 parents afbf1c0 + 5e5e5e6 commit 253cee4

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Str.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ public static function asEventMethod(string $eventName): string
117117

118118
public static function getShortClassName(string $fullClassName): string
119119
{
120-
return substr($fullClassName, strrpos($fullClassName, '\\') + 1);
120+
if (!empty(self::getNamespace($fullClassName))) {
121+
return substr($fullClassName, strrpos($fullClassName, '\\') + 1);
122+
} else {
123+
return $fullClassName;
124+
}
121125
}
122126

123127
public static function getNamespace(string $fullClassName): string

tests/StrTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,18 @@ public function getAsCamelCaseTests()
161161

162162
yield ['foo_bar.baz\\pizza', 'FooBarBazPizza'];
163163
}
164+
165+
/**
166+
* @dataProvider getShortClassNameCaseTests
167+
*/
168+
public function testShortClassName(string $original, string $expected)
169+
{
170+
$this->assertSame($expected, Str::getShortClassName($original));
171+
}
172+
173+
public function getShortClassNameCaseTests()
174+
{
175+
yield ['App\\Entity\\Foo', 'Foo'];
176+
yield ['Foo', 'Foo'];
177+
}
164178
}

0 commit comments

Comments
 (0)