Skip to content

Commit d921d06

Browse files
committed
Fix Incorrectly nested style tag found for narrow terminals
1 parent b655e85 commit d921d06

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/Command/ErrorsConsoleStyle.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44

55
use OndraM\CiDetector\CiDetector;
66
use Symfony\Component\Console\Helper\ProgressBar;
7+
use Symfony\Component\Console\Helper\TableSeparator;
78
use Symfony\Component\Console\Input\InputInterface;
89
use Symfony\Component\Console\Output\OutputInterface;
910
use Symfony\Component\Console\Style\SymfonyStyle;
1011
use Symfony\Component\Console\Terminal;
12+
use function array_unshift;
1113
use function explode;
1214
use function implode;
15+
use function sprintf;
1316
use function str_starts_with;
1417
use function strlen;
1518
use function wordwrap;
@@ -65,12 +68,22 @@ public function table(array $headers, array $rows): void
6568
// https://github.com/symfony/symfony/issues/45520
6669
// https://github.com/symfony/symfony/issues/45521
6770
$headers = $this->wrap($headers, $terminalWidth, $maxHeaderWidth);
71+
foreach ($headers as $i => $header) {
72+
$newHeader = [];
73+
foreach (explode("\n", $header) as $h) {
74+
$newHeader[] = sprintf('<info>%s</info>', $h);
75+
}
76+
77+
$headers[$i] = implode("\n", $newHeader);
78+
}
79+
6880
foreach ($rows as $i => $row) {
6981
$rows[$i] = $this->wrap($row, $terminalWidth, $maxHeaderWidth);
7082
}
7183

7284
$table = $this->createTable();
73-
$table->setHeaders($headers);
85+
array_unshift($rows, new TableSeparator());
86+
array_unshift($rows, $headers);
7487
$table->setRows($rows);
7588

7689
$table->render();

tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@
77
use PHPStan\File\FuzzyRelativePathHelper;
88
use PHPStan\File\NullRelativePathHelper;
99
use PHPStan\Testing\ErrorFormatterTestCase;
10+
use function putenv;
1011
use function sprintf;
1112
use const PHP_VERSION_ID;
1213

1314
class TableErrorFormatterTest extends ErrorFormatterTestCase
1415
{
1516

17+
protected function tearDown(): void
18+
{
19+
putenv('COLUMNS');
20+
}
21+
1622
public function dataFormatterOutputProvider(): iterable
1723
{
1824
yield [
@@ -172,4 +178,29 @@ public function testEditorUrlWithTrait(): void
172178
$this->assertStringContainsString('Bar.php', $this->getOutputContent());
173179
}
174180

181+
public function testBug6727(): void
182+
{
183+
putenv('COLUMNS=30');
184+
$formatter = new TableErrorFormatter(new FuzzyRelativePathHelper(new NullRelativePathHelper(), self::DIRECTORY_PATH, [], '/'), false, null);
185+
$formatter->formatErrors(
186+
new AnalysisResult(
187+
[
188+
new Error(
189+
'Method MissingTypehintPromotedProperties\Foo::__construct() has parameter $foo with no value type specified in iterable type array.',
190+
'/var/www/html/app/src/Foo.php (in context of class App\Foo\Bar)',
191+
5,
192+
),
193+
],
194+
[],
195+
[],
196+
[],
197+
false,
198+
null,
199+
true,
200+
),
201+
$this->getOutput(),
202+
);
203+
self::expectNotToPerformAssertions();
204+
}
205+
175206
}

0 commit comments

Comments
 (0)