diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 03dc6eb1bda..90c837a11df 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '2b8cf93121045df5548684660ce7ae06b23b0e50'; + public const PACKAGE_VERSION = 'e37a659d4bbcdb540157a3034e8abef30e5f77bf'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-10-11 22:10:47'; + public const RELEASE_DATE = '2024-10-11 18:23:19'; /** * @var int */ diff --git a/src/ChangesReporting/Output/ConsoleOutputFormatter.php b/src/ChangesReporting/Output/ConsoleOutputFormatter.php index b6cf89ebf4d..cd76009878d 100644 --- a/src/ChangesReporting/Output/ConsoleOutputFormatter.php +++ b/src/ChangesReporting/Output/ConsoleOutputFormatter.php @@ -5,10 +5,13 @@ use RectorPrefix202410\Nette\Utils\Strings; use Rector\ChangesReporting\Contract\Output\OutputFormatterInterface; +use Rector\Configuration\Option; +use Rector\Configuration\Parameter\SimpleParameterProvider; use Rector\ValueObject\Configuration; use Rector\ValueObject\Error\SystemError; use Rector\ValueObject\ProcessResult; use Rector\ValueObject\Reporting\FileDiff; +use RectorPrefix202410\Symfony\Component\Console\Formatter\OutputFormatter; use RectorPrefix202410\Symfony\Component\Console\Style\SymfonyStyle; final class ConsoleOutputFormatter implements OutputFormatterInterface { @@ -70,7 +73,8 @@ private function reportFileDiffs(array $fileDiffs, bool $absoluteFilePath) : voi if ($firstLineNumber !== null) { $filePath .= ':' . $firstLineNumber; } - $message = \sprintf('%d) %s', ++$i, $filePath); + $filePathWithUrl = $this->addEditorUrl($filePath, $fileDiff->getAbsoluteFilePath(), $fileDiff->getRelativeFilePath(), (string) $fileDiff->getFirstLineNumber()); + $message = \sprintf('%d) %s', ++$i, $filePathWithUrl); $this->symfonyStyle->writeln($message); $this->symfonyStyle->newLine(); $this->symfonyStyle->writeln($fileDiff->getDiffConsoleFormatted()); @@ -111,4 +115,13 @@ private function createSuccessMessage(ProcessResult $processResult, Configuratio } return \sprintf('%d file%s %s by Rector', $changeCount, $changeCount > 1 ? 's' : '', $configuration->isDryRun() ? 'would have been changed (dry-run)' : ($changeCount === 1 ? 'has' : 'have') . ' been changed'); } + private function addEditorUrl(string $filePath, ?string $absoluteFilePath, ?string $relativeFilePath, ?string $lineNumber) : string + { + $editorUrl = SimpleParameterProvider::provideStringParameter(Option::EDITOR_URL, ''); + if ($editorUrl !== '') { + $editorUrl = \str_replace(['%file%', '%relFile%', '%line%'], [$absoluteFilePath, $relativeFilePath, $lineNumber], $editorUrl); + $filePath = '' . $filePath . ''; + } + return $filePath; + } } diff --git a/src/Config/RectorConfig.php b/src/Config/RectorConfig.php index f52e772b6ef..f9340a4a57e 100644 --- a/src/Config/RectorConfig.php +++ b/src/Config/RectorConfig.php @@ -336,6 +336,10 @@ public function reportingRealPath(bool $absolute = \true) : void { SimpleParameterProvider::setParameter(Option::ABSOLUTE_FILE_PATH, $absolute); } + public function editorUrl(string $editorUrl) : void + { + SimpleParameterProvider::setParameter(Option::EDITOR_URL, $editorUrl); + } /** * @internal Used only for bridge * @return array, mixed> diff --git a/src/Configuration/Option.php b/src/Configuration/Option.php index 2047e8d704b..f5ea0d23ffa 100644 --- a/src/Configuration/Option.php +++ b/src/Configuration/Option.php @@ -216,4 +216,10 @@ final class Option * @var string */ public const ABSOLUTE_FILE_PATH = 'absolute_file_path'; + /** + * @internal To add editor links to console output + * @see \Rector\Config\RectorConfig::editorUrl() + * @var string + */ + public const EDITOR_URL = 'editor_url'; } diff --git a/src/Configuration/RectorConfigBuilder.php b/src/Configuration/RectorConfigBuilder.php index f595a48a8f5..8c4fab96dec 100644 --- a/src/Configuration/RectorConfigBuilder.php +++ b/src/Configuration/RectorConfigBuilder.php @@ -177,6 +177,10 @@ final class RectorConfigBuilder * @var string[] */ private $groupLoadedSets = []; + /** + * @var string|null + */ + private $editorUrl; /** * @api soon to be used * @var bool|null @@ -288,6 +292,9 @@ public function __invoke(RectorConfig $rectorConfig) : void if ($this->reportingRealPath !== null) { $rectorConfig->reportingRealPath($this->reportingRealPath); } + if ($this->editorUrl !== null) { + $rectorConfig->editorUrl($this->editorUrl); + } } /** * @param string[] $paths @@ -815,4 +822,9 @@ public function withRealPathReporting(bool $absolutePath = \true) : self $this->reportingRealPath = $absolutePath; return $this; } + public function withEditorUrl(string $editorUrl) : self + { + $this->editorUrl = $editorUrl; + return $this; + } }