1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-12 09:19:40 +01:00
psalm/src/Psalm/Report/CheckstyleReport.php
Bruce Weirdan abf557da44
Encode XML output consistently
This fixes test failures when running on PHP 8.1, due to changed
`htmlspecialchars()` defaults
2021-09-05 20:06:59 +03:00

39 lines
1.0 KiB
PHP

<?php
namespace Psalm\Report;
use Psalm\Report;
use function sprintf;
class CheckstyleReport extends Report
{
public function create(): string
{
$output = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
$output .= '<checkstyle>' . "\n";
foreach ($this->issues_data as $issue_data) {
$message = sprintf(
'%s: %s',
$issue_data->type,
$issue_data->message
);
$output .= '<file name="' . $this->xmlEncode($issue_data->file_name) . '">' . "\n";
$output .= ' ';
$output .= '<error';
$output .= ' line="' . $issue_data->line_from . '"';
$output .= ' column="' . $issue_data->column_from . '"';
$output .= ' severity="' . $issue_data->severity . '"';
$output .= ' message="' . $this->xmlEncode($message) . '"';
$output .= '/>' . "\n";
$output .= '</file>' . "\n";
}
$output .= '</checkstyle>' . "\n";
return $output;
}
}