From 11979749e42cba302e4a7faa3570ee97b3ef8942 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Wed, 6 Oct 2021 02:53:37 +0200 Subject: [PATCH 1/2] Add severity key in Phan converter Reported errors by Phan are not recognized by Gitlab Code Quality due to missing severity key in the generated Code Climate nodes. See https://docs.gitlab.com/ee/user/project/merge_requests/code_quality.html#implementing-a-custom-tool for a description of the required elements --- src/Phan/PhanConvertToSubset.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Phan/PhanConvertToSubset.php b/src/Phan/PhanConvertToSubset.php index 990a8f1..061b447 100644 --- a/src/Phan/PhanConvertToSubset.php +++ b/src/Phan/PhanConvertToSubset.php @@ -9,6 +9,12 @@ final class PhanConvertToSubset extends AbstractConverter { + private const SEVERITY_LEVELS = [ + 0 => 'info', + 5 => 'minor', + 10 => 'critical' + ]; + public function convertToSubset(): void { try { @@ -22,6 +28,7 @@ public function convertToSubset(): void $node->location->path, $node->location->lines->begin ), + 'severity' => self::SEVERITY_LEVELS[$node->severity] ?? null, 'location' => [ 'path' => $node->location->path, 'lines' => [ From 7786fbad96a546bb0aba5fc4e8c74c67d060e999 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Mon, 11 Oct 2021 20:01:58 +0200 Subject: [PATCH 2/2] Update tests with new severity key for Phan --- src/Phan/PhanConvertToSubset.php | 4 ++-- tests/Phan/PhanConverterTest.php | 1 + tests/Phan/fixtures/output.json | 1 + tests/TestCase.php | 1 + tests/fixtures/output.json | 1 + 5 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Phan/PhanConvertToSubset.php b/src/Phan/PhanConvertToSubset.php index 061b447..513a821 100644 --- a/src/Phan/PhanConvertToSubset.php +++ b/src/Phan/PhanConvertToSubset.php @@ -12,9 +12,9 @@ final class PhanConvertToSubset extends AbstractConverter private const SEVERITY_LEVELS = [ 0 => 'info', 5 => 'minor', - 10 => 'critical' + 10 => 'critical', ]; - + public function convertToSubset(): void { try { diff --git a/tests/Phan/PhanConverterTest.php b/tests/Phan/PhanConverterTest.php index 99bcfd1..b47e707 100644 --- a/tests/Phan/PhanConverterTest.php +++ b/tests/Phan/PhanConverterTest.php @@ -40,6 +40,7 @@ public function testItCanConvertPhanJsonToSubset(): void [ 'description' => '(Phan) UndefError PhanUndeclaredClassConstant Reference to constant class from undeclared class \PhpParser\Node\Stmt\ClassMethod', 'fingerprint' => 'e8547906ee21b4f8e8804de980a9d239', + 'severity' => 'critical', 'location' => [ 'path' => 'app/Class.php', 'lines' => [ diff --git a/tests/Phan/fixtures/output.json b/tests/Phan/fixtures/output.json index e0fa56a..d77e34d 100644 --- a/tests/Phan/fixtures/output.json +++ b/tests/Phan/fixtures/output.json @@ -2,6 +2,7 @@ { "description": "(Phan) UndefError PhanUndeclaredClassConstant Reference to constant class from undeclared class \\PhpParser\\Node\\Stmt\\ClassMethod", "fingerprint": "e8547906ee21b4f8e8804de980a9d239", + "severity": "critical", "location": { "path": "app/Class.php", "lines": { diff --git a/tests/TestCase.php b/tests/TestCase.php index bbc923d..2ffac58 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -34,6 +34,7 @@ public function multipleConvertersProvider(): array 'output' => [ 'description' => '(Phan) UndefError PhanUndeclaredClassConstant Reference to constant class from undeclared class \PhpParser\Node\Stmt\ClassMethod', 'fingerprint' => 'e8547906ee21b4f8e8804de980a9d239', + 'severity' => 'critical', 'location' => [ 'path' => 'app/Class.php', 'lines' => [ diff --git a/tests/fixtures/output.json b/tests/fixtures/output.json index cd85bec..12a7992 100644 --- a/tests/fixtures/output.json +++ b/tests/fixtures/output.json @@ -2,6 +2,7 @@ { "description": "(Phan) UndefError PhanUndeclaredClassConstant Reference to constant class from undeclared class \\PhpParser\\Node\\Stmt\\ClassMethod", "fingerprint": "e8547906ee21b4f8e8804de980a9d239", + "severity": "critical", "location": { "path": "app/Class.php", "lines": {