File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -217,6 +217,14 @@ public function lowerFirst(): static
217217 return $ this ->createOrModify (lower_first ($ this ->value ));
218218 }
219219
220+ /**
221+ * Keeps only the base name of the instance.
222+ */
223+ public function basename (string $ suffix = '' ): static
224+ {
225+ return $ this ->createOrModify (basename ($ this ->value , $ suffix ));
226+ }
227+
220228 /**
221229 * Keeps only the base name of the instance, assuming the instance is a class name.
222230 */
Original file line number Diff line number Diff line change @@ -648,4 +648,19 @@ public function test_tap(): void
648648 $ this ->assertSame ($ string , $ result );
649649 $ this ->assertEquals ('foo ' , $ log );
650650 }
651+
652+ public function test_class_basename (): void
653+ {
654+ $ this ->assertSame ('ImmutableString ' , str (ImmutableString::class)->classBasename ()->toString ());
655+ $ this ->assertSame ('ImmutableString ' , str ('ImmutableString ' )->classBasename ()->toString ());
656+ $ this ->assertSame ('' , str ()->classBasename ()->toString ());
657+ }
658+
659+ public function test_basename (): void
660+ {
661+ $ this ->assertSame ('file.txt ' , str ('path/to/file.txt ' )->basename ()->toString ());
662+ $ this ->assertSame ('file.txt ' , str ('file.txt ' )->basename ()->toString ());
663+ $ this ->assertSame ('file ' , str ('file.txt ' )->basename ('.txt ' )->toString ());
664+ $ this ->assertSame ('' , str ()->basename ()->toString ());
665+ }
651666}
You can’t perform that action at this time.
0 commit comments