Skip to content

Commit f66cf5b

Browse files
committed
CheckstyleErrorFormatter - include error identifier in source attribute
1 parent 1c8894d commit f66cf5b

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Command/ErrorFormatter/CheckstyleErrorFormatter.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ public function formatErrors(
3838

3939
foreach ($errors as $error) {
4040
$output->writeRaw(sprintf(
41-
' <error line="%d" column="1" severity="error" message="%s" />',
41+
' <error line="%d" column="1" severity="error" message="%s"%s />',
4242
$this->escape((string) $error->getLine()),
4343
$this->escape($error->getMessage()),
44+
$error->getIdentifier() !== null ? sprintf(' source="%s"', $this->escape($error->getIdentifier())) : '',
4445
));
4546
$output->writeLineFormatted('');
4647
}

tests/PHPStan/Command/ErrorFormatter/CheckstyleErrorFormatterTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,33 @@ public function testTraitPath(): void
163163
</checkstyle>', $this->getOutputContent());
164164
}
165165

166+
public function testIdentifier(): void
167+
{
168+
$formatter = new CheckstyleErrorFormatter(new SimpleRelativePathHelper(__DIR__));
169+
$error = (new Error(
170+
'Foo',
171+
__DIR__ . '/FooTrait.php',
172+
5,
173+
true,
174+
__DIR__ . '/Foo.php',
175+
null,
176+
))->withIdentifier('argument.type');
177+
$formatter->formatErrors(new AnalysisResult(
178+
[$error],
179+
[],
180+
[],
181+
[],
182+
[],
183+
false,
184+
null,
185+
true,
186+
0,
187+
), $this->getOutput());
188+
$this->assertXmlStringEqualsXmlString('<checkstyle>
189+
<file name="Foo.php">
190+
<error column="1" line="5" message="Foo" severity="error" source="argument.type" />
191+
</file>
192+
</checkstyle>', $this->getOutputContent());
193+
}
194+
166195
}

0 commit comments

Comments
 (0)