Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Command/ErrorFormatter/TeamcityErrorFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use function count;
use function is_string;
use function preg_replace;
use function sprintf;
use const PHP_EOL;

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

foreach ($fileSpecificErrors as $fileSpecificError) {
$message = $fileSpecificError->getMessage();

if ($fileSpecificError->getIdentifier() !== null && $fileSpecificError->canBeIgnored()) {
$message .= sprintf(' (🪪 %s)', $fileSpecificError->getIdentifier());
}

$result .= $this->createTeamcityLine('inspection', [
'typeId' => 'phpstan',
'message' => $fileSpecificError->getMessage(),
'message' => $message,
'file' => $this->relativePathHelper->getRelativePath($fileSpecificError->getFile()),
'line' => $fileSpecificError->getLine(),
// additional attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function dataFormatterOutputProvider(): iterable
0,
0,
'',
'',
];

yield [
Expand Down Expand Up @@ -76,18 +77,29 @@ public function dataFormatterOutputProvider(): iterable
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'a tip\']
##teamcity[inspection typeId=\'phpstan\' message=\'first generic error\' file=\'.\' SEVERITY=\'ERROR\']
##teamcity[inspection typeId=\'phpstan\' message=\'second generic<error>\' file=\'.\' SEVERITY=\'ERROR\']
',
];

yield [
'One file error',
1,
[4, 2],
0,
'##teamcity[inspectionType id=\'phpstan\' name=\'phpstan\' category=\'phpstan\' description=\'phpstan Inspection\']
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Foobar\Buz (🪪 foobar.buz)\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'a tip\']
',
];
}

/**
* @dataProvider dataFormatterOutputProvider
*
* @param array{int, int}|int $numFileErrors
*/
public function testFormatErrors(
string $message,
int $exitCode,
int $numFileErrors,
array|int $numFileErrors,
int $numGenericErrors,
string $expected,
): void
Expand Down
Loading