From 1d1bec0278a3575da00c33306f823c6d305bd0da Mon Sep 17 00:00:00 2001 From: Manuel Pichler Date: Thu, 4 Dec 2014 12:01:56 +0100 Subject: [PATCH] Closes #170: invalid xml-report after parsing traits --- src/main/php/PDepend/Report/Summary/Xml.php | 42 ++++++++++++++++----- src/site/docx/changes.xml | 3 ++ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/main/php/PDepend/Report/Summary/Xml.php b/src/main/php/PDepend/Report/Summary/Xml.php index 95ca5b0000..3322732f27 100644 --- a/src/main/php/PDepend/Report/Summary/Xml.php +++ b/src/main/php/PDepend/Report/Summary/Xml.php @@ -56,6 +56,7 @@ use PDepend\Source\AST\ASTInterface; use PDepend\Source\AST\ASTMethod; use PDepend\Source\AST\ASTNamespace; +use PDepend\Source\AST\ASTTrait; use PDepend\Source\ASTVisitor\AbstractASTVisitor; /** @@ -256,27 +257,50 @@ private function getProjectMetrics() */ public function visitClass(ASTClass $class) { - if (!$class->isUserDefined()) { + $this->generateTypeXml($class, 'class'); + } + + /** + * Visits a trait node. + * + * @param \PDepend\Source\AST\ASTTrait $trait + * @return void + */ + public function visitTrait(ASTTrait $trait) + { + $this->generateTypeXml($trait, 'trait'); + } + + /** + * Generates the XML for a class or trait node. + * + * @param \PDepend\Source\AST\ASTClass $type + * @param string $typeIdentifier + * @return void + */ + private function generateTypeXml(ASTClass $type, $typeIdentifier) + { + if (!$type->isUserDefined()) { return; } $xml = end($this->xmlStack); $doc = $xml->ownerDocument; - $classXml = $doc->createElement('class'); - $classXml->setAttribute('name', $class->getName()); + $typeXml = $doc->createElement($typeIdentifier); + $typeXml->setAttribute('name', $type->getName()); - $this->writeNodeMetrics($classXml, $class); - $this->writeFileReference($classXml, $class->getCompilationUnit()); + $this->writeNodeMetrics($typeXml, $type); + $this->writeFileReference($typeXml, $type->getCompilationUnit()); - $xml->appendChild($classXml); + $xml->appendChild($typeXml); - array_push($this->xmlStack, $classXml); + array_push($this->xmlStack, $typeXml); - foreach ($class->getMethods() as $method) { + foreach ($type->getMethods() as $method) { $method->accept($this); } - foreach ($class->getProperties() as $property) { + foreach ($type->getProperties() as $property) { $property->accept($this); } diff --git a/src/site/docx/changes.xml b/src/site/docx/changes.xml index b89a131863..31f55b10d1 100644 --- a/src/site/docx/changes.xml +++ b/src/site/docx/changes.xml @@ -30,6 +30,9 @@ Fixing parsing True/False keywords in namespaces: Usage of true and false keywords are allowed in namespace declarations in PHP. + + invalid xml-report after parsing traits + Fix Invalid argument supplied for foreach() in FileCacheDriver.php