@@ -52,16 +52,13 @@ public function process(CodeCoverage $coverage, $target)
5252 $ this ->processTests ($ coverage ->getTests ());
5353 $ this ->processDirectory ($ report , $ this ->project );
5454
55- $ index = $ this ->project ->asDom ();
56- $ index ->formatOutput = true ;
57- $ index ->preserveWhiteSpace = false ;
58- $ index ->save ($ target . '/index.xml ' );
55+ $ this ->saveDocument ($ this ->project ->asDom (), 'index ' );
5956 }
6057
6158 /**
6259 * @param string $directory
6360 */
64- private function initTargetDirectory ($ directory )
61+ protected function initTargetDirectory ($ directory )
6562 {
6663 if (file_exists ($ directory )) {
6764 if (!is_dir ($ directory )) {
@@ -101,7 +98,7 @@ private function processFile(FileNode $file, Directory $context)
10198 {
10299 $ fileObject = $ context ->addFile (
103100 $ file ->getName (),
104- $ file ->getId () . '.xml '
101+ $ file ->getId (). '.xml '
105102 );
106103
107104 $ this ->setTotals ($ file , $ fileObject ->getTotals ());
@@ -132,14 +129,7 @@ private function processFile(FileNode $file, Directory $context)
132129 $ coverage ->finalize ();
133130 }
134131
135- $ this ->initTargetDirectory (
136- $ this ->target . dirname ($ file ->getId ()) . '/ '
137- );
138-
139- $ fileDom = $ fileReport ->asDom ();
140- $ fileDom ->formatOutput = true ;
141- $ fileDom ->preserveWhiteSpace = false ;
142- $ fileDom ->save ($ this ->target . $ file ->getId () . '.xml ' );
132+ $ this ->saveDocument ($ fileReport ->asDom (), $ file ->getId ());
143133 }
144134
145135 private function processUnit ($ unit , Report $ report )
@@ -235,4 +225,23 @@ private function setTotals(AbstractNode $node, Totals $totals)
235225 $ node ->getNumTestedFunctions ()
236226 );
237227 }
228+
229+ /**
230+ * @return string
231+ */
232+ protected function getTargetDirectory ()
233+ {
234+ return $ this ->target ;
235+ }
236+
237+ protected function saveDocument (\DOMDocument $ document , $ name )
238+ {
239+ $ filename = sprintf ('%s/%s.xml ' , $ this ->getTargetDirectory (), $ name );
240+
241+ $ document ->formatOutput = true ;
242+ $ document ->preserveWhiteSpace = false ;
243+ $ this ->initTargetDirectory (dirname ($ filename ));
244+
245+ $ document ->save ($ filename );
246+ }
238247}
0 commit comments