1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-12 17:27:28 +01:00
psalm/src/Psalm/Report.php

101 lines
2.7 KiB
PHP
Raw Normal View History

<?php
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;
2021-06-08 04:55:21 +02:00
use function array_filter;
use function htmlspecialchars;
use const ENT_QUOTES;
use const ENT_XML1;
2021-06-08 04:55:21 +02:00
abstract class Report
{
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';
public const TYPE_SARIF = 'sarif';
public const TYPE_CODECLIMATE = 'codeclimate';
2022-07-11 00:20:45 +02:00
public const TYPE_COUNT = 'count';
public const TYPE_BY_ISSUE_LEVEL = 'by-issue-level';
/**
2020-02-17 00:24:40 +01:00
* @var array<int, IssueData>
*/
protected $issues_data;
/** @var array<string, int> */
protected $fixable_issue_counts;
/** @var bool */
protected $use_color;
/** @var bool */
protected $show_snippet;
/** @var bool */
protected $show_info;
/** @var bool */
protected $pretty;
/** @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;
/**
2020-02-17 00:24:40 +01:00
* @param array<int, IssueData> $issues_data
* @param array<string, int> $fixable_issue_counts
*/
2019-05-11 00:07:13 +02:00
public function __construct(
array $issues_data,
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
) {
if (!$report_options->show_info) {
$this->issues_data = array_filter(
$issues_data,
static fn(IssueData $issue_data): bool => $issue_data->severity !== Config::REPORT_INFO
);
} else {
$this->issues_data = $issues_data;
}
$this->fixable_issue_counts = $fixable_issue_counts;
$this->use_color = $report_options->use_color;
$this->show_snippet = $report_options->show_snippet;
$this->show_info = $report_options->show_info;
$this->pretty = $report_options->pretty;
$this->in_ci = $report_options->in_ci;
2019-05-11 00:07:13 +02:00
$this->mixed_expression_count = $mixed_expression_count;
$this->total_expression_count = $total_expression_count;
}
protected function xmlEncode(string $data): string
{
2021-09-26 21:09:20 +02:00
return htmlspecialchars($data, ENT_XML1 | ENT_QUOTES);
}
abstract public function create(): string;
}