File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments