Skip to content

Commit

Permalink
Add tip message to JSON error formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Oct 3, 2022
1 parent a57127c commit 8657382
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 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
4 changes: 4 additions & 0 deletions src/Testing/LevelsTestCase.php
Expand Up @@ -110,6 +110,8 @@ public function testLevels(
}
}

unset($message['tip']);

$messages[] = $message;
}

Expand All @@ -124,6 +126,8 @@ public function testLevels(
}
}

unset($previousMessage['tip']);

$missingMessages[] = $previousMessage;
}

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
14 changes: 8 additions & 6 deletions tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php
Expand Up @@ -85,13 +85,14 @@ public function dataFormatterOutputProvider(): iterable
4 Foo
------ -------------------------------------------------------------------
------ ---------
------ ----------
Line foo.php
------ ---------
------ ----------
1 Foo
5 Bar
Bar2
------ ---------
💡 a tip
------ ----------
[ERROR] Found 4 errors
Expand Down Expand Up @@ -129,13 +130,14 @@ public function dataFormatterOutputProvider(): iterable
4 Foo
------ -------------------------------------------------------------------
------ ---------
------ ----------
Line foo.php
------ ---------
------ ----------
1 Foo
5 Bar
Bar2
------ ---------
💡 a tip
------ ----------
-- ----------------------
Error
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 8657382

Please sign in to comment.