Browse Source

Improves readability of `yii\console\widgets\Table` widget (#15236)

* Fixes code style

* Moves magic numbers to constants
tags/2.0.14
Vladimir Kuprienko 7 years ago committed by Alexander Makarov
parent
commit
898e43d6eb
  1. 15
      framework/console/widgets/Table.php

15
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;
}
}

Loading…
Cancel
Save