2018-12-09 21:47:20 +01:00
|
|
|
<?php
|
2021-12-15 04:58:32 +01:00
|
|
|
|
2018-12-09 21:47:20 +01:00
|
|
|
namespace Psalm;
|
|
|
|
|
2020-02-17 00:24:40 +01:00
|
|
|
use Psalm\Internal\Analyzer\IssueData;
|
2021-12-04 21:55:53 +01:00
|
|
|
use Psalm\Report\ReportOptions;
|
2019-06-26 22:52:29 +02:00
|
|
|
|
2021-06-08 04:55:21 +02:00
|
|
|
use function array_filter;
|
2021-09-05 19:06:59 +02:00
|
|
|
use function htmlspecialchars;
|
|
|
|
|
|
|
|
use const ENT_QUOTES;
|
|
|
|
use const ENT_XML1;
|
2021-06-08 04:55:21 +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';
|
2020-11-17 19:23:20 +01:00
|
|
|
public const TYPE_SARIF = 'sarif';
|
2020-11-23 21:34:51 +01:00
|
|
|
public const TYPE_CODECLIMATE = 'codeclimate';
|
2022-07-11 00:20:45 +02:00
|
|
|
public const TYPE_COUNT = 'count';
|
2022-12-01 23:05:27 +01:00
|
|
|
public const TYPE_BY_ISSUE_SEVERITY = 'by-issue-severity';
|
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;
|
|
|
|
|
2021-12-04 18:49:24 +01:00
|
|
|
/** @var bool */
|
|
|
|
protected $in_ci;
|
|
|
|
|
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
|
|
|
*/
|
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,
|
2021-12-04 21:55:53 +01:00
|
|
|
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,
|
2022-04-09 11:58:26 +02:00
|
|
|
static fn(IssueData $issue_data): bool => $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;
|
2021-12-04 18:49:24 +01:00
|
|
|
$this->in_ci = $report_options->in_ci;
|
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
|
|
|
}
|
|
|
|
|
2021-09-05 19:06:59 +02:00
|
|
|
protected function xmlEncode(string $data): string
|
|
|
|
{
|
2021-09-26 21:09:20 +02:00
|
|
|
return htmlspecialchars($data, ENT_XML1 | ENT_QUOTES);
|
2021-09-05 19:06:59 +02:00
|
|
|
}
|
|
|
|
|
2018-12-09 21:47:20 +01:00
|
|
|
abstract public function create(): string;
|
|
|
|
}
|