From 898e43d6ebd78acbef94a5dc3442b1f944cfb319 Mon Sep 17 00:00:00 2001 From: Vladimir Kuprienko Date: Tue, 28 Nov 2017 22:40:21 +0200 Subject: [PATCH] Improves readability of `yii\console\widgets\Table` widget (#15236) * Fixes code style * Moves magic numbers to constants --- framework/console/widgets/Table.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/framework/console/widgets/Table.php b/framework/console/widgets/Table.php index 12cfc1e..1e17358 100644 --- a/framework/console/widgets/Table.php +++ b/framework/console/widgets/Table.php @@ -48,6 +48,9 @@ use yii\helpers\Console; */ class Table extends Widget { + const DEFAULT_CONSOLE_SCREEN_WIDTH = 120; + const CONSOLE_SCROLLBAR_OFFSET = 3; + const CHAR_TOP = 'top'; const CHAR_TOP_MID = 'top-mid'; const CHAR_TOP_LEFT = 'top-left'; @@ -298,7 +301,7 @@ class Table extends Widget { $this->_columnWidths = $columns = []; $totalWidth = 0; - $screenWidth = $this->getScreenWidth() - 3; + $screenWidth = $this->getScreenWidth() - self::CONSOLE_SCROLLBAR_OFFSET; for ($i = 0, $count = count($this->_headers); $i < $count; $i++) { $columns[] = ArrayHelper::getColumn($this->_rows, $i); @@ -374,14 +377,10 @@ class Table extends Widget { if (!$this->_screenWidth) { $size = Console::getScreenSize(); - if (isset($size[0])) { - $this->_screenWidth = $size[0]; - } - else { - $this->_screenWidth = 123; - } + $this->_screenWidth = isset($size[0]) + ? $size[0] + : self::DEFAULT_CONSOLE_SCREEN_WIDTH + self::CONSOLE_SCROLLBAR_OFFSET; } - return $this->_screenWidth; } }