From d9402bdc3e28bc889c9c735f925c03fffd588a63 Mon Sep 17 00:00:00 2001 From: NickSdot Date: Tue, 7 Oct 2025 13:52:32 +0700 Subject: [PATCH 1/2] refactor(formatters): added error identifier to actual checkstyle the message --- src/Command/ErrorFormatter/CheckstyleErrorFormatter.php | 7 ++++++- .../ErrorFormatter/CheckstyleErrorFormatterTest.php | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Command/ErrorFormatter/CheckstyleErrorFormatter.php b/src/Command/ErrorFormatter/CheckstyleErrorFormatter.php index 8120dea1ef..569ab6586a 100644 --- a/src/Command/ErrorFormatter/CheckstyleErrorFormatter.php +++ b/src/Command/ErrorFormatter/CheckstyleErrorFormatter.php @@ -43,10 +43,15 @@ public function formatErrors( $output->writeLineFormatted(''); foreach ($errors as $error) { + + $identifier = null !== $error->getIdentifier() + ? " // @phpstan-ignore {$error->getIdentifier()}" : + ''; + $output->writeRaw(sprintf( ' ', $this->escape((string) $error->getLine()), - $this->escape($error->getMessage()), + $this->escape($error->getMessage() . $identifier), $error->getIdentifier() !== null ? sprintf(' source="%s"', $this->escape($error->getIdentifier())) : '', )); $output->writeLineFormatted(''); diff --git a/tests/PHPStan/Command/ErrorFormatter/CheckstyleErrorFormatterTest.php b/tests/PHPStan/Command/ErrorFormatter/CheckstyleErrorFormatterTest.php index 48e906017c..34f7ef2f46 100644 --- a/tests/PHPStan/Command/ErrorFormatter/CheckstyleErrorFormatterTest.php +++ b/tests/PHPStan/Command/ErrorFormatter/CheckstyleErrorFormatterTest.php @@ -186,7 +186,7 @@ public function testIdentifier(): void ), $this->getOutput()); $this->assertXmlStringEqualsXmlString(' - + ', $this->getOutputContent()); } From ee972b4ac284d57267547975e60fef11414c0cba Mon Sep 17 00:00:00 2001 From: NickSdot Date: Tue, 7 Oct 2025 14:06:52 +0700 Subject: [PATCH 2/2] refactor(formatters): code style --- src/Command/ErrorFormatter/CheckstyleErrorFormatter.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Command/ErrorFormatter/CheckstyleErrorFormatter.php b/src/Command/ErrorFormatter/CheckstyleErrorFormatter.php index 569ab6586a..4afb8ca3f1 100644 --- a/src/Command/ErrorFormatter/CheckstyleErrorFormatter.php +++ b/src/Command/ErrorFormatter/CheckstyleErrorFormatter.php @@ -44,15 +44,13 @@ public function formatErrors( foreach ($errors as $error) { - $identifier = null !== $error->getIdentifier() - ? " // @phpstan-ignore {$error->getIdentifier()}" : - ''; + $identifier = $error->getIdentifier(); $output->writeRaw(sprintf( ' ', $this->escape((string) $error->getLine()), - $this->escape($error->getMessage() . $identifier), - $error->getIdentifier() !== null ? sprintf(' source="%s"', $this->escape($error->getIdentifier())) : '', + $this->escape($error->getMessage() . ($identifier !== null ? sprintf(' // @phpstan-ignore %s', $identifier) : '')), + $identifier !== null ? sprintf(' source="%s"', $this->escape($identifier)) : '', )); $output->writeLineFormatted(''); }