Skip to content

Commit

Permalink
Fix Incorrectly nested style tag found for narrow terminals
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Mar 3, 2022
1 parent b655e85 commit d921d06
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Command/ErrorsConsoleStyle.php
Expand Up @@ -4,12 +4,15 @@

use OndraM\CiDetector\CiDetector;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Helper\TableSeparator;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Terminal;
use function array_unshift;
use function explode;
use function implode;
use function sprintf;
use function str_starts_with;
use function strlen;
use function wordwrap;
Expand Down Expand Up @@ -65,12 +68,22 @@ public function table(array $headers, array $rows): void
// https://github.com/symfony/symfony/issues/45520
// https://github.com/symfony/symfony/issues/45521
$headers = $this->wrap($headers, $terminalWidth, $maxHeaderWidth);
foreach ($headers as $i => $header) {
$newHeader = [];
foreach (explode("\n", $header) as $h) {
$newHeader[] = sprintf('<info>%s</info>', $h);
}

$headers[$i] = implode("\n", $newHeader);
}

foreach ($rows as $i => $row) {
$rows[$i] = $this->wrap($row, $terminalWidth, $maxHeaderWidth);
}

$table = $this->createTable();
$table->setHeaders($headers);
array_unshift($rows, new TableSeparator());
array_unshift($rows, $headers);
$table->setRows($rows);

$table->render();
Expand Down
31 changes: 31 additions & 0 deletions tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php
Expand Up @@ -7,12 +7,18 @@
use PHPStan\File\FuzzyRelativePathHelper;
use PHPStan\File\NullRelativePathHelper;
use PHPStan\Testing\ErrorFormatterTestCase;
use function putenv;
use function sprintf;
use const PHP_VERSION_ID;

class TableErrorFormatterTest extends ErrorFormatterTestCase
{

protected function tearDown(): void
{
putenv('COLUMNS');
}

public function dataFormatterOutputProvider(): iterable
{
yield [
Expand Down Expand Up @@ -172,4 +178,29 @@ public function testEditorUrlWithTrait(): void
$this->assertStringContainsString('Bar.php', $this->getOutputContent());
}

public function testBug6727(): void
{
putenv('COLUMNS=30');
$formatter = new TableErrorFormatter(new FuzzyRelativePathHelper(new NullRelativePathHelper(), self::DIRECTORY_PATH, [], '/'), false, null);
$formatter->formatErrors(
new AnalysisResult(
[
new Error(
'Method MissingTypehintPromotedProperties\Foo::__construct() has parameter $foo with no value type specified in iterable type array.',
'/var/www/html/app/src/Foo.php (in context of class App\Foo\Bar)',
5,
),
],
[],
[],
[],
false,
null,
true,
),
$this->getOutput(),
);
self::expectNotToPerformAssertions();
}

}

0 comments on commit d921d06

Please sign in to comment.