From e6142e40b4e47258a675b0d1e1898bc8b1cd916e Mon Sep 17 00:00:00 2001 From: Sander Muller Date: Mon, 6 Jan 2025 17:15:41 +0100 Subject: [PATCH 1/6] Render error identifier when ran verbose --- src/ErrorFormatter/SymplifyErrorFormatter.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ErrorFormatter/SymplifyErrorFormatter.php b/src/ErrorFormatter/SymplifyErrorFormatter.php index 6aea5513..26488ed7 100644 --- a/src/ErrorFormatter/SymplifyErrorFormatter.php +++ b/src/ErrorFormatter/SymplifyErrorFormatter.php @@ -136,6 +136,10 @@ private function printSingleError(Error $error, OutputStyle $outputStyle): void $itemMessage = sprintf(" - '%s'", $regexMessage); $this->writeln($itemMessage); + if ($this->output?->isVerbose() && $error->getIdentifier() !== null && $error->canBeIgnored()) { + $this->writeln(' 🪪 ' . $error->getIdentifier()); + } + $this->separator(); $outputStyle->newLine(); } From 00df8f270abf2a5269e9dd95e1f25c583910ea6d Mon Sep 17 00:00:00 2001 From: Sander Muller Date: Mon, 6 Jan 2025 17:50:49 +0100 Subject: [PATCH 2/6] Add test --- ...ngle_message_many_files_report_verbose.txt | 10 +++ .../SymplifyErrorFormatterVerboseTest.php | 61 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 tests/ErrorFormatter/Fixture/expected_single_message_many_files_report_verbose.txt create mode 100644 tests/ErrorFormatter/SymplifyErrorFormatterVerboseTest.php diff --git a/tests/ErrorFormatter/Fixture/expected_single_message_many_files_report_verbose.txt b/tests/ErrorFormatter/Fixture/expected_single_message_many_files_report_verbose.txt new file mode 100644 index 00000000..34096c74 --- /dev/null +++ b/tests/ErrorFormatter/Fixture/expected_single_message_many_files_report_verbose.txt @@ -0,0 +1,10 @@ + ---------------------------%s + /data/folder/with space/and unicode 😃/project/folder with unicode 😃/file name with "spaces" and unicode 😃.php:4 + ---------------------------%s + - '#Foo#' + 🪪 identical.alwaysFalse + ---------------------------%s + + + [ERROR] Found 1 errors + diff --git a/tests/ErrorFormatter/SymplifyErrorFormatterVerboseTest.php b/tests/ErrorFormatter/SymplifyErrorFormatterVerboseTest.php new file mode 100644 index 00000000..2ed514d4 --- /dev/null +++ b/tests/ErrorFormatter/SymplifyErrorFormatterVerboseTest.php @@ -0,0 +1,61 @@ +getByType(SymplifyErrorFormatter::class); + + $analysisResult = $this->getAnalysisResult($numFileErrors, $numGenericErrors); + $output = $this->getOutput(verbose: true); + $resultCode = $symplifyErrorFormatter->formatErrors($analysisResult, $output); + + $this->assertSame($expectedExitCode, $resultCode); + + $this->assertStringMatchesFormatFile($expectedOutputFile, $this->getOutputContent(verbose: true)); + } + + /** + * @return Iterator + */ + public static function provideData(): Iterator + { + yield ['Some message', 1, 1, 1, __DIR__ . '/Fixture/expected_single_message_many_files_report_verbose.txt']; + } + + /** + * @return string[] + */ + public static function getAdditionalConfigFiles(): array + { + return [__DIR__ . '/../../config/config.neon']; + } + + protected function getAnalysisResult($numFileErrors, int $numGenericErrors): AnalysisResult + { + $fileErrors = [new Error('Foo', self::DIRECTORY_PATH . '/folder with unicode 😃/file name with "spaces" and unicode 😃.php', 4, identifier: 'identical.alwaysFalse')]; + + return new AnalysisResult($fileErrors, [], [], [], [], \false, null, \true, 0, \false, []); + } +} From 49494f2b9f8227b92d594e66b74fd085e0457fcd Mon Sep 17 00:00:00 2001 From: Sander Muller Date: Mon, 6 Jan 2025 20:41:02 +0100 Subject: [PATCH 3/6] fix phpstan --- .gitignore | 1 + tests/ErrorFormatter/SymplifyErrorFormatterVerboseTest.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index ccdb9d71..3300e50a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /vendor composer.lock +.idea # phpunit 10+ /.phpunit.cache diff --git a/tests/ErrorFormatter/SymplifyErrorFormatterVerboseTest.php b/tests/ErrorFormatter/SymplifyErrorFormatterVerboseTest.php index 2ed514d4..7023bd30 100644 --- a/tests/ErrorFormatter/SymplifyErrorFormatterVerboseTest.php +++ b/tests/ErrorFormatter/SymplifyErrorFormatterVerboseTest.php @@ -54,8 +54,10 @@ public static function getAdditionalConfigFiles(): array protected function getAnalysisResult($numFileErrors, int $numGenericErrors): AnalysisResult { + // @phpstan-ignore phpstanApi.constructor $fileErrors = [new Error('Foo', self::DIRECTORY_PATH . '/folder with unicode 😃/file name with "spaces" and unicode 😃.php', 4, identifier: 'identical.alwaysFalse')]; + // @phpstan-ignore phpstanApi.constructor return new AnalysisResult($fileErrors, [], [], [], [], \false, null, \true, 0, \false, []); } } From b661e010250d1317997deb87414773f97abdea32 Mon Sep 17 00:00:00 2001 From: Sander Muller Date: Mon, 6 Jan 2025 21:06:40 +0100 Subject: [PATCH 4/6] run fix-cs --- src/Console/Terminal.php | 2 +- src/TypeResolver/ClassConstFetchReturnTypeResolver.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Console/Terminal.php b/src/Console/Terminal.php index f2c956ad..cb820afb 100644 --- a/src/Console/Terminal.php +++ b/src/Console/Terminal.php @@ -127,7 +127,7 @@ private static function readFromProcess(string $command): ?string private static function getAnsiconWidth(): ?int { - if (!is_string(\getenv('ANSICON'))) { + if (! is_string(\getenv('ANSICON'))) { return null; } diff --git a/src/TypeResolver/ClassConstFetchReturnTypeResolver.php b/src/TypeResolver/ClassConstFetchReturnTypeResolver.php index 6a280af4..a17191ed 100644 --- a/src/TypeResolver/ClassConstFetchReturnTypeResolver.php +++ b/src/TypeResolver/ClassConstFetchReturnTypeResolver.php @@ -10,7 +10,6 @@ use PhpParser\Node\Identifier; use PhpParser\Node\Name; use PHPStan\Reflection\MethodReflection; -use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Type\MixedType; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; From d196b539645991794c57abd37e38336d8d0d7035 Mon Sep 17 00:00:00 2001 From: Sander Muller Date: Mon, 6 Jan 2025 21:31:50 +0100 Subject: [PATCH 5/6] use parent identifier getAnalysisResult --- ...ngle_message_many_files_report_verbose.txt | 43 ++++++++++++++++--- .../SymplifyErrorFormatterVerboseTest.php | 22 +++------- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/tests/ErrorFormatter/Fixture/expected_single_message_many_files_report_verbose.txt b/tests/ErrorFormatter/Fixture/expected_single_message_many_files_report_verbose.txt index 34096c74..114e2239 100644 --- a/tests/ErrorFormatter/Fixture/expected_single_message_many_files_report_verbose.txt +++ b/tests/ErrorFormatter/Fixture/expected_single_message_many_files_report_verbose.txt @@ -1,10 +1,43 @@ - ---------------------------%s + ---------------------------------------------------------------------------------------------------------------- + /data/folder/with space/and unicode 😃/project/folder with unicode 😃/file name with "spaces" and unicode 😃.php:2 + ---------------------------------------------------------------------------------------------------------------- + - '#Bar +Bar2#' + ---------------------------------------------------------------------------------------------------------------- + + ---------------------------------------------------------------------------------------------------------------- /data/folder/with space/and unicode 😃/project/folder with unicode 😃/file name with "spaces" and unicode 😃.php:4 - ---------------------------%s + ---------------------------------------------------------------------------------------------------------------- - '#Foo#' - 🪪 identical.alwaysFalse - ---------------------------%s + ---------------------------------------------------------------------------------------------------------------- + + ---------------------------------------------------------------------------------------------------------------- + /data/folder/with space/and unicode 😃/project/foo.php: + ---------------------------------------------------------------------------------------------------------------- + - '#Bar +Bar2#' + ---------------------------------------------------------------------------------------------------------------- + + ---------------------------------------------------------------------------------------------------------------- + /data/folder/with space/and unicode 😃/project/foo.php:1 + ---------------------------------------------------------------------------------------------------------------- + - '#Foo#' + ---------------------------------------------------------------------------------------------------------------- + + ---------------------------------------------------------------------------------------------------------------- + /data/folder/with space/and unicode 😃/project/foo.php:5 + ---------------------------------------------------------------------------------------------------------------- + - '#Bar +Bar2#' + ---------------------------------------------------------------------------------------------------------------- + + ---------------------------------------------------------------------------------------------------------------- + /data/folder/with space/and unicode 😃/project/foo.php:5 + ---------------------------------------------------------------------------------------------------------------- + - '#Foobar\\Buz#' + 🪪 foobar.buz + ---------------------------------------------------------------------------------------------------------------- - [ERROR] Found 1 errors + [ERROR] Found 6 errors diff --git a/tests/ErrorFormatter/SymplifyErrorFormatterVerboseTest.php b/tests/ErrorFormatter/SymplifyErrorFormatterVerboseTest.php index 7023bd30..96dbb32d 100644 --- a/tests/ErrorFormatter/SymplifyErrorFormatterVerboseTest.php +++ b/tests/ErrorFormatter/SymplifyErrorFormatterVerboseTest.php @@ -5,9 +5,6 @@ namespace Symplify\PHPStanExtensions\Tests\ErrorFormatter; use Iterator; -use PHPStan\Analyser\Error; -use PHPStan\Command\AnalysisResult; -use PHPStan\ShouldNotHappenException; use PHPStan\Testing\ErrorFormatterTestCase; use PHPUnit\Framework\Attributes\DataProvider; use Symplify\PHPStanExtensions\ErrorFormatter\SymplifyErrorFormatter; @@ -20,9 +17,9 @@ final class SymplifyErrorFormatterVerboseTest extends ErrorFormatterTestCase #[DataProvider('provideData')] public function testFormatErrors( string $message, - int $expectedExitCode, - int $numFileErrors, - int $numGenericErrors, + int $expectedExitCode, + int $numFileErrors, + int $numGenericErrors, string $expectedOutputFile, ): void { $symplifyErrorFormatter = self::getContainer()->getByType(SymplifyErrorFormatter::class); @@ -33,7 +30,7 @@ public function testFormatErrors( $this->assertSame($expectedExitCode, $resultCode); - $this->assertStringMatchesFormatFile($expectedOutputFile, $this->getOutputContent(verbose: true)); + $this->assertStringMatchesFormatFile($expectedOutputFile, str_replace("\r", "\r\n",$this->getOutputContent(verbose: true))); } /** @@ -41,7 +38,7 @@ public function testFormatErrors( */ public static function provideData(): Iterator { - yield ['Some message', 1, 1, 1, __DIR__ . '/Fixture/expected_single_message_many_files_report_verbose.txt']; + yield ['Some message', 1, 6, 0, __DIR__ . '/Fixture/expected_single_message_many_files_report_verbose.txt']; } /** @@ -51,13 +48,4 @@ public static function getAdditionalConfigFiles(): array { return [__DIR__ . '/../../config/config.neon']; } - - protected function getAnalysisResult($numFileErrors, int $numGenericErrors): AnalysisResult - { - // @phpstan-ignore phpstanApi.constructor - $fileErrors = [new Error('Foo', self::DIRECTORY_PATH . '/folder with unicode 😃/file name with "spaces" and unicode 😃.php', 4, identifier: 'identical.alwaysFalse')]; - - // @phpstan-ignore phpstanApi.constructor - return new AnalysisResult($fileErrors, [], [], [], [], \false, null, \true, 0, \false, []); - } } From fa13b2b9a764b2921a902b95fd83d2309ad286cb Mon Sep 17 00:00:00 2001 From: Sander Muller Date: Tue, 7 Jan 2025 09:21:29 +0100 Subject: [PATCH 6/6] Apply review feedback --- src/ErrorFormatter/SymplifyErrorFormatter.php | 2 +- ...ngle_message_many_files_report_verbose.txt | 43 ---------------- .../SymplifyErrorFormatterVerboseTest.php | 51 ------------------- 3 files changed, 1 insertion(+), 95 deletions(-) delete mode 100644 tests/ErrorFormatter/Fixture/expected_single_message_many_files_report_verbose.txt delete mode 100644 tests/ErrorFormatter/SymplifyErrorFormatterVerboseTest.php diff --git a/src/ErrorFormatter/SymplifyErrorFormatter.php b/src/ErrorFormatter/SymplifyErrorFormatter.php index 26488ed7..871c106a 100644 --- a/src/ErrorFormatter/SymplifyErrorFormatter.php +++ b/src/ErrorFormatter/SymplifyErrorFormatter.php @@ -136,7 +136,7 @@ private function printSingleError(Error $error, OutputStyle $outputStyle): void $itemMessage = sprintf(" - '%s'", $regexMessage); $this->writeln($itemMessage); - if ($this->output?->isVerbose() && $error->getIdentifier() !== null && $error->canBeIgnored()) { + if ($error->getIdentifier() !== null && $error->canBeIgnored()) { $this->writeln(' 🪪 ' . $error->getIdentifier()); } diff --git a/tests/ErrorFormatter/Fixture/expected_single_message_many_files_report_verbose.txt b/tests/ErrorFormatter/Fixture/expected_single_message_many_files_report_verbose.txt deleted file mode 100644 index 114e2239..00000000 --- a/tests/ErrorFormatter/Fixture/expected_single_message_many_files_report_verbose.txt +++ /dev/null @@ -1,43 +0,0 @@ - ---------------------------------------------------------------------------------------------------------------- - /data/folder/with space/and unicode 😃/project/folder with unicode 😃/file name with "spaces" and unicode 😃.php:2 - ---------------------------------------------------------------------------------------------------------------- - - '#Bar -Bar2#' - ---------------------------------------------------------------------------------------------------------------- - - ---------------------------------------------------------------------------------------------------------------- - /data/folder/with space/and unicode 😃/project/folder with unicode 😃/file name with "spaces" and unicode 😃.php:4 - ---------------------------------------------------------------------------------------------------------------- - - '#Foo#' - ---------------------------------------------------------------------------------------------------------------- - - ---------------------------------------------------------------------------------------------------------------- - /data/folder/with space/and unicode 😃/project/foo.php: - ---------------------------------------------------------------------------------------------------------------- - - '#Bar -Bar2#' - ---------------------------------------------------------------------------------------------------------------- - - ---------------------------------------------------------------------------------------------------------------- - /data/folder/with space/and unicode 😃/project/foo.php:1 - ---------------------------------------------------------------------------------------------------------------- - - '#Foo#' - ---------------------------------------------------------------------------------------------------------------- - - ---------------------------------------------------------------------------------------------------------------- - /data/folder/with space/and unicode 😃/project/foo.php:5 - ---------------------------------------------------------------------------------------------------------------- - - '#Bar -Bar2#' - ---------------------------------------------------------------------------------------------------------------- - - ---------------------------------------------------------------------------------------------------------------- - /data/folder/with space/and unicode 😃/project/foo.php:5 - ---------------------------------------------------------------------------------------------------------------- - - '#Foobar\\Buz#' - 🪪 foobar.buz - ---------------------------------------------------------------------------------------------------------------- - - - [ERROR] Found 6 errors - diff --git a/tests/ErrorFormatter/SymplifyErrorFormatterVerboseTest.php b/tests/ErrorFormatter/SymplifyErrorFormatterVerboseTest.php deleted file mode 100644 index 96dbb32d..00000000 --- a/tests/ErrorFormatter/SymplifyErrorFormatterVerboseTest.php +++ /dev/null @@ -1,51 +0,0 @@ -getByType(SymplifyErrorFormatter::class); - - $analysisResult = $this->getAnalysisResult($numFileErrors, $numGenericErrors); - $output = $this->getOutput(verbose: true); - $resultCode = $symplifyErrorFormatter->formatErrors($analysisResult, $output); - - $this->assertSame($expectedExitCode, $resultCode); - - $this->assertStringMatchesFormatFile($expectedOutputFile, str_replace("\r", "\r\n",$this->getOutputContent(verbose: true))); - } - - /** - * @return Iterator - */ - public static function provideData(): Iterator - { - yield ['Some message', 1, 6, 0, __DIR__ . '/Fixture/expected_single_message_many_files_report_verbose.txt']; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/../../config/config.neon']; - } -}