diff --git a/patches/OutputFormatter.patch b/patches/OutputFormatter.patch index e0cfc00b48..e956d7210c 100644 --- a/patches/OutputFormatter.patch +++ b/patches/OutputFormatter.patch @@ -31,23 +31,37 @@ return strtr($output, ["\0" => '\\', '\\<' => '<', '\\>' => '>']); } -@@ -253,8 +256,8 @@ class OutputFormatter implements WrappableOutputFormatterInterface +@@ -253,8 +256,20 @@ class OutputFormatter implements WrappableOutputFormatterInterface } if ($currentLineLength) { - $prefix = substr($text, 0, $i = $width - $currentLineLength)."\n"; - $text = substr($text, $i); -+ $prefix = Helper::substr($text, 0, $i = $width - $currentLineLength)."\n"; -+ $text = Helper::substr($text, $i); ++ $lines = explode("\n", $text, 2); ++ $prefix = Helper::substr($lines[0], 0, $i = $width - $currentLineLength)."\n"; ++ $text = Helper::substr($lines[0], $i); ++ ++ if (isset($lines[1])) { ++ // $prefix may contain the full first line in which the \n is already a part of $prefix. ++ if ('' !== $text) { ++ $text .= "\n"; ++ } ++ ++ $text .= $lines[1]; ++ } ++ ++ unset($lines); } else { $prefix = ''; } -@@ -270,7 +273,7 @@ class OutputFormatter implements WrappableOutputFormatterInterface +@@ -269,8 +284,8 @@ class OutputFormatter implements WrappableOutputFormatterInterface + $lines = explode("\n", $text); - foreach ($lines as $line) { +- foreach ($lines as $line) { - $currentLineLength += \strlen($line); -+ $currentLineLength += Helper::length($line); ++ foreach ($lines as $i => $line) { ++ $currentLineLength = 0 === $i ? $currentLineLength + Helper::length($line) : Helper::length($line); if ($width <= $currentLineLength) { $currentLineLength = 0; } diff --git a/tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php b/tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php index 40ee11eb6e..eec2a3c7c2 100644 --- a/tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php +++ b/tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php @@ -350,6 +350,51 @@ public function testBug13292(): void self::expectNotToPerformAssertions(); } + public function testBug13317(): void + { + putenv('COLUMNS=170'); + $formatter = $this->createErrorFormatter(null); + $formatter->formatErrors( + new AnalysisResult( + [ + new Error( + 'Property bla::$error_params (non-empty-list|null) is never assigned non-empty-list so it can be removed from the property type.', + 'bla.php', + 6, + identifier: 'property.unusedType', + ), + ], + [], + [], + [], + [], + false, + null, + true, + 0, + false, + [], + ), + $this->getOutput(), + ); + $this->assertSame( + <<<'TABLE' + ------ ------------------------------------------------------------------------------------------------------------------------------------------------- + Line bla.php + ------ ------------------------------------------------------------------------------------------------------------------------------------------------- + 6 Property bla::$error_params (non-empty-list|null) is never assigned non-empty-list so it can be removed from the property type. + 🪪 property.unusedType + ------ ------------------------------------------------------------------------------------------------------------------------------------------------- + + + [ERROR] Found 1 error + + +TABLE, + $this->getOutputContent(), + ); + } + private function createErrorFormatter(?string $editorUrl, ?string $editorUrlTitle = null): TableErrorFormatter { $relativePathHelper = new FuzzyRelativePathHelper(new NullRelativePathHelper(), self::DIRECTORY_PATH, [], '/');