@@ -124,7 +124,9 @@ private function processDirectory(DirectoryNode $directory, Node $context): void
124124 $ directoryName = '/ ' ;
125125 }
126126
127- $ directoryObject = $ context ->addDirectory ($ directoryName );
127+ $ this ->xmlWriter ->startElement ('directory ' );
128+ $ this ->xmlWriter ->writeAttribute ('name ' , $ directoryName );
129+ $ directoryObject = $ context ->addDirectory ();
128130
129131 $ this ->setTotals ($ directory , $ directoryObject ->totals ());
130132
@@ -135,17 +137,19 @@ private function processDirectory(DirectoryNode $directory, Node $context): void
135137 foreach ($ directory ->files () as $ node ) {
136138 $ this ->processFile ($ node , $ directoryObject );
137139 }
140+ $ this ->xmlWriter ->endElement ();
138141 }
139142
140143 /**
141144 * @throws XmlException
142145 */
143146 private function processFile (FileNode $ file , Directory $ context ): void
144147 {
145- $ fileObject = $ context ->addFile (
146- $ file ->name (),
147- $ file ->id () . '.xml ' ,
148- );
148+ $ this ->xmlWriter ->startElement ('file ' );
149+ $ this ->xmlWriter ->writeAttribute ('name ' , $ file ->name ());
150+ $ this ->xmlWriter ->writeAttribute ('href ' , $ file ->id () . '.xml ' );
151+
152+ $ fileObject = $ context ->addFile ();
149153
150154 $ this ->setTotals ($ file , $ fileObject ->totals ());
151155
@@ -154,7 +158,7 @@ private function processFile(FileNode $file, Directory $context): void
154158 strlen ($ this ->project ->projectSourceDirectory ()),
155159 );
156160
157- $ fileReport = new Report ($ path );
161+ $ fileReport = new Report ($ this -> xmlWriter , $ path );
158162
159163 $ this ->setTotals ($ file , $ fileReport ->totals ());
160164
@@ -177,16 +181,21 @@ private function processFile(FileNode $file, Directory $context): void
177181 }
178182 $ this ->xmlWriter ->endElement ();
179183
184+ $ this ->xmlWriter ->endElement ();
185+
180186 $ fileReport ->source ()->setSourceCode (
181187 file_get_contents ($ file ->pathAsString ()),
182188 );
189+ $ fileReport ->finalize ();
183190
184191 $ this ->saveDocument ($ fileReport ->asDom (), $ file ->id ());
185192 }
186193
187194 private function processUnit (ProcessedClassType |ProcessedTraitType $ unit , Report $ report ): void
188195 {
189196 if ($ unit instanceof ProcessedClassType) {
197+ $ this ->xmlWriter ->startElement ('class ' );
198+
190199 $ unitObject = $ report ->classObject (
191200 $ unit ->className ,
192201 $ unit ->namespace ,
@@ -196,6 +205,8 @@ private function processUnit(ProcessedClassType|ProcessedTraitType $unit, Report
196205 (float ) $ unit ->crap ,
197206 );
198207 } else {
208+ $ this ->xmlWriter ->startElement ('trait ' );
209+
199210 $ unitObject = $ report ->traitObject (
200211 $ unit ->traitName ,
201212 $ unit ->namespace ,
@@ -218,6 +229,8 @@ private function processUnit(ProcessedClassType|ProcessedTraitType $unit, Report
218229 $ method ->crap ,
219230 );
220231 }
232+
233+ $ this ->xmlWriter ->endElement ();
221234 }
222235
223236 private function processFunction (ProcessedFunctionType $ function , Report $ report ): void
0 commit comments