Skip to content

Commit

Permalink
add tip-message to json error format
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Sep 20, 2022
1 parent 6d5a65c commit 7318c4a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/Command/ErrorFormatter/JsonErrorFormatter.php
Expand Up @@ -36,11 +36,17 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output): in
}
$errorsArray['files'][$file]['errors']++;

$errorsArray['files'][$file]['messages'][] = [
$message = [
'message' => $fileSpecificError->getMessage(),
'line' => $fileSpecificError->getLine(),
'ignorable' => $fileSpecificError->canBeIgnored(),
];

if ($fileSpecificError->getTip() !== null) {
$message['tip'] = $fileSpecificError->getTip();
}

$errorsArray['files'][$file]['messages'][] = $message;
}

foreach ($analysisResult->getNotFileSpecificErrors() as $notFileSpecificError) {
Expand Down
2 changes: 1 addition & 1 deletion src/Testing/ErrorFormatterTestCase.php
Expand Up @@ -81,7 +81,7 @@ protected function getAnalysisResult(int $numFileErrors, int $numGenericErrors):
$fileErrors = array_slice([
new Error('Foo', self::DIRECTORY_PATH . '/folder with unicode 😃/file name with "spaces" and unicode 😃.php', 4),
new Error('Foo', self::DIRECTORY_PATH . '/foo.php', 1),
new Error("Bar\nBar2", self::DIRECTORY_PATH . '/foo.php', 5),
new Error("Bar\nBar2", self::DIRECTORY_PATH . '/foo.php', 5, true, null, null, 'a tip'),
new Error("Bar\nBar2", self::DIRECTORY_PATH . '/folder with unicode 😃/file name with "spaces" and unicode 😃.php', 2),
new Error("Bar\nBar2", self::DIRECTORY_PATH . '/foo.php', null),
], 0, $numFileErrors);
Expand Down
Expand Up @@ -109,7 +109,8 @@ public function dataFormatterOutputProvider(): iterable
{
"message": "Bar\nBar2",
"line": 5,
"ignorable": true
"ignorable": true,
"tip": "a tip"
}
]
}
Expand Down Expand Up @@ -175,7 +176,8 @@ public function dataFormatterOutputProvider(): iterable
{
"message": "Bar\nBar2",
"line": 5,
"ignorable": true
"ignorable": true,
"tip": "a tip"
}
]
}
Expand Down
Expand Up @@ -49,7 +49,7 @@ public function dataFormatterOutputProvider(): iterable
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'folder with unicode 😃/file name with "spaces" and unicode 😃.php\' line=\'2\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Foo\' file=\'folder with unicode 😃/file name with "spaces" and unicode 😃.php\' line=\'4\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Foo\' file=\'foo.php\' line=\'1\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'a tip\']
',
];

Expand All @@ -73,7 +73,7 @@ public function dataFormatterOutputProvider(): iterable
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'folder with unicode 😃/file name with "spaces" and unicode 😃.php\' line=\'2\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Foo\' file=\'folder with unicode 😃/file name with "spaces" and unicode 😃.php\' line=\'4\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Foo\' file=\'foo.php\' line=\'1\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##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\']
',
Expand Down

0 comments on commit 7318c4a

Please sign in to comment.