From c334161304f7734ebc6a87c6634b3166f49419e9 Mon Sep 17 00:00:00 2001 From: inhere Date: Mon, 19 Apr 2021 21:59:09 +0800 Subject: [PATCH] up: use Str::ucwords inteadof the ucwords() --- src/Component/Formatter/Panel.php | 6 +++--- src/Component/Formatter/Section.php | 3 +-- src/Component/Formatter/SingleList.php | 4 ++-- src/Component/Formatter/Table.php | 3 +-- src/Component/Formatter/Title.php | 2 +- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Component/Formatter/Panel.php b/src/Component/Formatter/Panel.php index 01eeee3..c8225a6 100644 --- a/src/Component/Formatter/Panel.php +++ b/src/Component/Formatter/Panel.php @@ -23,7 +23,6 @@ use function rtrim; use function strip_tags; use function trim; -use function ucwords; use const PHP_EOL; /** @@ -159,7 +158,7 @@ public static function show($data, string $title = 'Information Panel', array $o // output title if ($title) { - $title = ucwords($title); + $title = Str::ucwords($title); $titleLength = mb_strlen($title, 'UTF-8'); $panelWidth = $panelWidth > $titleLength ? $panelWidth : $titleLength; @@ -257,7 +256,8 @@ public function format(): string // output title if ($title) { - $title = ucwords($title); + $title = Str::ucwords($title); + $titleLength = mb_strlen($title, 'UTF-8'); $panelWidth = $panelWidth > $titleLength ? $panelWidth : $titleLength; $indentSpace = Str::pad(' ', ceil($panelWidth / 2) - ceil($titleLength / 2) + 2 * 2, ' '); diff --git a/src/Component/Formatter/Section.php b/src/Component/Formatter/Section.php index 69d91ee..8c16687 100644 --- a/src/Component/Formatter/Section.php +++ b/src/Component/Formatter/Section.php @@ -11,7 +11,6 @@ use function implode; use function is_array; use function trim; -use function ucwords; use const PHP_EOL; /** @@ -43,7 +42,7 @@ public static function show(string $title, $body, array $opts = []): void $indent = (int)$opts['indent'] >= 0 ? $opts['indent'] : 2; $indentStr = Str::pad(self::CHAR_SPACE, $indent, self::CHAR_SPACE); - $title = ucwords(trim($title)); + $title = Str::ucwords(trim($title)); $tLength = Str::len($title); $width = $width > 10 ? $width : 80; diff --git a/src/Component/Formatter/SingleList.php b/src/Component/Formatter/SingleList.php index 161555d..90c4072 100644 --- a/src/Component/Formatter/SingleList.php +++ b/src/Component/Formatter/SingleList.php @@ -6,9 +6,9 @@ use Inhere\Console\Console; use Inhere\Console\Util\FormatUtil; use Toolkit\Cli\ColorTag; +use Toolkit\Stdlib\Str; use function array_merge; use function trim; -use function ucwords; use const PHP_EOL; /** @@ -50,7 +50,7 @@ public static function show($data, string $title = 'Information', array $opts = // title if ($title) { - $title = ucwords(trim($title)); + $title = Str::ucwords(trim($title)); $string .= ColorTag::wrap($title, $opts['titleStyle']) . PHP_EOL; } diff --git a/src/Component/Formatter/Table.php b/src/Component/Formatter/Table.php index 2be79f6..063d73e 100644 --- a/src/Component/Formatter/Table.php +++ b/src/Component/Formatter/Table.php @@ -20,7 +20,6 @@ use function count; use function is_bool; use function is_string; -use function ucwords; /** * Class Table - Tabular data display @@ -166,7 +165,7 @@ public static function show(array $data, string $title = 'Data Table', array $op // output title if ($title) { $tStyle = $opts['titleStyle'] ?: 'bold'; - $title = ucwords(trim($title)); + $title = Str::ucwords(trim($title)); $titleLength = Str::utf8Len($title, 'UTF-8'); $indentSpace = Str::pad(' ', ceil($tableWidth / 2) - ceil($titleLength / 2) + ($columnCount * 2), ' '); $buf->write(" {$indentSpace}<$tStyle>{$title}\n"); diff --git a/src/Component/Formatter/Title.php b/src/Component/Formatter/Title.php index 0363ef7..552850a 100644 --- a/src/Component/Formatter/Title.php +++ b/src/Component/Formatter/Title.php @@ -43,7 +43,7 @@ public static function show(string $title, array $opts = []): void $indentStr = Str::pad(self::CHAR_SPACE, $indent, self::CHAR_SPACE); } - $title = $opts['ucWords'] ? ucwords(trim($title)) : trim($title); + $title = $opts['ucWords'] ? Str::ucwords(trim($title)) : trim($title); $tLength = Str::len($title); $width = $width > 10 ? $width : 80;