From c7f7912efe812c43429dc75bcd5fcd36df915737 Mon Sep 17 00:00:00 2001 From: Grzegorz Korba Date: Sun, 12 Jun 2022 01:03:13 +0200 Subject: [PATCH] Support for relative paths in `editorUrl` This allows running PHPStan within Docker environment and output errors with links to files on the host (`editorUrl` must be configured using actual host's path to the project + `%rel_file%`). Fixes phpstan/phpstan#7043 --- src/Command/ErrorFormatter/TableErrorFormatter.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Command/ErrorFormatter/TableErrorFormatter.php b/src/Command/ErrorFormatter/TableErrorFormatter.php index a6e8ed31398..4494233aacc 100644 --- a/src/Command/ErrorFormatter/TableErrorFormatter.php +++ b/src/Command/ErrorFormatter/TableErrorFormatter.php @@ -78,7 +78,11 @@ public function formatErrors( } if (is_string($this->editorUrl)) { $editorFile = $error->getTraitFilePath() ?? $error->getFilePath(); - $url = str_replace(['%file%', '%line%'], [$editorFile, (string) $error->getLine()], $this->editorUrl); + $url = str_replace( + ['%file%', '%rel_file%', '%line%'], + [$editorFile, $this->relativePathHelper->getRelativePath($editorFile), (string) $error->getLine()], + $this->editorUrl, + ); $message .= "\n✏️ ' . $this->relativePathHelper->getRelativePath($editorFile) . ''; } $rows[] = [