Skip to content

Commit

Permalink
Checkstyle error formatter - always use file path, not file description
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Apr 18, 2020
1 parent 31cb273 commit 94dc8d2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Command/ErrorFormatter/CheckstyleErrorFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ private function groupByFile(AnalysisResult $analysisResult): array

/** @var \PHPStan\Analyser\Error $fileSpecificError */
foreach ($analysisResult->getFileSpecificErrors() as $fileSpecificError) {
$absolutePath = $fileSpecificError->getFilePath();
if ($fileSpecificError->getTraitFilePath() !== null) {
$absolutePath = $fileSpecificError->getTraitFilePath();
}
$relativeFilePath = $this->relativePathHelper->getRelativePath(
$fileSpecificError->getFile()
$absolutePath
);

$files[$relativeFilePath][] = $fileSpecificError;
Expand Down
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\SimpleRelativePathHelper;
use PHPStan\Testing\ErrorFormatterTestCase;

Expand Down Expand Up @@ -136,4 +138,30 @@ public function testFormatErrors(
$this->assertStringStartsWith('<?xml', $outputContent);
}

public function testTraitPath(): void
{
$formatter = new CheckstyleErrorFormatter(new SimpleRelativePathHelper(__DIR__));
$error = new Error(
'Foo',
__DIR__ . '/FooTrait.php (in context of class Foo)',
5,
true,
__DIR__ . '/Foo.php',
__DIR__ . '/FooTrait.php'
);
$formatter->formatErrors(new AnalysisResult(
[$error],
[],
[],
false,
false,
null
), $this->getOutput());
$this->assertXmlStringEqualsXmlString('<checkstyle>
<file name="FooTrait.php">
<error column="1" line="5" message="Foo" severity="error"/>
</file>
</checkstyle>', $this->getOutputContent());
}

}

0 comments on commit 94dc8d2

Please sign in to comment.