Skip to content

Commit

Permalink
Editor URL - fix for traits
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed May 18, 2021
1 parent 5645c04 commit bb841d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Command/ErrorFormatter/TableErrorFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function formatErrors(
$message .= "\n💡 " . $tip;
}
if (is_string($this->editorUrl)) {
$message .= "\n✏️ " . str_replace(['%file%', '%line%'], [$file, (string) $error->getLine()], $this->editorUrl);
$message .= "\n✏️ " . str_replace(['%file%', '%line%'], [$error->getTraitFilePath() ?? $error->getFilePath(), (string) $error->getLine()], $this->editorUrl);
}
$rows[] = [
(string) $error->getLine(),
Expand Down
11 changes: 11 additions & 0 deletions tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace PHPStan\Command\ErrorFormatter;

use PHPStan\Analyser\Error;
use PHPStan\Command\AnalysisResult;
use PHPStan\File\FuzzyRelativePathHelper;
use PHPStan\File\NullRelativePathHelper;
use PHPStan\Testing\ErrorFormatterTestCase;
Expand Down Expand Up @@ -158,4 +160,13 @@ public function testFormatErrors(
$this->assertEquals($expected, $this->getOutputContent(), sprintf('%s: output do not match', $message));
}

public function testEditorUrlWithTrait(): void
{
$formatter = new TableErrorFormatter(new FuzzyRelativePathHelper(new NullRelativePathHelper(), self::DIRECTORY_PATH, [], '/'), false, 'editor://%file%/%line%');
$error = new Error('Test', 'Foo.php (in context of trait)', 12, true, 'Foo.php', 'Bar.php');
$formatter->formatErrors(new AnalysisResult([$error], [], [], [], false, null, true), $this->getOutput());

$this->assertStringContainsString('editor://Bar.php/12', $this->getOutputContent());
}

}

0 comments on commit bb841d2

Please sign in to comment.