-
Notifications
You must be signed in to change notification settings - Fork 653
/
GithubActionsReport.php
71 lines (63 loc) · 1.85 KB
/
GithubActionsReport.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
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace Psalm\Report;
use Psalm\Config;
use Psalm\Report;
use function sprintf;
use function strtr;
class GithubActionsReport extends Report
{
public function create(): string
{
$output = '';
foreach ($this->issues_data as $issue_data) {
$issue_reference = $issue_data->link ? ' (see ' . $issue_data->link . ')' : '';
$properties = sprintf(
'file=%1$s,line=%2$d,col=%3$d,title=%4$s',
$this->escapeProperty($issue_data->file_name),
$this->escapeProperty($issue_data->line_from),
$this->escapeProperty($issue_data->column_from),
$this->escapeProperty($issue_data->type)
);
$data = $this->escapeData(sprintf(
'%1$s:%2$d:%3$d: %4$s: %5$s',
$issue_data->file_name,
$issue_data->line_from,
$issue_data->column_from,
$issue_data->type,
$issue_data->message . $issue_reference
));
$output .= sprintf(
'::%1$s %2$s::%3$s',
($issue_data->severity === Config::REPORT_ERROR ? 'error' : 'warning'),
$properties,
$data
) . "\n";
}
return $output;
}
private function escapeData(string $data): string
{
return strtr(
$data,
[
'%' => '%25',
"\r" => '%0D',
"\n" => '%0A',
]
);
}
/** @param mixed $value */
private function escapeProperty($value): string
{
return strtr(
(string) $value,
[
'%' => '%25',
"\r" => '%0D',
"\n" => '%0A',
':' => '%3A',
',' => '%2C',
]
);
}
}