aboutsummaryrefslogtreecommitdiff
path: root/.gitlab/scripts/convert-phplint-report
blob: b306b2628d5312c067d56b270231478cf4567c99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env php
<?php
function error(string $error, int $status = 1): void
{
    echo trim($error) . "\n";
    exit($status);
}

$self = basename($argv[0]);

if ($argc !== 2) {
    error("Missing report file, use {$self} <filename>");
}

$report_file = $argv[1];
if (!file_exists($report_file)) {
    error("Report file {$report_file} does not exist");
}
if (!is_readable($report_file)) {
    error("Report file {$report_file} is not readable");
}

$json = json_decode(file_get_contents($report_file), true);
if ($json === false) {
    error("Could not read json contents of {$report_file}");
}

$errors = [];
foreach ($json['errors'] as $error) {
    $errors[] = [
        'description' => $error['error'],
        'fingerprint' => md5("{$error['file_name']}:{$error['line']}"),
        'severity' => 'major',
        'location' => [
            'path' => $error['file_name'],
            'lines' => [
                'begin' => $error['line'],
            ],
        ],
    ];
}

echo json_encode($errors);