Skip to content

Instantly share code, notes, and snippets.

@jaymecd
Forked from YarekTyshchenko/clover-merge.php
Created August 30, 2016 18:57
Show Gist options
  • Save jaymecd/dd9fae0ae0a3eff1b3362445580ba28a to your computer and use it in GitHub Desktop.
Save jaymecd/dd9fae0ae0a3eff1b3362445580ba28a to your computer and use it in GitHub Desktop.
Clover XML Merger
<?php
$options = getopt("f:o:");
if (! isset($options['f'])) {
echo "Files have to be specified with -f\n";
exit(1);
}
if (! isset($options['o'])) {
echo "Output has to be specified with -o\n";
exit(1);
}
$files = $options['f'];
if (! is_array($files)) {
$files = array($files);
}
$output = $options['o'];
$buffer = '';
foreach ($files as $file) {
if (! file_exists($file)) {
echo "File '$file' doesn't exist\n";
exit(2);
}
$report = simplexml_load_file($file);
$buffer .= $report->project->asXML();
}
$fh = fopen($output ,'w');
if (! $fh) {
echo "Cannot open '$output' for writing\n";
exit(2);
}
fwrite($fh, sprintf('<?xml version="1.0" encoding="UTF-8"?><coverage>%s</coverage>', $buffer));
fclose($fh);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment