Skip to content

Commit

Permalink
up: remove some util methods
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Dec 5, 2021
1 parent ee9ce7f commit be11933
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 36 deletions.
39 changes: 7 additions & 32 deletions src/Util/FormatUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

use Toolkit\Cli\ColorTag;
use Toolkit\Stdlib\Arr\ArrayHelper;
use Toolkit\Stdlib\Helper\Format;
use Toolkit\Stdlib\Helper\JsonHelper;
use Toolkit\Stdlib\Str;
use Toolkit\Sys\Sys;
Expand All @@ -25,6 +24,7 @@
use function is_int;
use function is_numeric;
use function is_scalar;
use function preg_match;
use function rtrim;
use function str_repeat;
use function str_replace;
Expand Down Expand Up @@ -136,19 +136,22 @@ public static function wrapText(string $text, int $indent = 0, int $width = 0):
}

/**
* Align command option names.
*
* @param array $options
*
* @return array
* @deprecated Please use {@see FlagUtil::alignOptions()}
*/
public static function alignOptions(array $options): array
{
if (!$options) {
return [];
}

// e.g '-h, --help'
$hasShort = (bool)strpos(implode('', array_keys($options)), ',');
if (!$hasShort) {
// check has short option. e.g '-h, --help'
$nameString = implode('|', array_keys($options));
if (preg_match('/\|-\w/', $nameString) !== 1) {
return $options;
}

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

/**
* ```
* FormatUtil::memoryUsage(memory_get_usage(true));
* ```
*
* @param float|int $memory
*
* @return string
* @deprecated use Format::memory($secs);
*/
public static function memoryUsage(float|int $memory): string
{
return Format::memory($memory);
}

/**
* format timestamp to how long ago
*
* @param int $secs
*
* @return string
* @deprecated use Format::howLongAgo($secs);
*/
public static function howLongAgo(int $secs): string
{
return Format::howLongAgo($secs);
}

/**
* Splice array
*
Expand Down
1 change: 0 additions & 1 deletion src/Util/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Inhere\Console\Concern\RuntimeProfileTrait;
use Inhere\Console\ConsoleConst;
use InvalidArgumentException;
use Iterator;
use RecursiveCallbackFilterIterator;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
Expand Down
6 changes: 3 additions & 3 deletions src/Util/ProgressBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ private static function loadDefaultParsers(): array
return $display;
},
'elapsed' => static function (self $bar) {
return FormatUtil::howLongAgo(time() - $bar->getStartTime());
return Format::howLongAgo(time() - $bar->getStartTime());
},
'remaining' => static function (self $bar) {
if (!$bar->getMaxSteps()) {
Expand All @@ -609,7 +609,7 @@ private static function loadDefaultParsers(): array
$remaining = (int)round((time() - $bar->getStartTime()) / $progress * ($bar->getMaxSteps() - $progress));
}

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

return FormatUtil::howLongAgo($estimated);
return Format::howLongAgo($estimated);
},
'memory' => static function () {
return Format::memory(memory_get_usage(true));
Expand Down

0 comments on commit be11933

Please sign in to comment.