1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-15 10:57:08 +01:00
psalm/src/Psalm/Report/PylintReport.php
Matthew Brown da42be175f Apply PHPCS fixes
Fixes #1880
2019-07-05 16:27:53 -04:00

59 lines
1.5 KiB
PHP

<?php
namespace Psalm\Report;
use Psalm\Config;
use Psalm\Report;
use function sprintf;
class PylintReport extends Report
{
/**
* {@inheritdoc}
*/
public function create(): string
{
$output = '';
foreach ($this->issues_data as $issue_data) {
$output .= $this->format($issue_data) . "\n";
}
return $output;
}
/**
* @param array{severity: string, line_from: int, line_to: int, type: string, message: string,
* file_name: string, file_path: string, snippet: string, from: int, to: int,
* snippet_from: int, snippet_to: int, column_from: int, column_to: int} $issue_data
*
* @return string
*/
private function format(array $issue_data): string
{
$message = sprintf(
'%s: %s',
$issue_data['type'],
$issue_data['message']
);
if ($issue_data['severity'] === Config::REPORT_ERROR) {
$code = 'E0001';
} else {
$code = 'W0001';
}
// https://docs.pylint.org/en/1.6.0/output.html doesn't mention what to do about 'column',
// but it's still useful for users.
// E.g. jenkins can't parse %s:%d:%d.
$message = sprintf('%s (column %d)', $message, $issue_data['column_from']);
$issue_string = sprintf(
'%s:%d: [%s] %s',
$issue_data['file_name'],
$issue_data['line_from'],
$code,
$message
);
return $issue_string;
}
}