1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-05 12:38:35 +01:00
psalm/src/Psalm/Report/SonarqubeReport.php

47 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace Psalm\Report;
2019-07-05 22:24:00 +02:00
use function json_encode;
use function max;
use Psalm\Config;
use Psalm\Report;
/**
* JSON report format suitable for import into SonarQube or SonarCloud as
* generic (external) issue data via `sonar.externalIssuesReportPaths`.
*
* https://docs.sonarqube.org/latest/analysis/generic-issue/
*/
class SonarqubeReport extends Report
{
/**
2019-07-05 22:24:00 +02:00
* {@inheritdoc}
*/
public function create(): string
{
$report = ['issues' => []];
foreach ($this->issues_data as $issue_data) {
$report['issues'][] = [
'engineId' => 'Psalm',
'ruleId' => $issue_data['type'],
'primaryLocation' => [
'message' => $issue_data['message'],
'filePath' => $issue_data['file_name'],
'textRange' => [
'startLine' => $issue_data['line_from'],
'endLine' => $issue_data['line_to'],
// Columns in external issue reports are indexed from 0
'startColumn' => max(0, $issue_data['column_from'] - 1),
'endColumn' => max(0, $issue_data['column_to'] - 1),
],
],
'type' => 'CODE_SMELL',
'severity' => $issue_data['severity'] == Config::REPORT_ERROR ? 'CRITICAL' : 'MINOR',
];
}
return json_encode($report) . "\n";
}
}