Skip to content

Commit be11933

Browse files
committed
up: remove some util methods
1 parent ee9ce7f commit be11933

File tree

3 files changed

+10
-36
lines changed

3 files changed

+10
-36
lines changed

src/Util/FormatUtil.php

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
use Toolkit\Cli\ColorTag;
1313
use Toolkit\Stdlib\Arr\ArrayHelper;
14-
use Toolkit\Stdlib\Helper\Format;
1514
use Toolkit\Stdlib\Helper\JsonHelper;
1615
use Toolkit\Stdlib\Str;
1716
use Toolkit\Sys\Sys;
@@ -25,6 +24,7 @@
2524
use function is_int;
2625
use function is_numeric;
2726
use function is_scalar;
27+
use function preg_match;
2828
use function rtrim;
2929
use function str_repeat;
3030
use function str_replace;
@@ -136,19 +136,22 @@ public static function wrapText(string $text, int $indent = 0, int $width = 0):
136136
}
137137

138138
/**
139+
* Align command option names.
140+
*
139141
* @param array $options
140142
*
141143
* @return array
144+
* @deprecated Please use {@see FlagUtil::alignOptions()}
142145
*/
143146
public static function alignOptions(array $options): array
144147
{
145148
if (!$options) {
146149
return [];
147150
}
148151

149-
// e.g '-h, --help'
150-
$hasShort = (bool)strpos(implode('', array_keys($options)), ',');
151-
if (!$hasShort) {
152+
// check has short option. e.g '-h, --help'
153+
$nameString = implode('|', array_keys($options));
154+
if (preg_match('/\|-\w/', $nameString) !== 1) {
152155
return $options;
153156
}
154157

@@ -171,34 +174,6 @@ public static function alignOptions(array $options): array
171174
return $formatted;
172175
}
173176

174-
/**
175-
* ```
176-
* FormatUtil::memoryUsage(memory_get_usage(true));
177-
* ```
178-
*
179-
* @param float|int $memory
180-
*
181-
* @return string
182-
* @deprecated use Format::memory($secs);
183-
*/
184-
public static function memoryUsage(float|int $memory): string
185-
{
186-
return Format::memory($memory);
187-
}
188-
189-
/**
190-
* format timestamp to how long ago
191-
*
192-
* @param int $secs
193-
*
194-
* @return string
195-
* @deprecated use Format::howLongAgo($secs);
196-
*/
197-
public static function howLongAgo(int $secs): string
198-
{
199-
return Format::howLongAgo($secs);
200-
}
201-
202177
/**
203178
* Splice array
204179
*

src/Util/Helper.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Inhere\Console\Concern\RuntimeProfileTrait;
1414
use Inhere\Console\ConsoleConst;
1515
use InvalidArgumentException;
16-
use Iterator;
1716
use RecursiveCallbackFilterIterator;
1817
use RecursiveDirectoryIterator;
1918
use RecursiveIteratorIterator;

src/Util/ProgressBar.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ private static function loadDefaultParsers(): array
595595
return $display;
596596
},
597597
'elapsed' => static function (self $bar) {
598-
return FormatUtil::howLongAgo(time() - $bar->getStartTime());
598+
return Format::howLongAgo(time() - $bar->getStartTime());
599599
},
600600
'remaining' => static function (self $bar) {
601601
if (!$bar->getMaxSteps()) {
@@ -609,7 +609,7 @@ private static function loadDefaultParsers(): array
609609
$remaining = (int)round((time() - $bar->getStartTime()) / $progress * ($bar->getMaxSteps() - $progress));
610610
}
611611

612-
return FormatUtil::howLongAgo($remaining);
612+
return Format::howLongAgo($remaining);
613613
},
614614
'estimated' => static function (self $bar) {
615615
if (!$bar->getMaxSteps()) {
@@ -623,7 +623,7 @@ private static function loadDefaultParsers(): array
623623
$estimated = (int)round((time() - $bar->getStartTime()) / $bar->getProgress() * $bar->getMaxSteps());
624624
}
625625

626-
return FormatUtil::howLongAgo($estimated);
626+
return Format::howLongAgo($estimated);
627627
},
628628
'memory' => static function () {
629629
return Format::memory(memory_get_usage(true));

0 commit comments

Comments
 (0)