diff --git a/extension.neon b/extension.neon index f521483..55d5d55 100644 --- a/extension.neon +++ b/extension.neon @@ -15,6 +15,7 @@ services: errorFormatter.friendly: class: Yamadashy\PhpStanFriendlyFormatter\FriendlyErrorFormatter arguments: + simpleRelativePathHelper: @simpleRelativePathHelper lineBefore: %friendly.lineBefore% lineAfter: %friendly.lineAfter% editorUrl: %friendly.editorUrl% diff --git a/src/ErrorFormat/ErrorWriter.php b/src/ErrorFormat/ErrorWriter.php index e73b4cf..cacc997 100644 --- a/src/ErrorFormat/ErrorWriter.php +++ b/src/ErrorFormat/ErrorWriter.php @@ -6,6 +6,8 @@ use PHPStan\Command\AnalysisResult; use PHPStan\Command\Output; use PHPStan\File\RelativePathHelper; +use PHPStan\File\SimpleRelativePathHelper; +use Symfony\Component\Console\Formatter\OutputFormatter; use Yamadashy\PhpStanFriendlyFormatter\CodeHighlight\CodeHighlighter; use Yamadashy\PhpStanFriendlyFormatter\Config\FriendlyFormatterConfig; @@ -14,14 +16,19 @@ class ErrorWriter /** @var RelativePathHelper */ private $relativePathHelper; + /** @var SimpleRelativePathHelper */ + private $simpleRelativePathHelper; + /** @var FriendlyFormatterConfig */ private $config; public function __construct( RelativePathHelper $relativePathHelper, + SimpleRelativePathHelper $simpleRelativePathHelper, FriendlyFormatterConfig $config ) { $this->relativePathHelper = $relativePathHelper; + $this->simpleRelativePathHelper = $simpleRelativePathHelper; $this->config = $config; } @@ -72,7 +79,11 @@ public function writeFileSpecificErrors(AnalysisResult $analysisResult, Output $ } if (\is_string($this->config->editorUrl)) { - $output->writeLineFormatted(' ✏️ '.str_replace(['%file%', '%line%'], [$error->getTraitFilePath() ?? $error->getFilePath(), (string) $error->getLine()], $this->config->editorUrl)); + $output->writeLineFormatted(' ✏️ simpleRelativePathHelper->getRelativePath($filePath), (string) $error->getLine()], + $this->config->editorUrl, + )).'>'.$relativeFilePath.''); } $output->writeLineFormatted($codeSnippet); diff --git a/src/FriendlyErrorFormatter.php b/src/FriendlyErrorFormatter.php index f69e221..1e05c00 100644 --- a/src/FriendlyErrorFormatter.php +++ b/src/FriendlyErrorFormatter.php @@ -7,6 +7,7 @@ use PHPStan\Command\ErrorFormatter\ErrorFormatter; use PHPStan\Command\Output; use PHPStan\File\RelativePathHelper; +use PHPStan\File\SimpleRelativePathHelper; use Yamadashy\PhpStanFriendlyFormatter\Config\FriendlyFormatterConfig; use Yamadashy\PhpStanFriendlyFormatter\ErrorFormat\ErrorWriter; use Yamadashy\PhpStanFriendlyFormatter\ErrorFormat\SummaryWriter; @@ -16,12 +17,21 @@ class FriendlyErrorFormatter implements ErrorFormatter /** @var RelativePathHelper */ private $relativePathHelper; + /** @var SimpleRelativePathHelper */ + private $simpleRelativePathHelper; + /** @var FriendlyFormatterConfig */ private $config; - public function __construct(RelativePathHelper $relativePathHelper, int $lineBefore, int $lineAfter, ?string $editorUrl) - { + public function __construct( + RelativePathHelper $relativePathHelper, + SimpleRelativePathHelper $simpleRelativePathHelper, + int $lineBefore, + int $lineAfter, + ?string $editorUrl + ) { $this->relativePathHelper = $relativePathHelper; + $this->simpleRelativePathHelper = $simpleRelativePathHelper; $this->config = new FriendlyFormatterConfig( $lineBefore, $lineAfter, @@ -40,7 +50,7 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output): in $output->writeLineFormatted(''); - $errorWriter = new ErrorWriter($this->relativePathHelper, $this->config); + $errorWriter = new ErrorWriter($this->relativePathHelper, $this->simpleRelativePathHelper, $this->config); $errorWriter->writeFileSpecificErrors($analysisResult, $output); $errorWriter->writeNotFileSpecificErrors($analysisResult, $output); $errorWriter->writeWarnings($analysisResult, $output);