2018-12-09 21:47:20 +01:00
|
|
|
<?php
|
|
|
|
namespace Psalm;
|
|
|
|
|
2019-06-26 22:52:29 +02:00
|
|
|
use function array_filter;
|
2020-02-17 00:24:40 +01:00
|
|
|
use Psalm\Internal\Analyzer\IssueData;
|
2019-06-26 22:52:29 +02:00
|
|
|
|
2019-06-09 18:37:28 +02:00
|
|
|
abstract class Report
|
2018-12-09 21:47:20 +01:00
|
|
|
{
|
2020-09-20 18:54:46 +02:00
|
|
|
public const TYPE_COMPACT = 'compact';
|
|
|
|
public const TYPE_CONSOLE = 'console';
|
|
|
|
public const TYPE_PYLINT = 'pylint';
|
|
|
|
public const TYPE_JSON = 'json';
|
|
|
|
public const TYPE_JSON_SUMMARY = 'json-summary';
|
|
|
|
public const TYPE_SONARQUBE = 'sonarqube';
|
|
|
|
public const TYPE_EMACS = 'emacs';
|
|
|
|
public const TYPE_XML = 'xml';
|
|
|
|
public const TYPE_JUNIT = 'junit';
|
|
|
|
public const TYPE_CHECKSTYLE = 'checkstyle';
|
|
|
|
public const TYPE_TEXT = 'text';
|
|
|
|
public const TYPE_GITHUB_ACTIONS = 'github';
|
|
|
|
public const TYPE_PHP_STORM = 'phpstorm';
|
2019-06-09 18:37:28 +02:00
|
|
|
|
2020-09-20 18:54:46 +02:00
|
|
|
public const SUPPORTED_OUTPUT_TYPES = [
|
2019-06-09 18:37:28 +02:00
|
|
|
self::TYPE_COMPACT,
|
|
|
|
self::TYPE_CONSOLE,
|
|
|
|
self::TYPE_PYLINT,
|
|
|
|
self::TYPE_JSON,
|
|
|
|
self::TYPE_JSON_SUMMARY,
|
2019-06-18 03:17:09 +02:00
|
|
|
self::TYPE_SONARQUBE,
|
2019-06-09 18:37:28 +02:00
|
|
|
self::TYPE_EMACS,
|
|
|
|
self::TYPE_XML,
|
2019-12-19 21:18:09 +01:00
|
|
|
self::TYPE_JUNIT,
|
2019-06-09 18:37:28 +02:00
|
|
|
self::TYPE_CHECKSTYLE,
|
|
|
|
self::TYPE_TEXT,
|
2020-01-23 13:14:48 +01:00
|
|
|
self::TYPE_GITHUB_ACTIONS,
|
2020-09-04 22:24:14 +02:00
|
|
|
self::TYPE_PHP_STORM,
|
2019-06-09 18:37:28 +02:00
|
|
|
];
|
|
|
|
|
2018-12-09 21:47:20 +01:00
|
|
|
/**
|
2020-02-17 00:24:40 +01:00
|
|
|
* @var array<int, IssueData>
|
2018-12-09 21:47:20 +01:00
|
|
|
*/
|
|
|
|
protected $issues_data;
|
|
|
|
|
2019-12-02 21:24:01 +01:00
|
|
|
/** @var array<string, int> */
|
|
|
|
protected $fixable_issue_counts;
|
|
|
|
|
2018-12-09 21:47:20 +01:00
|
|
|
/** @var bool */
|
|
|
|
protected $use_color;
|
|
|
|
|
|
|
|
/** @var bool */
|
|
|
|
protected $show_snippet;
|
|
|
|
|
|
|
|
/** @var bool */
|
|
|
|
protected $show_info;
|
|
|
|
|
2020-05-18 14:40:20 +02:00
|
|
|
/** @var bool */
|
|
|
|
protected $pretty;
|
|
|
|
|
2019-05-11 00:07:13 +02:00
|
|
|
/** @var int */
|
|
|
|
protected $mixed_expression_count;
|
|
|
|
|
|
|
|
/** @var int */
|
|
|
|
protected $total_expression_count;
|
|
|
|
|
2018-12-09 21:47:20 +01:00
|
|
|
/**
|
2020-02-17 00:24:40 +01:00
|
|
|
* @param array<int, IssueData> $issues_data
|
2019-12-02 21:24:01 +01:00
|
|
|
* @param array<string, int> $fixable_issue_counts
|
2018-12-09 21:47:20 +01:00
|
|
|
* @param bool $use_color
|
|
|
|
* @param bool $show_snippet
|
|
|
|
* @param bool $show_info
|
|
|
|
*/
|
2019-05-11 00:07:13 +02:00
|
|
|
public function __construct(
|
|
|
|
array $issues_data,
|
2019-12-02 21:24:01 +01:00
|
|
|
array $fixable_issue_counts,
|
2019-06-09 18:37:28 +02:00
|
|
|
Report\ReportOptions $report_options,
|
2019-05-11 00:07:13 +02:00
|
|
|
int $mixed_expression_count = 1,
|
|
|
|
int $total_expression_count = 1
|
|
|
|
) {
|
2019-06-13 17:06:01 +02:00
|
|
|
if (!$report_options->show_info) {
|
|
|
|
$this->issues_data = array_filter(
|
|
|
|
$issues_data,
|
2020-02-17 00:24:40 +01:00
|
|
|
function ($issue_data) : bool {
|
|
|
|
return $issue_data->severity !== Config::REPORT_INFO;
|
2019-06-13 17:06:01 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$this->issues_data = $issues_data;
|
|
|
|
}
|
2019-12-02 21:24:01 +01:00
|
|
|
$this->fixable_issue_counts = $fixable_issue_counts;
|
2019-06-13 17:06:01 +02:00
|
|
|
|
2019-06-09 18:37:28 +02:00
|
|
|
$this->use_color = $report_options->use_color;
|
|
|
|
$this->show_snippet = $report_options->show_snippet;
|
|
|
|
$this->show_info = $report_options->show_info;
|
2020-05-18 14:40:20 +02:00
|
|
|
$this->pretty = $report_options->pretty;
|
2019-06-13 17:06:01 +02:00
|
|
|
|
2019-05-11 00:07:13 +02:00
|
|
|
$this->mixed_expression_count = $mixed_expression_count;
|
|
|
|
$this->total_expression_count = $total_expression_count;
|
2018-12-09 21:47:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
abstract public function create(): string;
|
|
|
|
}
|