From c3f8200daa77b71f6c3fa0e9f0eebd900f8ed1e5 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 10 Oct 2016 08:51:31 +0200 Subject: [PATCH] Use Symfony's helper to format the memory values --- src/Symfony/Installer/DownloadCommand.php | 25 +++-------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/src/Symfony/Installer/DownloadCommand.php b/src/Symfony/Installer/DownloadCommand.php index c3bf3d7..f24c54a 100644 --- a/src/Symfony/Installer/DownloadCommand.php +++ b/src/Symfony/Installer/DownloadCommand.php @@ -21,6 +21,7 @@ use GuzzleHttp\Event\ProgressEvent; use GuzzleHttp\Utils; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Helper\Helper; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -146,10 +147,10 @@ protected function download() if (null === $progressBar) { ProgressBar::setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) { - return $this->formatSize($bar->getMaxSteps()); + return Helper::formatMemory($bar->getMaxSteps()); }); ProgressBar::setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) { - return str_pad($this->formatSize($bar->getProgress()), 11, ' ', STR_PAD_LEFT); + return str_pad(Helper::formatMemory($bar->getProgress()), 11, ' ', STR_PAD_LEFT); }); $progressBar = new ProgressBar($this->output, $downloadSize); @@ -449,26 +450,6 @@ protected function checkPermissions() return $this; } - /** - * Utility method to show the number of bytes in a readable format. - * - * @param int $bytes The number of bytes to format - * - * @return string The human readable string of bytes (e.g. 4.32MB) - */ - protected function formatSize($bytes) - { - $units = array('B', 'KB', 'MB', 'GB', 'TB'); - - $bytes = max($bytes, 0); - $pow = $bytes ? floor(log($bytes, 1024)) : 0; - $pow = min($pow, count($units) - 1); - - $bytes /= pow(1024, $pow); - - return number_format($bytes, 2).' '.$units[$pow]; - } - /** * Formats the error message contained in the given Requirement item * using the optional line length provided.