From b82d78efa56792f12f1cd6e52703aa462bed6e52 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 16 Nov 2026 21:44:05 +0100 Subject: [PATCH] [ChangesReporting] Remove deprecated github and gitlab output formats --- phpstan-deprecated.neon | 9 - .../Output/GitHubOutputFormatter.php | 156 ------------------ .../Output/GitlabOutputFormatter.php | 156 ------------------ src/Console/Command/ProcessCommand.php | 10 -- .../Output/GitHubOutputFormatterTest.php | 113 ------------- 5 files changed, 444 deletions(-) delete mode 100644 src/ChangesReporting/Output/GitHubOutputFormatter.php delete mode 100644 src/ChangesReporting/Output/GitlabOutputFormatter.php delete mode 100644 tests/ChangesReporting/Output/GitHubOutputFormatterTest.php diff --git a/phpstan-deprecated.neon b/phpstan-deprecated.neon index 639a2b6286c..02caadda8b9 100644 --- a/phpstan-deprecated.neon +++ b/phpstan-deprecated.neon @@ -23,12 +23,3 @@ parameters: paths: - config/set/level - tests/Bridge/SetRectorsResolverTest.php - - # the deprecated github/gitlab output formatters are still tested until removed in next minor version - - - identifier: new.deprecatedClass - path: tests/ChangesReporting/Output/GitHubOutputFormatterTest.php - - - - identifier: method.deprecatedClass - path: tests/ChangesReporting/Output/GitHubOutputFormatterTest.php diff --git a/src/ChangesReporting/Output/GitHubOutputFormatter.php b/src/ChangesReporting/Output/GitHubOutputFormatter.php deleted file mode 100644 index 96a643f118e..00000000000 --- a/src/ChangesReporting/Output/GitHubOutputFormatter.php +++ /dev/null @@ -1,156 +0,0 @@ -startGroup(); - - $this->reportSystemErrors($processResult, $configuration); - $this->reportFileDiffs($processResult, $configuration); - - $this->endGroup(); - } - - private function startGroup(): void - { - echo sprintf('::group::%s', self::GROUP_NAME) . PHP_EOL; - } - - private function endGroup(): void - { - echo '::endgroup::' . PHP_EOL; - } - - private function reportSystemErrors(ProcessResult $processResult, Configuration $configuration): void - { - foreach ($processResult->getSystemErrors() as $systemError) { - $filePath = $configuration->isReportingWithRealPath() - ? $systemError->getAbsoluteFilePath() - : $systemError->getRelativeFilePath(); - - $line = $systemError->getLine(); - $message = trim($systemError->getRectorShortClass() . PHP_EOL . $systemError->getMessage()); - - $this->reportErrorAnnotation($message, [ - 'file' => $filePath, - 'line' => $line, - ]); - } - } - - private function reportFileDiffs(ProcessResult $processResult, Configuration $configuration): void - { - - $fileDiffs = $processResult->getFileDiffs(); - ksort($fileDiffs); - - foreach ($fileDiffs as $fileDiff) { - $filePath = $configuration->isReportingWithRealPath() - ? $fileDiff->getAbsoluteFilePath() - : $fileDiff->getRelativeFilePath(); - - $line = $fileDiff->getFirstLineNumber(); - $endLine = $fileDiff->getLastLineNumber(); - - $message = trim( - implode(' / ', $fileDiff->getRectorShortClasses()) - ) . PHP_EOL . PHP_EOL . $fileDiff->getDiff(); - - $this->reportErrorAnnotation($message, [ - 'file' => $filePath, - 'line' => $line, - 'endLine' => $endLine, - ]); - } - } - - /** - * @param AnnotationProperties $annotationProperties - */ - private function reportErrorAnnotation(string $message, array $annotationProperties): void - { - $properties = $this->sanitizeAnnotationProperties($annotationProperties); - - $command = sprintf('::error %s::%s', $properties, $message); - - // Sanitize command - $command = str_replace(['%', "\r", "\n"], ['%25', '%0D', '%0A'], $command); - - echo $command . PHP_EOL; - } - - /** - * @param AnnotationProperties $annotationProperties - */ - private function sanitizeAnnotationProperties(array $annotationProperties): string - { - if (! isset($annotationProperties['line']) || ! $annotationProperties['line']) { - $annotationProperties['line'] = 0; - } - - // This is a workaround for buggy endLine. See https://github.com/orgs/community/discussions/129899 - // TODO: Should be removed once github will have fixed it issue. - unset($annotationProperties['endLine']); - - $nonNullProperties = array_filter( - $annotationProperties, - static fn (int|string|null $value): bool => $value !== null - ); - - $sanitizedProperties = array_map( - fn (string $key, string|int|null $value): string => sprintf( - '%s=%s', - $key, - $this->sanitizeAnnotationProperty($value) - ), - array_keys($nonNullProperties), - $nonNullProperties - ); - - return implode(',', $sanitizedProperties); - } - - private function sanitizeAnnotationProperty(string|int|null $value): string - { - if ($value === null || $value === '') { - return ''; - } - - $value = (string) $value; - - return str_replace(['%', "\r", "\n", ':', ','], ['%25', '%0D', '%0A', '%3A', '%2C'], $value); - } -} diff --git a/src/ChangesReporting/Output/GitlabOutputFormatter.php b/src/ChangesReporting/Output/GitlabOutputFormatter.php deleted file mode 100644 index 970113e1066..00000000000 --- a/src/ChangesReporting/Output/GitlabOutputFormatter.php +++ /dev/null @@ -1,156 +0,0 @@ -appendSystemErrors($processResult, $configuration), - ...$this->appendFileDiffs($processResult, $configuration), - ]; - - $json = Json::encode($errorsJson, true); - - echo $json . PHP_EOL; - } - - /** - * @return array - */ - private function appendSystemErrors(ProcessResult $processResult, Configuration $configuration): array - { - $errorsJson = []; - - foreach ($processResult->getSystemErrors() as $systemError) { - $filePath = $configuration->isReportingWithRealPath() - ? ($systemError->getAbsoluteFilePath() ?? '') - : ($systemError->getRelativeFilePath() ?? '') - ; - - $fingerprint = $this->filehasher->hash( - $filePath . ';' . $systemError->getLine() . ';' . $systemError->getMessage() - ); - - $errorsJson[] = [ - 'fingerprint' => $fingerprint, - 'type' => self::ERROR_TYPE_ISSUE, - 'categories' => [self::ERROR_CATEGORY_BUG_RISK], - 'severity' => self::ERROR_SEVERITY_BLOCKER, - 'description' => $systemError->getMessage(), - 'check_name' => $systemError->getRectorClass() ?? '', - 'location' => [ - 'path' => $filePath, - 'lines' => [ - 'begin' => $systemError->getLine() ?? 0, - ], - ], - ]; - } - - return $errorsJson; - } - - /** - * @return array - */ - private function appendFileDiffs(ProcessResult $processResult, Configuration $configuration): array - { - $errorsJson = []; - - $fileDiffs = $processResult->getFileDiffs(); - ksort($fileDiffs); - - foreach ($fileDiffs as $fileDiff) { - $filePath = $configuration->isReportingWithRealPath() - ? ($fileDiff->getAbsoluteFilePath() ?? '') - : ($fileDiff->getRelativeFilePath() ?? '') - ; - - $rectorClasses = implode(' / ', $fileDiff->getRectorShortClasses()); - $fingerprint = $this->filehasher->hash($filePath . ';' . $fileDiff->getDiff()); - - $errorsJson[] = [ - 'fingerprint' => $fingerprint, - 'type' => self::ERROR_TYPE_ISSUE, - 'categories' => [self::ERROR_CATEGORY_STYLE], - 'severity' => self::ERROR_SEVERITY_MINOR, - 'description' => $rectorClasses, - 'content' => [ - 'body' => $fileDiff->getDiff(), - ], - 'check_name' => $rectorClasses, - 'location' => [ - 'path' => $filePath, - 'lines' => [ - 'begin' => $fileDiff->getFirstLineNumber() ?? 0, - ], - ], - ]; - } - - return $errorsJson; - } -} diff --git a/src/Console/Command/ProcessCommand.php b/src/Console/Command/ProcessCommand.php index 93254c835da..851825921d6 100644 --- a/src/Console/Command/ProcessCommand.php +++ b/src/Console/Command/ProcessCommand.php @@ -178,16 +178,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int // 3. reporting phaseRunning 2nd time with collectors data // report diffs and errors $outputFormat = $configuration->getOutputFormat(); - - // warn about deprecated static-analysis-oriented output formats, to be removed in next minor version - if (in_array($outputFormat, ['github', 'gitlab'], true)) { - $this->symfonyStyle->getErrorStyle() - ->warning(sprintf( - 'The "%s" output format is deprecated and will be removed in the next minor version, as Rector is not a static analysis tool.', - $outputFormat - )); - } - $outputFormatter = $this->outputFormatterCollector->getByName($outputFormat); $outputFormatter->report($processResult, $configuration); diff --git a/tests/ChangesReporting/Output/GitHubOutputFormatterTest.php b/tests/ChangesReporting/Output/GitHubOutputFormatterTest.php deleted file mode 100644 index 98a1d8ad1a8..00000000000 --- a/tests/ChangesReporting/Output/GitHubOutputFormatterTest.php +++ /dev/null @@ -1,113 +0,0 @@ -gitHubOutputFormatter = new GitHubOutputFormatter(); - - parent::setUp(); - } - - public function testGetName(): void - { - $this->assertSame('github', $this->gitHubOutputFormatter->getName()); - } - - public function testReportShouldOutputErrorMessagesGrouped(): void - { - - $this->expectOsOutputString( - '::group::Rector report' . PHP_EOL . - '::error file=some/file.php,line=1::Some error message' . PHP_EOL . - '::error file=some/file.php,line=38::StrStartsWithRector%0A%0A--- Original%0A+++ New%0A@@ -38,5 +39,6 @@%0Areturn true;%0A}%0A' . PHP_EOL . - '::endgroup::' . PHP_EOL - ); - - $this->gitHubOutputFormatter->report( - new ProcessResult( - [new SystemError('Some error message', 'some/file.php', 1)], - [ - new FileDiff( - 'some/file.php', - '--- Original' . PHP_EOL . '+++ New' . PHP_EOL . - '@@ -38,5 +39,6 @@' . PHP_EOL . - 'return true;' . PHP_EOL . '}' . PHP_EOL, - 'diff console formatted', - [new RectorWithLineChange(StrStartsWithRector::class, 38)] - ), - ], - 1 - ), - new Configuration() - ); - } - - public function testReportShouldOutputErrorMessagesGroupedWithNoErrors(): void - { - $this->expectOsOutputString('::group::Rector report' . PHP_EOL . '::endgroup::' . PHP_EOL); - - $this->gitHubOutputFormatter->report(new ProcessResult([], [], 1), new Configuration()); - } - - public function testReportShouldOutputErrorMessagesGroupedWithMultipleDiffs(): void - { - $this->expectOsOutputString( - '::group::Rector report' . PHP_EOL . - '::error file=some/file.php,line=38::StrStartsWithRector / NullToStrictStringFuncCallArgRector%0A%0A--- Original%0A+++ New%0A@@ -38,5 +39,6 @@%0Areturn true;%0A}%0A' . PHP_EOL . - '::error file=some/another-file.php,line=54::StrStartsWithRector%0A%0A--- Original%0A+++ New%0A@@ -54,10 +54,10 @@%0Areturn true;%0A}%0A' . PHP_EOL . - '::endgroup::' . PHP_EOL - ); - - $this->gitHubOutputFormatter->report( - new ProcessResult([], [ - new FileDiff( - 'some/file.php', - '--- Original' . PHP_EOL . '+++ New' . PHP_EOL . - '@@ -38,5 +39,6 @@' . PHP_EOL . - 'return true;' . PHP_EOL . '}' . PHP_EOL, - 'diff console formatted', - [ - new RectorWithLineChange(StrStartsWithRector::class, 38), - new RectorWithLineChange(NullToStrictStringFuncCallArgRector::class, 38), - ] - ), - new FileDiff( - 'some/another-file.php', - '--- Original' . PHP_EOL . '+++ New' . PHP_EOL . - '@@ -54,10 +54,10 @@' . PHP_EOL . - 'return true;' . PHP_EOL . '}' . PHP_EOL, - 'diff console formatted', - [new RectorWithLineChange(StrStartsWithRector::class, 54)] - ), - ], 2), - new Configuration() - ); - } - - protected function expectOsOutputString(string $expectedOutput): void - { - $isWindows = strncasecmp(PHP_OS, 'WIN', 3) === 0; - if ($isWindows) { - $expectedOutput = str_replace('%0A', '%0D%0A', $expectedOutput); - } - - parent::expectOutputString($expectedOutput); - } -}