Skip to content

Commit 85ee4f9

Browse files
kamil-zacekondrejmirtes
authored andcommitted
Teamcity - show rule identifier when verbose output is set
1 parent 24e2736 commit 85ee4f9

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/Command/ErrorFormatter/TeamcityErrorFormatter.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use function count;
1111
use function is_string;
1212
use function preg_replace;
13+
use function sprintf;
1314
use const PHP_EOL;
1415

1516
/**
@@ -41,9 +42,15 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output): in
4142
]);
4243

4344
foreach ($fileSpecificErrors as $fileSpecificError) {
45+
$message = $fileSpecificError->getMessage();
46+
47+
if ($fileSpecificError->getIdentifier() !== null && $fileSpecificError->canBeIgnored()) {
48+
$message .= sprintf(' (🪪 %s)', $fileSpecificError->getIdentifier());
49+
}
50+
4451
$result .= $this->createTeamcityLine('inspection', [
4552
'typeId' => 'phpstan',
46-
'message' => $fileSpecificError->getMessage(),
53+
'message' => $message,
4754
'file' => $this->relativePathHelper->getRelativePath($fileSpecificError->getFile()),
4855
'line' => $fileSpecificError->getLine(),
4956
// additional attributes

tests/PHPStan/Command/ErrorFormatter/TeamcityErrorFormatterTest.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function dataFormatterOutputProvider(): iterable
1818
0,
1919
0,
2020
'',
21+
'',
2122
];
2223

2324
yield [
@@ -76,18 +77,29 @@ public function dataFormatterOutputProvider(): iterable
7677
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'a tip\']
7778
##teamcity[inspection typeId=\'phpstan\' message=\'first generic error\' file=\'.\' SEVERITY=\'ERROR\']
7879
##teamcity[inspection typeId=\'phpstan\' message=\'second generic<error>\' file=\'.\' SEVERITY=\'ERROR\']
80+
',
81+
];
82+
83+
yield [
84+
'One file error',
85+
1,
86+
[4, 2],
87+
0,
88+
'##teamcity[inspectionType id=\'phpstan\' name=\'phpstan\' category=\'phpstan\' description=\'phpstan Inspection\']
89+
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
90+
##teamcity[inspection typeId=\'phpstan\' message=\'Foobar\Buz (🪪 foobar.buz)\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'a tip\']
7991
',
8092
];
8193
}
8294

8395
/**
8496
* @dataProvider dataFormatterOutputProvider
85-
*
97+
* @param array{int, int}|int $numFileErrors
8698
*/
8799
public function testFormatErrors(
88100
string $message,
89101
int $exitCode,
90-
int $numFileErrors,
102+
array|int $numFileErrors,
91103
int $numGenericErrors,
92104
string $expected,
93105
): void

0 commit comments

Comments
 (0)