From 93071bbedde15b0fcf1177419bc3a7e21a0692c2 Mon Sep 17 00:00:00 2001 From: Felix Bernhard Date: Mon, 25 Aug 2025 19:04:06 +0200 Subject: [PATCH] replace `PHP_EOL` with `\n` when used with symfony console --- src/ChangesReporting/Output/ConsoleOutputFormatter.php | 3 ++- src/Console/Command/ProcessCommand.php | 10 +++++----- src/Console/Command/SetupCICommand.php | 2 +- .../DependencyInjection/PHPStanServicesFactory.php | 2 +- src/Reporting/MissConfigurationReporter.php | 6 +++--- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/ChangesReporting/Output/ConsoleOutputFormatter.php b/src/ChangesReporting/Output/ConsoleOutputFormatter.php index 81c3322f637..6b0e5679ef6 100644 --- a/src/ChangesReporting/Output/ConsoleOutputFormatter.php +++ b/src/ChangesReporting/Output/ConsoleOutputFormatter.php @@ -115,6 +115,7 @@ private function reportErrors(array $errors, bool $absoluteFilePath): void foreach ($errors as $error) { $errorMessage = $error->getMessage(); $errorMessage = $this->normalizePathsToRelativeWithLine($errorMessage); + $errorMessage = str_replace("\r\n", "\n", $errorMessage); $filePath = $absoluteFilePath ? $error->getAbsoluteFilePath() : $error->getRelativeFilePath(); @@ -122,7 +123,7 @@ private function reportErrors(array $errors, bool $absoluteFilePath): void 'Could not process %s%s, due to: %s"%s".', $filePath !== null ? '"' . $filePath . '" file' : 'some files', $error->getRectorClass() !== null ? ' by "' . $error->getRectorClass() . '"' : '', - PHP_EOL, + "\n", $errorMessage ); diff --git a/src/Console/Command/ProcessCommand.php b/src/Console/Command/ProcessCommand.php index f2e978ccf94..14b7754f8df 100644 --- a/src/Console/Command/ProcessCommand.php +++ b/src/Console/Command/ProcessCommand.php @@ -119,8 +119,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($setAndRulesDuplicatedRegistrations !== []) { $this->symfonyStyle->warning(sprintf( 'These rules are registered in both sets and "withRules()". Remove them from "withRules()" to avoid duplications: %s* %s', - PHP_EOL . PHP_EOL, - implode(' * ', $setAndRulesDuplicatedRegistrations) . PHP_EOL + "\n\n", + implode(' * ', $setAndRulesDuplicatedRegistrations) . "\n" )); } @@ -145,8 +145,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $isSingular ? 'es' : '', $isSingular ? '' : 's', $isSingular ? 'y' : 'ies', - PHP_EOL . PHP_EOL . ' - ', - implode(PHP_EOL . ' - ', $paths) + "\n\n" . ' - ', + implode("\n" . ' - ', $paths) ) ); @@ -253,7 +253,7 @@ private function reportLevelOverflow(LevelOverflow $levelOverflow): void $levelOverflow->getConfigurationName(), $levelOverflow->getRuleCount(), $levelOverflow->getLevel(), - PHP_EOL, + "\n", $suggestedSetMethod, )); } diff --git a/src/Console/Command/SetupCICommand.php b/src/Console/Command/SetupCICommand.php index bbb566d0f32..4b19f9b54d4 100644 --- a/src/Console/Command/SetupCICommand.php +++ b/src/Console/Command/SetupCICommand.php @@ -42,7 +42,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $noteMessage = sprintf( 'Only GitHub and GitLab are currently supported.%s Contribute your CI template to Rector to make this work: %s', - PHP_EOL, + "\n", 'https://github.com/rectorphp/rector-src/' ); diff --git a/src/NodeTypeResolver/DependencyInjection/PHPStanServicesFactory.php b/src/NodeTypeResolver/DependencyInjection/PHPStanServicesFactory.php index 7f4b450d126..b983c7be64c 100644 --- a/src/NodeTypeResolver/DependencyInjection/PHPStanServicesFactory.php +++ b/src/NodeTypeResolver/DependencyInjection/PHPStanServicesFactory.php @@ -58,7 +58,7 @@ public function __construct() } catch (Throwable $throwable) { if ($throwable->getMessage() === "File 'phar://phpstan.phar/conf/bleedingEdge.neon' is missing or is not readable.") { $symfonyStyle = new SymfonyStyle(new ArrayInput([]), new ConsoleOutput()); - $symfonyStyle->error(sprintf(self::INVALID_BLEEDING_EDGE_PATH_MESSAGE, $throwable->getMessage())); + $symfonyStyle->error(str_replace("\r\n", "\n", sprintf(self::INVALID_BLEEDING_EDGE_PATH_MESSAGE, $throwable->getMessage()))); exit(-1); } diff --git a/src/Reporting/MissConfigurationReporter.php b/src/Reporting/MissConfigurationReporter.php index d5529dfc13e..208220c3c7e 100644 --- a/src/Reporting/MissConfigurationReporter.php +++ b/src/Reporting/MissConfigurationReporter.php @@ -55,7 +55,7 @@ public function reportVendorInPaths(array $filePaths): void $this->symfonyStyle->warning(sprintf( 'Rector has detected a "/vendor" directory in your configured paths. If this is Composer\'s vendor directory, this is not necessary as it will be autoloaded. Scanning the Composer /vendor directory will cause Rector to run much slower and possibly with errors.%sRemove "/vendor" from Rector paths and run again.', - PHP_EOL . PHP_EOL + "\n\n" )); sleep(3); @@ -69,12 +69,12 @@ public function reportStartWithShortOpenTag(): void } $suffix = count($files) > 1 ? 's were' : ' was'; - $fileList = implode(PHP_EOL, $files); + $fileList = implode("\n", $files); $this->symfonyStyle->warning(sprintf( 'The following file%s skipped as starting with short open tag. Migrate to long open PHP tag first: %s%s', $suffix, - PHP_EOL . PHP_EOL, + "\n\n", $fileList ));