forked from phan/phan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtocheckstyle
executable file
·51 lines (41 loc) · 1.25 KB
/
tocheckstyle
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
#!/usr/bin/env php
<?php
$files = [];
while($line = trim(fgets(STDIN))) {
$elements = explode(' ', $line, 3);
list($file, $line) = explode(':', $elements[0]);
$source = $elements[1];
$message = $elements[2];
if (empty($files[$file])) {
$files[$file] = [];
}
$files[$file][] = [
'line' => $line,
'source' => $source,
'message' => $message,
'severity' => 'error',
];
}
$document = new \DomDocument('1.0', 'ISO-8859-15');
$checkstyle = new \DOMElement('checkstyle');
$document->appendChild($checkstyle);
$checkstyle->appendChild(new \DOMAttr('version', '6.5'));
// Write each file to the DOM
foreach ($files as $file_name => $error_list) {
$file = new \DOMElement('file');
$checkstyle->appendChild($file);
$file->appendChild(new \DOMAttr('name', $file_name));
// Write each error to the file
foreach ($error_list as $error_map) {
$error = new \DOMElement('error');
$file->appendChild($error);
// Write each element of the error as an attribute
// of the error
foreach ($error_map as $key => $value) {
$error->appendChild(
new \DOMAttr($key, (string)$value)
);
}
}
}
print $document->saveXML();