@@ -311,7 +311,7 @@ public function setVertical(bool $vertical = true): static
311311 public function render()
312312 {
313313 $divider = new TableSeparator();
314- $isCellWithColspan = static fn ($cell): bool => $cell instanceof TableCell && $cell->getColspan() >= 2;
314+ $isCellWithColspan = static fn ($cell) => $cell instanceof TableCell && $cell->getColspan() >= 2;
315315
316316 $horizontal = self::DISPLAY_ORIENTATION_HORIZONTAL === $this->displayOrientation;
317317 $vertical = self::DISPLAY_ORIENTATION_VERTICAL === $this->displayOrientation;
@@ -334,30 +334,36 @@ 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 = false;
350+ foreach ($row as $cell) {
351+ if ($containsColspan = $isCellWithColspan($cell)) {
352+ break;
353+ }
354+ }
349355
350356 $headers = $this->headers[0] ?? [];
351357 $maxRows = max(\count($headers), \count($row));
352358 for ($i = 0; $i < $maxRows; ++$i) {
353359 $cell = (string) ($row[$i] ?? '');
354- if ([] !== $headers && !$containsColspan) {
360+ if ($headers && !$containsColspan) {
355361 $rows[] = [sprintf(
356362 '<comment>%s</>: %s',
357363 str_pad($headers[$i] ?? '', $maxHeaderLength, ' ', \STR_PAD_LEFT),
358364 $cell
359365 )];
360- } elseif (!empty( $cell) ) {
366+ } elseif ('' !== $cell) {
361367 $rows[] = [$cell];
362368 }
363369 }
@@ -443,7 +449,7 @@ public function render()
443449 */
444450 private function renderRowSeparator(int $type = self::SEPARATOR_MID, string $title = null, string $titleFormat = null)
445451 {
446- if (0 === $count = $this->numberOfColumns) {
452+ if (! $count = $this->numberOfColumns) {
447453 return;
448454 }
449455
@@ -652,7 +658,7 @@ private function calculateRowCount(): int
652658 ++$numberOfRows; // Add row for header separator
653659 }
654660
655- if (\count( $this->rows) > 0 ) {
661+ if ($this->rows) {
656662 ++$numberOfRows; // Add row for footer separator
657663 }
658664
0 commit comments