Skip to content

Commit dfef3d4

Browse files
committed
remove manual wrapping for error table
1 parent fabf273 commit dfef3d4

File tree

1 file changed

+5
-52
lines changed

1 file changed

+5
-52
lines changed

src/Command/ErrorsConsoleStyle.php

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PHPStan\Command;
44

55
use OndraM\CiDetector\CiDetector;
6+
use Symfony\Component\Console\Helper\Helper;
67
use Symfony\Component\Console\Helper\ProgressBar;
78
use Symfony\Component\Console\Helper\TableSeparator;
89
use Symfony\Component\Console\Input\InputInterface;
@@ -13,9 +14,7 @@
1314
use function explode;
1415
use function implode;
1516
use function sprintf;
16-
use function str_starts_with;
1717
use function strlen;
18-
use function wordwrap;
1918
use const DIRECTORY_SEPARATOR;
2019

2120
final class ErrorsConsoleStyle extends SymfonyStyle
@@ -55,19 +54,15 @@ public function table(array $headers, array $rows): void
5554
$terminalWidth = (new Terminal())->getWidth() - 2;
5655
$maxHeaderWidth = strlen($headers[0]);
5756
foreach ($rows as $row) {
58-
$length = strlen($row[0]);
57+
$length = Helper::width(Helper::removeDecoration($this->getFormatter(), $row[0]));
58+
5959
if ($maxHeaderWidth !== 0 && $length <= $maxHeaderWidth) {
6060
continue;
6161
}
6262

6363
$maxHeaderWidth = $length;
6464
}
6565

66-
// manual wrapping could be replaced with $table->setColumnMaxWidth()
67-
// but it's buggy for <href> lines
68-
// https://github.com/symfony/symfony/issues/45520
69-
// https://github.com/symfony/symfony/issues/45521
70-
$headers = $this->wrap($headers, $terminalWidth, $maxHeaderWidth);
7166
foreach ($headers as $i => $header) {
7267
$newHeader = [];
7368
foreach (explode("\n", $header) as $h) {
@@ -77,58 +72,16 @@ public function table(array $headers, array $rows): void
7772
$headers[$i] = implode("\n", $newHeader);
7873
}
7974

80-
foreach ($rows as $i => $row) {
81-
$rows[$i] = $this->wrap($row, $terminalWidth, $maxHeaderWidth);
82-
}
83-
8475
$table = $this->createTable();
76+
// -5 because there are 5 padding spaces: One on each side of the table, one on each side of a cell and one between columns.
77+
$table->setColumnMaxWidth(1, $terminalWidth - $maxHeaderWidth - 5);
8578
array_unshift($rows, $headers, new TableSeparator());
8679
$table->setRows($rows);
8780

8881
$table->render();
8982
$this->newLine();
9083
}
9184

92-
/**
93-
* @param string[] $rows
94-
* @return string[]
95-
*/
96-
private function wrap(array $rows, int $terminalWidth, int $maxHeaderWidth): array
97-
{
98-
foreach ($rows as $i => $column) {
99-
$columnRows = explode("\n", $column);
100-
foreach ($columnRows as $k => $columnRow) {
101-
if (str_starts_with($columnRow, '✏️')) {
102-
continue;
103-
}
104-
$wrapped = wordwrap(
105-
$columnRow,
106-
$terminalWidth - $maxHeaderWidth - 5,
107-
);
108-
if (str_starts_with($columnRow, '💡 ')) {
109-
$wrappedLines = explode("\n", $wrapped);
110-
$newWrappedLines = [];
111-
foreach ($wrappedLines as $l => $line) {
112-
if ($l === 0) {
113-
$newWrappedLines[] = $line;
114-
continue;
115-
}
116-
117-
$newWrappedLines[] = ' ' . $line;
118-
}
119-
$columnRows[$k] = implode("\n", $newWrappedLines);
120-
} else {
121-
$columnRows[$k] = $wrapped;
122-
}
123-
124-
}
125-
126-
$rows[$i] = implode("\n", $columnRows);
127-
}
128-
129-
return $rows;
130-
}
131-
13285
public function createProgressBar(int $max = 0): ProgressBar
13386
{
13487
$this->progressBar = parent::createProgressBar($max);

0 commit comments

Comments
 (0)