Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5946306
tocheckstyle
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
tocheckstyle
View Options
#!/usr/bin/env php
<?php
$options
=
getopt
(
'h'
,
[
'help'
,
'output-format:'
]);
if
(
isset
(
$options
[
'h'
])
||
isset
(
$options
[
'help'
]))
{
fwrite
(
STDERR
,
<<<EOT
Usage: {$argv[0]} [--output-format=checkstyle-escapedhtml]
Reads Phan's regular output format on stdin and outputs a checkstyle file on stdout.
By default, errors in the XML are the plaintext of the issue, but those can be html escaped again by passing --output-format=checkstyle-escapedhtml.
EOT
);
exit
(
0
);
}
$escape_html
=
false
;
if
(
array_key_exists
(
'output-format'
,
$options
)
&&
$options
[
'output-format'
]
===
'checkstyle-escapedhtml'
)
{
$escape_html
=
true
;
}
$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
)
{
$string_value
=
$escape_html
?
htmlspecialchars
((
string
)
$value
,
ENT_NOQUOTES
,
'UTF-8'
)
:
(
string
)
$value
;
$error
->
appendChild
(
new
\DOMAttr
(
$key
,
$string_value
)
);
}
}
}
print
$document
->
saveXML
();
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Oct 2 2026, 19:32 (5 w, 5 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
9f/82/7475f4a2d440c4b2093272e6d120
Default Alt Text
tocheckstyle (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment