forked from vimeo/psalm
/
XmlReport.php
58 lines (48 loc) · 1.9 KB
/
XmlReport.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace Psalm\Report;
use Psalm\Internal\Analyzer\DataFlowNodeData;
use Psalm\Internal\Analyzer\IssueData;
use Psalm\Report;
use Spatie\ArrayToXml\ArrayToXml;
use function array_map;
use function get_object_vars;
final class XmlReport extends Report
{
public function create(): string
{
$xml = (string) ArrayToXml::convert(
[
'item' => array_map(
static function (IssueData $issue_data): array {
$issue_data = get_object_vars($issue_data);
unset($issue_data['dupe_key']);
if (null !== $issue_data['taint_trace']) {
$issue_data['taint_trace'] = array_map(
static fn($trace): array => (array) $trace,
$issue_data['taint_trace']
);
}
// replace null values, as XML serializers tend to have problems with them
$issue_data['taint_trace'] ??= '';
if (null !== $issue_data['other_references']) {
$issue_data['other_references'] = array_map(
static fn(DataFlowNodeData $reference): array => (array) $reference,
$issue_data['other_references']
);
}
// replace null values, as XML serializers tend to have problems with them
$issue_data['other_references'] ??= '';
return $issue_data;
},
$this->issues_data
)
],
'report',
true,
'UTF-8',
'1.0',
['preserveWhiteSpace' => false, 'formatOutput' => true]
);
return $xml;
}
}