Skip to content

Commit

Permalink
fix(documentator): `\LastDragon_ru\LaraASP\Documentator\Utils\Text::g…
Browse files Browse the repository at this point in the history
…etPathTitle()` will convert `-` to space and `mb_ucfirst()` call added.
  • Loading branch information
LastDragon-ru committed Feb 14, 2025
1 parent 5f65c5b commit 5410f3a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- markdownlint-disable -->

## no title
## No title

Package readme.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Summary text with special characters `<`, `>`, `&`.

[Read more](<packages/package/README.md>).

## no title
## No title

Package readme.

Expand Down
4 changes: 3 additions & 1 deletion packages/documentator/src/Utils/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use function mb_strlen;
use function mb_substr;
use function mb_trim;
use function mb_ucfirst;
use function min;
use function pathinfo;
use function preg_replace;
Expand Down Expand Up @@ -79,10 +80,11 @@ public static function getLines(string $text): array {

public static function getPathTitle(string $path): string {
$title = pathinfo($path, PATHINFO_FILENAME);
$title = str_replace(['_', '.'], ' ', $title);
$title = str_replace(['-', '_', '.'], ' ', $title);
$title = (string) preg_replace('/(\p{Ll})(\p{Lu})/u', '$1 $2', $title);
$title = (string) preg_replace('/\s+/u', ' ', $title);
$title = mb_trim($title);
$title = mb_ucfirst($title);

return $title;
}
Expand Down
5 changes: 3 additions & 2 deletions packages/documentator/src/Utils/TextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ public function testGetLines(): void {
}

public function testGetPathTitle(): void {
self::assertSame('file', Text::getPathTitle('path/to/file.txt'));
self::assertSame('file Name', Text::getPathTitle('path/to/fileName.txt'));
self::assertSame('File', Text::getPathTitle('path/to/file.txt'));
self::assertSame('File name', Text::getPathTitle('path/to/file-name.txt'));
self::assertSame('File Name', Text::getPathTitle('path/to/fileName.txt'));
self::assertSame('File name second', Text::getPathTitle('path/to/File name.second.txt'));
self::assertSame('File name', Text::getPathTitle('path/to/File name'));
}
Expand Down

0 comments on commit 5410f3a

Please sign in to comment.