99 */
1010namespace SebastianBergmann \CodeCoverage \Report \Xml ;
1111
12+ use XMLWriter ;
1213use function assert ;
1314use DOMElement ;
1415
1718 */
1819final readonly class Unit
1920{
20- private DOMElement $ contextNode ;
21+ private XMLWriter $ xmlWriter ;
2122
2223 public function __construct (
23- DOMElement $ context ,
24+ XMLWriter $ xmlWriter ,
2425 string $ name ,
2526 string $ namespace ,
2627 int $ start ,
2728 int $ executable ,
2829 int $ executed ,
2930 float $ crap
3031 ) {
31- $ this ->contextNode = $ context ;
32+ $ this ->xmlWriter = $ xmlWriter ;
3233
33- $ this ->contextNode -> setAttribute ('name ' , $ name );
34- $ this ->contextNode -> setAttribute ('start ' , (string ) $ start );
35- $ this ->contextNode -> setAttribute ('executable ' , (string ) $ executable );
36- $ this ->contextNode -> setAttribute ('executed ' , (string ) $ executed );
37- $ this ->contextNode -> setAttribute ('crap ' , (string ) $ crap );
34+ $ this ->xmlWriter -> writeAttribute ('name ' , $ name );
35+ $ this ->xmlWriter -> writeAttribute ('start ' , (string ) $ start );
36+ $ this ->xmlWriter -> writeAttribute ('executable ' , (string ) $ executable );
37+ $ this ->xmlWriter -> writeAttribute ('executed ' , (string ) $ executed );
38+ $ this ->xmlWriter -> writeAttribute ('crap ' , (string ) $ crap );
3839
39- $ node = $ this ->contextNode ->appendChild (
40- $ this ->contextNode ->ownerDocument ->createElementNS (
41- Facade::XML_NAMESPACE ,
42- 'namespace ' ,
43- ),
44- );
45- assert ($ node instanceof DOMElement);
46-
47- $ node ->setAttribute ('name ' , $ namespace );
40+ $ this ->xmlWriter ->startElement ('namespace ' );
41+ $ this ->xmlWriter ->writeAttribute ('name ' , $ namespace );
42+ $ this ->xmlWriter ->endElement ();
4843 }
4944
5045 public function addMethod (
@@ -57,17 +52,8 @@ public function addMethod(
5752 string $ coverage ,
5853 string $ crap
5954 ): void {
60- $ node = $ this ->contextNode ->appendChild (
61- $ this ->contextNode ->ownerDocument ->createElementNS (
62- Facade::XML_NAMESPACE ,
63- 'method ' ,
64- ),
65- );
66-
67- assert ($ node instanceof DOMElement);
68-
6955 new Method (
70- $ node ,
56+ $ this -> xmlWriter ,
7157 $ name ,
7258 $ signature ,
7359 $ start ,
0 commit comments