Skip to content

Commit d05326a

Browse files
committed
feat: GitLab 13.x expects severity field in code quality reports
Ref: phpstan/phpstan-src@a00eb3f Ref: phpstan/phpstan-src#504
1 parent 696d5be commit d05326a

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/ErrorFormatter/GitlabErrorFormatter.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output): in
6969
]
7070
)
7171
),
72+
'severity' => $fileSpecificError->canBeIgnored() ? 'major' : 'blocker',
7273
'location' => [
7374
'path' => $this->relativePathHelper->getRelativePath($file),
7475
'lines' => [
@@ -77,17 +78,14 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output): in
7778
],
7879
];
7980

80-
if (!$fileSpecificError->canBeIgnored()) {
81-
$error['severity'] = 'blocker';
82-
}
83-
8481
$errorsArray[] = $error;
8582
}
8683

8784
foreach ($analysisResult->getNotFileSpecificErrors() as $notFileSpecificError) {
8885
$errorsArray[] = [
8986
'description' => $notFileSpecificError,
9087
'fingerprint' => hash('sha256', $notFileSpecificError),
88+
'severity' => 'major',
9189
'location' => [
9290
'path' => '',
9391
'lines' => [

tests/ErrorFormatter/GitlabFormatterTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public function dataFormatterOutputProvider(): iterable
5757
{
5858
"description": "Foo",
5959
"fingerprint": "e82b7e1f1d4255352b19ecefa9116a12f129c7edb4351cf2319285eccdb1565e",
60+
"severity": "major",
6061
"location": {
6162
"path": "with space/and unicode 😃/project/folder with unicode 😃/file name with \"spaces\" and unicode 😃.php",
6263
"lines": {
@@ -76,6 +77,7 @@ public function dataFormatterOutputProvider(): iterable
7677
{
7778
"description": "first generic error",
7879
"fingerprint": "53ed216d77c9a9b21d9535322457ca7d7b037d6596d76484b3481f161adfd96f",
80+
"severity": "major",
7981
"location": {
8082
"path": "",
8183
"lines": {
@@ -95,6 +97,7 @@ public function dataFormatterOutputProvider(): iterable
9597
{
9698
"description": "Bar\nBar2",
9799
"fingerprint": "034b4afbfb347494c14e396ed8327692f58be4cd27e8aff5f19f4194934db7c9",
100+
"severity": "major",
98101
"location": {
99102
"path": "with space/and unicode 😃/project/folder with unicode 😃/file name with \"spaces\" and unicode 😃.php",
100103
"lines": {
@@ -105,6 +108,7 @@ public function dataFormatterOutputProvider(): iterable
105108
{
106109
"description": "Foo",
107110
"fingerprint": "e82b7e1f1d4255352b19ecefa9116a12f129c7edb4351cf2319285eccdb1565e",
111+
"severity": "major",
108112
"location": {
109113
"path": "with space/and unicode 😃/project/folder with unicode 😃/file name with \"spaces\" and unicode 😃.php",
110114
"lines": {
@@ -115,6 +119,7 @@ public function dataFormatterOutputProvider(): iterable
115119
{
116120
"description": "Foo",
117121
"fingerprint": "93c79740ed8c6fbaac2087e54d6f6f67fc0918e3ff77840530f32e19857ef63c",
122+
"severity": "major",
118123
"location": {
119124
"path": "with space/and unicode \ud83d\ude03/project/foo.php",
120125
"lines": {
@@ -125,6 +130,7 @@ public function dataFormatterOutputProvider(): iterable
125130
{
126131
"description": "Bar\nBar2",
127132
"fingerprint": "829f6c782152fdac840b39208c5b519d18e51bff2c601b6197812fffb8bcd9ed",
133+
"severity": "major",
128134
"location": {
129135
"path": "with space/and unicode \ud83d\ude03/project/foo.php",
130136
"lines": {
@@ -207,6 +213,7 @@ public function dataFormatterOutputProvider(): iterable
207213
{
208214
"description": "first generic error",
209215
"fingerprint": "53ed216d77c9a9b21d9535322457ca7d7b037d6596d76484b3481f161adfd96f",
216+
"severity": "major",
210217
"location": {
211218
"path": "",
212219
"lines": {
@@ -217,6 +224,7 @@ public function dataFormatterOutputProvider(): iterable
217224
{
218225
"description": "second generic error",
219226
"fingerprint": "f49870714e8ce889212aefb50f718f88ae63d00dd01c775b7bac86c4466e96f0",
227+
"severity": "major",
220228
"location": {
221229
"path": "",
222230
"lines": {
@@ -236,6 +244,7 @@ public function dataFormatterOutputProvider(): iterable
236244
{
237245
"description": "Bar\nBar2",
238246
"fingerprint": "034b4afbfb347494c14e396ed8327692f58be4cd27e8aff5f19f4194934db7c9",
247+
"severity": "major",
239248
"location": {
240249
"path": "with space/and unicode \ud83d\ude03/project/folder with unicode \ud83d\ude03/file name with \"spaces\" and unicode \ud83d\ude03.php",
241250
"lines": {
@@ -246,6 +255,7 @@ public function dataFormatterOutputProvider(): iterable
246255
{
247256
"description": "Foo",
248257
"fingerprint": "e82b7e1f1d4255352b19ecefa9116a12f129c7edb4351cf2319285eccdb1565e",
258+
"severity": "major",
249259
"location": {
250260
"path": "with space/and unicode \ud83d\ude03/project/folder with unicode \ud83d\ude03/file name with \"spaces\" and unicode \ud83d\ude03.php",
251261
"lines": {
@@ -256,6 +266,7 @@ public function dataFormatterOutputProvider(): iterable
256266
{
257267
"description": "Foo",
258268
"fingerprint": "93c79740ed8c6fbaac2087e54d6f6f67fc0918e3ff77840530f32e19857ef63c",
269+
"severity": "major",
259270
"location": {
260271
"path": "with space/and unicode \ud83d\ude03/project/foo.php",
261272
"lines": {
@@ -266,6 +277,7 @@ public function dataFormatterOutputProvider(): iterable
266277
{
267278
"description": "Bar\nBar2",
268279
"fingerprint": "829f6c782152fdac840b39208c5b519d18e51bff2c601b6197812fffb8bcd9ed",
280+
"severity": "major",
269281
"location": {
270282
"path": "with space/and unicode \ud83d\ude03/project/foo.php",
271283
"lines": {
@@ -276,6 +288,7 @@ public function dataFormatterOutputProvider(): iterable
276288
{
277289
"description": "first generic error",
278290
"fingerprint": "53ed216d77c9a9b21d9535322457ca7d7b037d6596d76484b3481f161adfd96f",
291+
"severity": "major",
279292
"location": {
280293
"path": "",
281294
"lines": {
@@ -286,6 +299,7 @@ public function dataFormatterOutputProvider(): iterable
286299
{
287300
"description": "second generic error",
288301
"fingerprint": "f49870714e8ce889212aefb50f718f88ae63d00dd01c775b7bac86c4466e96f0",
302+
"severity": "major",
289303
"location": {
290304
"path": "",
291305
"lines": {

0 commit comments

Comments
 (0)