Skip to content

Commit 1d1bec0

Browse files
author
Manuel Pichler
committed
Closes #170: invalid xml-report after parsing traits
1 parent 1d9d0e1 commit 1d1bec0

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

src/main/php/PDepend/Report/Summary/Xml.php

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
use PDepend\Source\AST\ASTInterface;
5757
use PDepend\Source\AST\ASTMethod;
5858
use PDepend\Source\AST\ASTNamespace;
59+
use PDepend\Source\AST\ASTTrait;
5960
use PDepend\Source\ASTVisitor\AbstractASTVisitor;
6061

6162
/**
@@ -256,27 +257,50 @@ private function getProjectMetrics()
256257
*/
257258
public function visitClass(ASTClass $class)
258259
{
259-
if (!$class->isUserDefined()) {
260+
$this->generateTypeXml($class, 'class');
261+
}
262+
263+
/**
264+
* Visits a trait node.
265+
*
266+
* @param \PDepend\Source\AST\ASTTrait $trait
267+
* @return void
268+
*/
269+
public function visitTrait(ASTTrait $trait)
270+
{
271+
$this->generateTypeXml($trait, 'trait');
272+
}
273+
274+
/**
275+
* Generates the XML for a class or trait node.
276+
*
277+
* @param \PDepend\Source\AST\ASTClass $type
278+
* @param string $typeIdentifier
279+
* @return void
280+
*/
281+
private function generateTypeXml(ASTClass $type, $typeIdentifier)
282+
{
283+
if (!$type->isUserDefined()) {
260284
return;
261285
}
262286

263287
$xml = end($this->xmlStack);
264288
$doc = $xml->ownerDocument;
265289

266-
$classXml = $doc->createElement('class');
267-
$classXml->setAttribute('name', $class->getName());
290+
$typeXml = $doc->createElement($typeIdentifier);
291+
$typeXml->setAttribute('name', $type->getName());
268292

269-
$this->writeNodeMetrics($classXml, $class);
270-
$this->writeFileReference($classXml, $class->getCompilationUnit());
293+
$this->writeNodeMetrics($typeXml, $type);
294+
$this->writeFileReference($typeXml, $type->getCompilationUnit());
271295

272-
$xml->appendChild($classXml);
296+
$xml->appendChild($typeXml);
273297

274-
array_push($this->xmlStack, $classXml);
298+
array_push($this->xmlStack, $typeXml);
275299

276-
foreach ($class->getMethods() as $method) {
300+
foreach ($type->getMethods() as $method) {
277301
$method->accept($this);
278302
}
279-
foreach ($class->getProperties() as $property) {
303+
foreach ($type->getProperties() as $property) {
280304
$property->accept($this);
281305
}
282306

src/site/docx/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
<action date="d96e4e7" dev="renan" type="fix" issue="173" system="github">
3131
Fixing parsing True/False keywords in namespaces: Usage of true and false keywords are allowed in namespace declarations in PHP.
3232
</action>
33+
<action date="" dev="manuelpichler" due-to="pupsschluepfer" type="fix" issue="170" system="github">
34+
invalid xml-report after parsing traits
35+
</action>
3336
<action date="73d32f3" dev="Deltachaos" type="fix" issue="167" system="github">
3437
Fix Invalid argument supplied for foreach() in FileCacheDriver.php
3538
</action>

0 commit comments

Comments
 (0)