8000 Using an enum instead of 2 separated booleans · symfony/symfony@a37528e · GitHub
[go: up one dir, main page]

Skip to content

Commit a37528e

Browse files
committed
Using an enum instead of 2 separated booleans
1 parent 045bb41 commit a37528e

File tree

1 file changed

+22
-10
lines changed
  • src/Symfony/Component/Console/Helper

1 file changed

+22
-10
lines changed

src/Symfony/Component/Console/Helper/Table.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class Table
3535
private const SEPARATOR_BOTTOM = 3;
3636
private const BORDER_OUTSIDE = 0;
3737
private const BORDER_INSIDE = 1;
38+
private const DISPLAY_ORIENTATION_DEFAULT = 'default';
39+
private const DISPLAY_ORIENTATION_HORIZONTAL = 'horizontal';
40+
private const DISPLAY_ORIENTATION_VERTICAL = 'vertical';
3841

3942
private $headerTitle;
4043
private $footerTitle;
@@ -48,8 +51,14 @@ class Table
4851
* Table rows.
4952
*/
5053
private $rows = [];
51-
private $horizontal = false;
52-
private $vertical = false;
54+
55+
/**
56+
* Defines the way the table will be displayed.
57+
* It can be either 'default', 'horizontal' or 'vertical'.
58+
*
59+
* @var string
60+
*/
61+
private $displayOrientation = self::DISPLAY_ORIENTATION_DEFAULT;
5362

5463
/**
5564
* Column widths cache.
@@ -314,14 +323,14 @@ public function setFooterTitle(?string $title): self
314323

315324
public function setHorizontal(bool $horizontal = true): self
316325
{
317-
$this->horizontal = $horizontal;
326+
$this->displayOrientation = $horizontal ? self::DISPLAY_ORIENTATION_HORIZONTAL : self::DISPLAY_ORIENTATION_DEFAULT;
318327

319328
return $this;
320329
}
321330

322331
public function setVertical(bool $vertical = true): self
323332
{
324-
$this->vertical = $vertical;
333+
$this->displayOrientation = $vertical ? self::DISPLAY_ORIENTATION_VERTICAL : self::DISPLAY_ORIENTATION_DEFAULT;
325334

326335
return $this;
327336
}
@@ -346,8 +355,11 @@ public function render()
346355
return $cell instanceof TableCell && $cell->getColspan() >= 2;
347356
};
348357

358+
$horizontal = self::DISPLAY_ORIENTATION_HORIZONTAL === $this->displayOrientation;
359+
$vertical = self::DISPLAY_ORIENTATION_VERTICAL === $this->displayOrientation;
360+
349361
$rows = [];
350-
if ($this->horizontal) {
362+
if ($horizontal) {
351363
foreach ($this->headers[0] ?? [] as $i => $header) {
352364
$rows[$i] = [$header];
353365
foreach ($this->rows as $row) {
@@ -363,7 +375,7 @@ public function render()
363375
}
364376
}
365377
}
366-
} elseif ($this->vertical) {
378+
} elseif ($vertical) {
367379
$maxHeaderLength = max(array_map(static function (string $header) {
368380
return mb_strlen($header);
369381
}, $this->headers[0] ?? ['']));
@@ -405,8 +417,8 @@ public function render()
405417
$rows = $this->buildTableRows($rows);
406418
$this->calculateColumnsWidth($rows);
407419

408-
$isHeader = !$this->horizontal;
409-
$isFirstRow = $this->horizontal;
420+
$isHeader = !$horizontal;
421+
$isFirstRow = $horizontal;
410422
foreach ($rows as $row) {
411423
if ($divider === $row) {
412424
$isHeader = false;
@@ -431,12 +443,12 @@ public function render()
431443
$this->renderRowSeparator(self::SEPARATOR_TOP, $this->headerTitle, $this->style->getHeaderTitleFormat());
432444
}
433445
}
434-
if ($this->vertical) {
446+
if ($vertical) {
435447
$isHeader = false;
436448
$isFirstRow = false;
437449
}
438450

439-
if ($this->horizontal) {
451+
if ($horizontal) {
440452
$this->renderRow($row, $this->style->getCellRowFormat(), $this->style->getCellHeaderFormat());
441453
} else {
442454
$this->renderRow($row, $isHeader ? $this->style->getCellHeaderFormat() : $this->style->getCellRowFormat());

0 commit comments

Comments
 (0)
0