From a4b26061a98fc7cbf08cca218e75646114b53895 Mon Sep 17 00:00:00 2001 From: cesar Date: Mon, 9 Nov 2020 18:39:08 -0300 Subject: [PATCH] Extracting ProgressBar's format's magic strings into const --- .../Component/Console/Helper/ProgressBar.php | 34 ++++++++++++------- .../Console/Tests/Helper/ProgressBarTest.php | 8 ++--- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/Symfony/Component/Console/Helper/ProgressBar.php b/src/Symfony/Component/Console/Helper/ProgressBar.php index 7b6b99e431859..35f733be34a5f 100644 --- a/src/Symfony/Component/Console/Helper/ProgressBar.php +++ b/src/Symfony/Component/Console/Helper/ProgressBar.php @@ -26,6 +26,16 @@ */ final class ProgressBar { + public const FORMAT_VERBOSE = 'verbose'; + public const FORMAT_VERY_VERBOSE = 'very_verbose'; + public const FORMAT_DEBUG = 'debug'; + public const FORMAT_NORMAL = 'normal'; + + private const FORMAT_VERBOSE_NOMAX = 'verbose_nomax'; + private const FORMAT_VERY_VERBOSE_NOMAX = 'very_verbose_nomax'; + private const FORMAT_DEBUG_NOMAX = 'debug_nomax'; + private const FORMAT_NORMAL_NOMAX = 'normal_nomax'; + private $barWidth = 28; private $barChar; private $emptyBarChar = '-'; @@ -489,13 +499,13 @@ private function determineBestFormat(): string switch ($this->output->getVerbosity()) { // OutputInterface::VERBOSITY_QUIET: display is disabled anyway case OutputInterface::VERBOSITY_VERBOSE: - return $this->max ? 'verbose' : 'verbose_nomax'; + return $this->max ? self::FORMAT_VERBOSE : self::FORMAT_VERBOSE_NOMAX; case OutputInterface::VERBOSITY_VERY_VERBOSE: - return $this->max ? 'very_verbose' : 'very_verbose_nomax'; + return $this->max ? self::FORMAT_VERY_VERBOSE : self::FORMAT_VERY_VERBOSE_NOMAX; case OutputInterface::VERBOSITY_DEBUG: - return $this->max ? 'debug' : 'debug_nomax'; + return $this->max ? self::FORMAT_DEBUG : self::FORMAT_DEBUG_NOMAX; default: - return $this->max ? 'normal' : 'normal_nomax'; + return $this->max ? self::FORMAT_NORMAL : self::FORMAT_NORMAL_NOMAX; } } @@ -547,17 +557,17 @@ private static function initPlaceholderFormatters(): array private static function initFormats(): array { return [ - 'normal' => ' %current%/%max% [%bar%] %percent:3s%%', - 'normal_nomax' => ' %current% [%bar%]', + self::FORMAT_NORMAL => ' %current%/%max% [%bar%] %percent:3s%%', + self::FORMAT_NORMAL_NOMAX => ' %current% [%bar%]', - 'verbose' => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%', - 'verbose_nomax' => ' %current% [%bar%] %elapsed:6s%', + self::FORMAT_VERBOSE => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%', + self::FORMAT_VERBOSE_NOMAX => ' %current% [%bar%] %elapsed:6s%', - 'very_verbose' => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s%', - 'very_verbose_nomax' => ' %current% [%bar%] %elapsed:6s%', + self::FORMAT_VERY_VERBOSE => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s%', + self::FORMAT_VERY_VERBOSE_NOMAX => ' %current% [%bar%] %elapsed:6s%', - 'debug' => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%', - 'debug_nomax' => ' %current% [%bar%] %elapsed:6s% %memory:6s%', + self::FORMAT_DEBUG => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%', + self::FORMAT_DEBUG_NOMAX => ' %current% [%bar%] %elapsed:6s% %memory:6s%', ]; } diff --git a/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php b/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php index b5d2b5f6e2645..7a1e9ee87f1bd 100644 --- a/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php @@ -210,7 +210,7 @@ public function testFormat() // max in construct, explicit format before $bar = new ProgressBar($output = $this->getOutputStream(), 10, 0); - $bar->setFormat('normal'); + $bar->setFormat(ProgressBar::FORMAT_NORMAL); $bar->start(); $bar->advance(10); $bar->finish(); @@ -220,7 +220,7 @@ public function testFormat() // max in start, explicit format before $bar = new ProgressBar($output = $this->getOutputStream(), 0, 0); - $bar->setFormat('normal'); + $bar->setFormat(ProgressBar::FORMAT_NORMAL); $bar->start(10); $bar->advance(10); $bar->finish(); @@ -828,7 +828,7 @@ public function testAnsiColorsAndEmojis() public function testSetFormat() { $bar = new ProgressBar($output = $this->getOutputStream(), 0, 0); - $bar->setFormat('normal'); + $bar->setFormat(ProgressBar::FORMAT_NORMAL); $bar->start(); rewind($output->getStream()); $this->assertEquals( @@ -837,7 +837,7 @@ public function testSetFormat() ); $bar = new ProgressBar($output = $this->getOutputStream(), 10, 0); - $bar->setFormat('normal'); + $bar->setFormat(ProgressBar::FORMAT_NORMAL); $bar->start(); rewind($output->getStream()); $this->assertEquals( pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy