Skip to content
This repository was archived by the owner on Nov 14, 2019. It is now read-only.

Commit 9173137

Browse files
committed
minor #283 Use Symfony's helper to format the memory values (javiereguiluz)
This PR was merged into the 1.0-dev branch. Discussion ---------- Use Symfony's helper to format the memory values Less code to maintain for us and the output is almost the same: ### Before ![before](https://cloud.githubusercontent.com/assets/73419/19228575/e50633b2-8ec6-11e6-97c6-1615528aef7e.gif) ### After ![after](https://cloud.githubusercontent.com/assets/73419/19228577/e8476f8c-8ec6-11e6-89bc-7a00274ffc43.gif) --- Thanks to @mickaelandrieu who tweeted about this helper method and allowed me to learn about it! Commits ------- c3f8200 Use Symfony's helper to format the memory values
2 parents b61f637 + c3f8200 commit 9173137

File tree

1 file changed

+3
-22
lines changed

1 file changed

+3
-22
lines changed

src/Symfony/Installer/DownloadCommand.php

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use GuzzleHttp\Event\ProgressEvent;
2222
use GuzzleHttp\Utils;
2323
use Symfony\Component\Console\Command\Command;
24+
use Symfony\Component\Console\Helper\Helper;
2425
use Symfony\Component\Console\Helper\ProgressBar;
2526
use Symfony\Component\Console\Input\InputInterface;
2627
use Symfony\Component\Console\Output\OutputInterface;
@@ -146,10 +147,10 @@ protected function download()
146147

147148
if (null === $progressBar) {
148149
ProgressBar::setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {
149-
return $this->formatSize($bar->getMaxSteps());
150+
return Helper::formatMemory($bar->getMaxSteps());
150151
});
151152
ProgressBar::setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
152-
return str_pad($this->formatSize($bar->getProgress()), 11, ' ', STR_PAD_LEFT);
153+
return str_pad(Helper::formatMemory($bar->getProgress()), 11, ' ', STR_PAD_LEFT);
153154
});
154155

155156
$progressBar = new ProgressBar($this->output, $downloadSize);
@@ -449,26 +450,6 @@ protected function checkPermissions()
449450
return $this;
450451
}
451452

452-
/**
453-
* Utility method to show the number of bytes in a readable format.
454-
*
455-
* @param int $bytes The number of bytes to format
456-
*
457-
* @return string The human readable string of bytes (e.g. 4.32MB)
458-
*/
459-
protected function formatSize($bytes)
460-
{
461-
$units = array('B', 'KB', 'MB', 'GB', 'TB');
462-
463-
$bytes = max($bytes, 0);
464-
$pow = $bytes ? floor(log($bytes, 1024)) : 0;
465-
$pow = min($pow, count($units) - 1);
466-
467-
$bytes /= pow(1024, $pow);
468-
469-
return number_format($bytes, 2).' '.$units[$pow];
470-
}
471-
472453
/**
473454
* Formats the error message contained in the given Requirement item
474455
* using the optional line length provided.

0 commit comments

Comments
 (0)