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

113 lines
3.0 KiB
PHP
Raw Normal View History

<?php
namespace Psalm;
2020-02-17 00:24:40 +01:00
use Psalm\Internal\Analyzer\IssueData;
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';
2020-09-20 18:54:46 +02:00
public const SUPPORTED_OUTPUT_TYPES = [
self::TYPE_COMPACT,
self::TYPE_CONSOLE,
self::TYPE_PYLINT,
self::TYPE_JSON,
self::TYPE_JSON_SUMMARY,
self::TYPE_SONARQUBE,
self::TYPE_EMACS,
self::TYPE_XML,
self::TYPE_JUNIT,
self::TYPE_CHECKSTYLE,
self::TYPE_TEXT,
self::TYPE_GITHUB_ACTIONS,
self::TYPE_PHP_STORM,
self::TYPE_SARIF,
self::TYPE_CODECLIMATE,
];
/**
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;
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,
Report\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,
2020-02-17 00:24:40 +01:00
function ($issue_data) : bool {
return $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;
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;
}