phpstan-src
phpstan-src copied to clipboard
remove manual wrapping for error table
The two issues mentioned in the comments were fixed years ago. Now it seems that Symfony's wrapping is superior to the PHPStan's.
Motivation:
- PHPStan's wrapping uses wordwrap, which doesn't work if there are no whitespaces (typically errors involving long unions).
- I wanted to try creating a custom version of
TableErrorFormatterwhich would put the editor links on the line numbers, instead of showing them separately (I find that distracting). But with the currentErrorConsoleStyleit causes the table to become very narrow, because the hyperlink is included in the computed width of the Line column.
Results:
| Before | After |
|---|---|
Here are the test files I used to generate the screenshots:
<?php
namespace Foo;
class Bar
{
public const CONST_1 = 'aaaa';
public const CONST_2 = 'bbbb';
public const CONST_3 = 'cccc';
public const CONST_4 = 'dddd';
public const CONST_5 = 'eeee';
public const CONST_6 = 'ffff';
public const CONST_7 = 'gggg';
public const CONST_8 = 'hhhh';
public const CONST_9 = 'iiii';
public const CONST_10 = 'jjjj';
public const CONST_11 = 'kkkk';
public const CONST_12 = 'llll';
public const CONST_13 = 'mmmm';
public const CONST_14 = 'nnnn';
public const CONST_15 = 'oooo';
public const CONST_16 = 'pppp';
public const CONST_17 = 'qqqq';
public const CONST_18 = 'rrrr';
public const CONST_19 = 'ssss';
public const CONST_20 = 'tttt';
}
/** @phpstan-param Bar::CONST_* $i */
function printNum(string $i): void
{
echo $i;
}
printNum((string) random_int(0, 100));
<?php declare(strict_types = 1);
use PHPStan\Command\ErrorsConsoleStyle;
use PHPStan\Command\Symfony\SymfonyOutput;
use PHPStan\Command\Symfony\SymfonyStyle;
require_once __DIR__ . '/vendor/autoload.php';
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
$input = new \Symfony\Component\Console\Input\ArgvInput();
$stdOutput = new SymfonyOutput($output, new SymfonyStyle(new ErrorsConsoleStyle($input, $output)));
$stdOutput->getStyle()->table(
['Line', 'path/foo/bar/baz/adlkjhasdkjhkajhsdkjad/adkljalskdjalkd/asdlkjaldjk/adasdasd/alkjdlkajsdlkjalkdjalkjdslkja/asdasdadasdasd/qeqwqeqasdasdada/Foo.php (in context of class aksdjlajdljasdlkjaldkjaldajdlkaj\alksjdalksdjlasdlajk\asldjkaskldj)'],
[
[
'<href="editor://open?file=foo/bar/baz.php&line=12">12</>',
"Long error message asdalksdj lkajsdl aksjd lakjsdl jasld kjalksd jlaskjd lakjd lkasjd lkajsd lkajsd lkaj dlkajsd klaj dlkaj d"
. "\n✏️ <href=\"editor://open?=file=path/foo/bar/baz/adlkjhasdkjhkajhsdkjad/adkljalskdjalkd/asdlkjaldjk/adasdasd/alkjdlkajsdlkjalkdjalkjdslkja/asdasdadasdasd/qeqwqeqasdasdada/Foo.php&line=12\">"
. "path/foo/bar/baz/adlkjhasdkjhkajhsdkjad/adkljalskdjalkd/asdlkjaldjk/adasdasd/alkjdlkajsdlkjalkdjalkjdslkja/asdasdadasdasd/qeqwqeqasdasdada/Foo.php</>",
],
[
'<href="editor://open?file=foo/bar/baz.php&line=12">12</>',
"Same link, but shorter title."
. "\n✏️ <href=\"editor://open?=file=path/foo/bar/baz/adlkjhasdkjhkajhsdkjad/adkljalskdjalkd/asdlkjaldjk/adasdasd/alkjdlkajsdlkjalkdjalkjdslkja/asdasdadasdasd/qeqwqeqasdasdada/Foo.php&line=12\">"
. "short title</>",
],
],
);
$stdOutput->writeLineFormatted('');
$stdOutput->writeLineFormatted('Table without Line links');
$stdOutput->writeLineFormatted('');
$stdOutput->getStyle()->table(
['Line', 'path/foo/bar/baz/adlkjhasdkjhkajhsdkjad/adkljalskdjalkd/asdlkjaldjk/adasdasd/alkjdlkajsdlkjalkdjalkjdslkja/asdasdadasdasd/qeqwqeqasdasdada/Foo.php (in context of class aksdjlajdljasdlkjaldkjaldajdlkaj\alksjdalksdjlasdlajk\asldjkaskldj)'],
[
[
'12',
"Long error message asdalksdj lkajsdl aksjd lakjsdl jasld kjalksd jlaskjd lakjd lkasjd lkajsd lkajsd lkaj dlkajsd klaj dlkaj d"
. "\n✏️ <href=\"editor://open?=file=path/foo/bar/baz/adlkjhasdkjhkajhsdkjad/adkljalskdjalkd/asdlkjaldjk/adasdasd/alkjdlkajsdlkjalkdjalkjdslkja/asdasdadasdasd/qeqwqeqasdasdada/Foo.php&line=12\">"
. "path/foo/bar/baz/adlkjhasdkjhkajhsdkjad/adkljalskdjalkd/asdlkjaldjk/adasdasd/alkjdlkajsdlkjalkdjalkjdslkja/asdasdadasdasd/qeqwqeqasdasdada/Foo.php</>",
],
[
'123456789',
"Same link, but shorter title."
. "\n✏️ <href=\"editor://open?=file=path/foo/bar/baz/adlkjhasdkjhkajhsdkjad/adkljalskdjalkd/asdlkjaldjk/adasdasd/alkjdlkajsdlkjalkdjalkjdslkja/asdasdadasdasd/qeqwqeqasdasdada/Foo.php&line=12\">"
. "short title</>",
],
],
);