Skip to content

Commit 75050b5

Browse files
authored
Update ErrorWriter.php
1 parent 87d5b38 commit 75050b5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/ErrorFormat/ErrorWriter.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use PHPStan\Command\AnalysisResult;
77
use PHPStan\Command\Output;
88
use PHPStan\File\RelativePathHelper;
9+
use PHPStan\File\SimpleRelativePathHelper;
10+
use Symfony\Component\Console\Formatter\OutputFormatter;
911
use Yamadashy\PhpStanFriendlyFormatter\CodeHighlight\CodeHighlighter;
1012
use Yamadashy\PhpStanFriendlyFormatter\Config\FriendlyFormatterConfig;
1113

@@ -14,14 +16,19 @@ class ErrorWriter
1416
/** @var RelativePathHelper */
1517
private $relativePathHelper;
1618

19+
/** @var SimpleRelativePathHelper */
20+
private $simpleRelativePathHelper;
21+
1722
/** @var FriendlyFormatterConfig */
1823
private $config;
1924

2025
public function __construct(
2126
RelativePathHelper $relativePathHelper,
27+
SimpleRelativePathHelper $simpleRelativePathHelper,
2228
FriendlyFormatterConfig $config
2329
) {
2430
$this->relativePathHelper = $relativePathHelper;
31+
$this->simpleRelativePathHelper = $simpleRelativePathHelper;
2532
$this->config = $config;
2633
}
2734

@@ -72,7 +79,11 @@ public function writeFileSpecificErrors(AnalysisResult $analysisResult, Output $
7279
}
7380

7481
if (\is_string($this->config->editorUrl)) {
75-
$output->writeLineFormatted(' ✏️ '.str_replace(['%file%', '%line%'], [$error->getTraitFilePath() ?? $error->getFilePath(), (string) $error->getLine()], $this->config->editorUrl));
82+
$output->writeLineFormatted(' ✏️ <href='.OutputFormatter::escape(str_replace(
83+
['%file%', '%relFile%', '%line%'],
84+
[$filePath, $this->simpleRelativePathHelper->getRelativePath($filePath), (string) $error->getLine()],
85+
$this->config->editorUrl,
86+
)).'>'.$relativeFilePath.'</>');
7687
}
7788

7889
$output->writeLineFormatted($codeSnippet);

0 commit comments

Comments
 (0)