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
|
|
|
|
2019-07-05 22:24:00 +02:00
|
|
|
use function count;
|
|
|
|
use function implode;
|
|
|
|
use function is_null;
|
2018-12-09 21:47:20 +01:00
|
|
|
use Psalm\Config;
|
2019-06-09 18:37:28 +02:00
|
|
|
use Psalm\Report;
|
2019-07-05 22:24:00 +02:00
|
|
|
use function str_split;
|
|
|
|
use function strlen;
|
|
|
|
use function strtoupper;
|
2018-12-09 21:47:20 +01:00
|
|
|
use Symfony\Component\Console\Helper\Table;
|
|
|
|
use Symfony\Component\Console\Output\BufferedOutput;
|
|
|
|
|
2019-06-09 18:37:28 +02:00
|
|
|
class CompactReport 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
|
|
|
* @psalm-suppress PossiblyNullReference
|
|
|
|
*/
|
|
|
|
public function create(): string
|
|
|
|
{
|
|
|
|
/** @var BufferedOutput|null $buffer */
|
|
|
|
$buffer = null;
|
|
|
|
|
|
|
|
/** @var Table|null $table */
|
|
|
|
$table = null;
|
|
|
|
|
|
|
|
/** @var string|null $current_file */
|
|
|
|
$current_file = null;
|
|
|
|
|
|
|
|
$output = [];
|
|
|
|
foreach ($this->issues_data as $i => $issue_data) {
|
|
|
|
if (!$this->show_info && $issue_data['severity'] === Config::REPORT_INFO) {
|
|
|
|
continue;
|
|
|
|
} elseif (is_null($current_file) || $current_file !== $issue_data['file_name']) {
|
|
|
|
// If we're processing a new file, then wrap up the last table and render it out.
|
|
|
|
if ($buffer !== null) {
|
|
|
|
$table->render();
|
|
|
|
$output[] = $buffer->fetch();
|
|
|
|
}
|
|
|
|
|
2019-07-03 22:58:27 +02:00
|
|
|
$output[] = 'FILE: ' . $issue_data['file_name'] . "\n";
|
2018-12-09 21:47:20 +01:00
|
|
|
|
|
|
|
$buffer = new BufferedOutput();
|
|
|
|
$table = new Table($buffer);
|
|
|
|
$table->setHeaders(['SEVERITY', 'LINE', 'ISSUE', 'DESCRIPTION']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$is_error = $issue_data['severity'] === Config::REPORT_ERROR;
|
|
|
|
if ($is_error) {
|
|
|
|
$severity = ($this->use_color ? "\e[0;31mERROR\e[0m" : 'ERROR');
|
|
|
|
} else {
|
|
|
|
$severity = strtoupper($issue_data['severity']);
|
|
|
|
}
|
|
|
|
|
2018-12-09 22:35:01 +01:00
|
|
|
// Since `Table::setColumnMaxWidth` is only available in symfony/console 4.2+ we need do something similar
|
|
|
|
// so we have clean tables.
|
|
|
|
$message = $issue_data['message'];
|
|
|
|
if (strlen($message) > 70) {
|
2019-07-03 22:58:27 +02:00
|
|
|
$message = implode("\n", str_split($message, 70));
|
2018-12-09 22:35:01 +01:00
|
|
|
}
|
|
|
|
|
2018-12-09 21:47:20 +01:00
|
|
|
$table->addRow([
|
|
|
|
$severity,
|
|
|
|
$issue_data['line_from'],
|
|
|
|
$issue_data['type'],
|
2019-07-05 22:24:00 +02:00
|
|
|
$message,
|
2018-12-09 21:47:20 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
$current_file = $issue_data['file_name'];
|
|
|
|
|
|
|
|
// If we're at the end of the issue sets, then wrap up the last table and render it out.
|
|
|
|
if ($i === count($this->issues_data) - 1) {
|
|
|
|
$table->render();
|
|
|
|
$output[] = $buffer->fetch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-03 22:58:27 +02:00
|
|
|
return implode("\n", $output);
|
2018-12-09 21:47:20 +01:00
|
|
|
}
|
|
|
|
}
|