8000 [Console] fix CS for code related to Table vertical rendering · symfony/symfony@8e2066e · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e2066e

Browse files
[Console] fix CS for code related to Table vertical rendering
1 parent a39ddaa commit 8e2066e

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,30 +334,31 @@ public function render()
334334
}
335335
}
336336
} elseif ($vertical) {
337-
$maxHeaderLength = array_reduce($this->headers[0] ?? [], static fn (int $max, string $header) => max($max, mb_strlen($header)), 0);
337+
$formatter = $this->output->getFormatter();
338+
$maxHeaderLength = array_reduce($this->headers[0] ?? [], static fn ($max, $header) => max($max, Helper::width(Helper::removeDecoration($formatter, $header))), 0);
338339

339340
foreach ($this->rows as $row) {
340341
if ($row instanceof TableSeparator) {
341342
continue;
342343
}
343344

344-
if (0 < \count($rows)) {
345+
if ($rows) {
345346
$rows[] = [$divider];
346347
}
347348

348-
$containsColspan = 0 < \count(array_filter($row, $isCellWithColspan));
349+
$containsColspan = \count(array_filter($row, $isCellWithColspan));
349350

350351
$headers = $this->headers[0] ?? [];
351352
$maxRows = max(\count($headers), \count($row));
352353
for ($i = 0; $i < $maxRows; ++$i) {
353354
$cell = (string) ($row[$i] ?? '');
354-
if ([] !== $headers && !$containsColspan) {
355+
if ($headers && !$containsColspan) {
355356
$rows[] = [sprintf(
356357
'<comment>%s</>: %s',
357358
str_pad($headers[$i] ?? '', $maxHeaderLength, ' ', \STR_PAD_LEFT),
358359
$cell
359360
)];
360-
} elseif (!empty($cell)) {
361+
} elseif ('' !== $cell) {
361362
$rows[] = [$cell];
362363
}
363364
}
@@ -443,7 +444,7 @@ public function render()
443444
*/
444445
private function renderRowSeparator(int $type = self::SEPARATOR_MID, string $title = null, string $titleFormat = null)
445446
{
446-
if (0 === $count = $this->numberOfColumns) {
447+
if (!$count = $this->numberOfColumns) {
447448
return;
448449
}
449450

@@ -652,7 +653,7 @@ private function calculateRowCount(): int
652653
++$numberOfRows; // Add row for header separator
653654
}
654655

655-
if (\count($this->rows) > 0) {
656+
if ($this->rows) {
656657
++$numberOfRows; // Add row for footer separator
657658
}
658659

src/Symfony/Component/Console/Tests/Helper/TableTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,10 +1938,10 @@ public function testVerticalRender(string $expectedOutput, array $headers, array
19381938
->setVertical()
19391939
->setStyle($style);
19401940

1941-
if (!empty($headerTitle)) {
1941+
if ('' !== $headerTitle) {
19421942
$table->setHeaderTitle($headerTitle);
19431943
}
1944-
if (!empty($footerTitle)) {
1944+
if ('' !== $footerTitle) {
19451945
$table->setFooterTitle($footerTitle);
19461946
}
19471947

0 commit comments

Comments
 (0)
0