2018-12-09 21:47:20 +01:00
|
|
|
<?php
|
2019-06-09 18:37:28 +02:00
|
|
|
namespace Psalm\Report;
|
2018-12-09 21:47:20 +01:00
|
|
|
|
|
|
|
use Psalm\Config;
|
2019-06-09 18:37:28 +02:00
|
|
|
use Psalm\Report;
|
2019-06-26 22:52:29 +02:00
|
|
|
use function substr;
|
2018-12-09 21:47:20 +01:00
|
|
|
|
2019-06-09 18:37:28 +02:00
|
|
|
class ConsoleReport extends Report
|
2018-12-09 21:47:20 +01:00
|
|
|
{
|
|
|
|
/**
|
2019-07-05 22:24:00 +02:00
|
|
|
* {@inheritdoc}
|
2018-12-09 21:47:20 +01:00
|
|
|
*/
|
|
|
|
public function create(): string
|
|
|
|
{
|
|
|
|
$output = '';
|
|
|
|
foreach ($this->issues_data as $issue_data) {
|
|
|
|
$output .= $this->format($issue_data) . "\n" . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2020-02-17 00:24:40 +01:00
|
|
|
private function format(\Psalm\Internal\Analyzer\IssueData $issue_data): string
|
2018-12-09 21:47:20 +01:00
|
|
|
{
|
|
|
|
$issue_string = '';
|
|
|
|
|
2020-02-17 00:24:40 +01:00
|
|
|
$is_error = $issue_data->severity === Config::REPORT_ERROR;
|
2018-12-09 21:47:20 +01:00
|
|
|
|
|
|
|
if ($is_error) {
|
|
|
|
$issue_string .= ($this->use_color ? "\e[0;31mERROR\e[0m" : 'ERROR');
|
|
|
|
} else {
|
|
|
|
$issue_string .= 'INFO';
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:04:35 +01:00
|
|
|
$issue_reference = ' (see ' . $issue_data->getLink() . ')';
|
|
|
|
|
|
|
|
$issue_string .= ': ' . $issue_data->type
|
|
|
|
. ' - ' . $issue_data->file_name . ':' . $issue_data->line_from . ':' . $issue_data->column_from
|
|
|
|
. ' - ' . $issue_data->message . $issue_reference . "\n";
|
2018-12-09 21:47:20 +01:00
|
|
|
|
|
|
|
if ($this->show_snippet) {
|
2020-02-17 00:24:40 +01:00
|
|
|
$snippet = $issue_data->snippet;
|
2018-12-09 21:47:20 +01:00
|
|
|
|
|
|
|
if (!$this->use_color) {
|
|
|
|
$issue_string .= $snippet;
|
|
|
|
} else {
|
2020-02-17 00:24:40 +01:00
|
|
|
$selection_start = $issue_data->from - $issue_data->snippet_from;
|
|
|
|
$selection_length = $issue_data->to - $issue_data->from;
|
2018-12-09 21:47:20 +01:00
|
|
|
|
|
|
|
$issue_string .= substr($snippet, 0, $selection_start)
|
|
|
|
. ($is_error ? "\e[97;41m" : "\e[30;47m") . substr($snippet, $selection_start, $selection_length)
|
|
|
|
. "\e[0m" . substr($snippet, $selection_length + $selection_start) . "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $issue_string;
|
|
|
|
}
|
|
|
|
}
|