|
10 | 10 | namespace SebastianBergmann\CodeCoverage\Report\Xml;
|
11 | 11 |
|
12 | 12 | use const DIRECTORY_SEPARATOR;
|
13 |
| -use const PHP_EOL; |
14 | 13 | use function count;
|
15 | 14 | use function dirname;
|
16 | 15 | use function file_get_contents;
|
17 |
| -use function file_put_contents; |
18 | 16 | use function is_array;
|
19 | 17 | use function is_dir;
|
20 | 18 | use function is_file;
|
21 | 19 | use function is_writable;
|
22 |
| -use function libxml_clear_errors; |
23 |
| -use function libxml_get_errors; |
24 |
| -use function libxml_use_internal_errors; |
25 | 20 | use function sprintf;
|
26 | 21 | use function strlen;
|
27 | 22 | use function substr;
|
|
33 | 28 | use SebastianBergmann\CodeCoverage\Node\File;
|
34 | 29 | use SebastianBergmann\CodeCoverage\Node\File as FileNode;
|
35 | 30 | use SebastianBergmann\CodeCoverage\PathExistsButIsNotDirectoryException;
|
36 |
| -use SebastianBergmann\CodeCoverage\Util\Filesystem as DirectoryUtil; |
| 31 | +use SebastianBergmann\CodeCoverage\Util\Filesystem; |
| 32 | +use SebastianBergmann\CodeCoverage\Util\Xml; |
37 | 33 | use SebastianBergmann\CodeCoverage\Version;
|
38 | 34 | use SebastianBergmann\CodeCoverage\WriteOperationFailedException;
|
39 | 35 | use SebastianBergmann\CodeCoverage\XmlException;
|
@@ -107,7 +103,7 @@ private function initTargetDirectory(string $directory): void
|
107 | 103 | // @codeCoverageIgnoreEnd
|
108 | 104 | }
|
109 | 105 |
|
110 |
| - DirectoryUtil::createDirectory($directory); |
| 106 | + Filesystem::createDirectory($directory); |
111 | 107 | }
|
112 | 108 |
|
113 | 109 | /**
|
@@ -287,38 +283,8 @@ private function saveDocument(DOMDocument $document, string $name): void
|
287 | 283 | {
|
288 | 284 | $filename = sprintf('%s/%s.xml', $this->targetDirectory(), $name);
|
289 | 285 |
|
290 |
| - $document->formatOutput = true; |
291 |
| - $document->preserveWhiteSpace = false; |
292 | 286 | $this->initTargetDirectory(dirname($filename));
|
293 | 287 |
|
294 |
| - file_put_contents($filename, $this->documentAsString($document)); |
295 |
| - } |
296 |
| - |
297 |
| - /** |
298 |
| - * @throws XmlException |
299 |
| - * |
300 |
| - * @see https://bugs.php.net/bug.php?id=79191 |
301 |
| - */ |
302 |
| - private function documentAsString(DOMDocument $document): string |
303 |
| - { |
304 |
| - $xmlErrorHandling = libxml_use_internal_errors(true); |
305 |
| - $xml = $document->saveXML(); |
306 |
| - |
307 |
| - if ($xml === false) { |
308 |
| - // @codeCoverageIgnoreStart |
309 |
| - $message = 'Unable to generate the XML'; |
310 |
| - |
311 |
| - foreach (libxml_get_errors() as $error) { |
312 |
| - $message .= PHP_EOL . $error->message; |
313 |
| - } |
314 |
| - |
315 |
| - throw new XmlException($message); |
316 |
| - // @codeCoverageIgnoreEnd |
317 |
| - } |
318 |
| - |
319 |
| - libxml_clear_errors(); |
320 |
| - libxml_use_internal_errors($xmlErrorHandling); |
321 |
| - |
322 |
| - return $xml; |
| 288 | + Filesystem::write($filename, Xml::asString($document)); |
323 | 289 | }
|
324 | 290 | }
|
0 commit comments