66use PHPStan \Command \AnalysisResult ;
77use PHPStan \Command \Output ;
88use PHPStan \File \RelativePathHelper ;
9+ use PHPStan \File \SimpleRelativePathHelper ;
10+ use Symfony \Component \Console \Formatter \OutputFormatter ;
911use Yamadashy \PhpStanFriendlyFormatter \CodeHighlight \CodeHighlighter ;
1012use 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