Skip to content

Commit 814a292

Browse files
committed
simplify
1 parent c7e45f1 commit 814a292

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/Report/Xml/Coverage.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
namespace SebastianBergmann\CodeCoverage\Report\Xml;
1111

1212
use DOMElement;
13-
use SebastianBergmann\CodeCoverage\ReportAlreadyFinalizedException;
1413
use XMLWriter;
1514

1615
/**
@@ -19,6 +18,7 @@
1918
final class Coverage
2019
{
2120
private readonly DOMElement $contextNode;
21+
private bool $finalized = false;
2222
private readonly string $line;
2323

2424
public function __construct(DOMElement $context, string $line)
@@ -29,14 +29,20 @@ public function __construct(DOMElement $context, string $line)
2929

3030
public function finalize(array $tests): void
3131
{
32-
$xml = '<line nr="'. $this->line .'">';
32+
$writer = new XMLWriter;
33+
$writer->openMemory();
34+
$writer->startElementNs(null, $this->contextNode->nodeName, 'https://schema.phpunit.de/coverage/1.0');
35+
$writer->writeAttribute('nr', $this->line);
36+
3337
foreach ($tests as $test) {
34-
$xml .= '<covered by="'. htmlspecialchars($test, ENT_QUOTES | ENT_XML1) .'" />';
38+
$writer->startElement('covered');
39+
$writer->writeAttribute('by', $test);
40+
$writer->endElement();
3541
}
36-
$xml .= '</line>';
42+
$writer->endElement();
3743

3844
$fragment = $this->contextNode->ownerDocument->createDocumentFragment();
39-
$fragment->appendXML($xml);
45+
$fragment->appendXML($writer->outputMemory());
4046

4147
$this->contextNode->parentNode->replaceChild(
4248
$fragment,

0 commit comments

Comments
 (0)