Skip to content

Commit

Permalink
Closes #170: invalid xml-report after parsing traits
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Pichler committed Dec 4, 2014
1 parent 1d9d0e1 commit 1d1bec0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
42 changes: 33 additions & 9 deletions src/main/php/PDepend/Report/Summary/Xml.php
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
}

Expand Down
3 changes: 3 additions & 0 deletions src/site/docx/changes.xml
Expand Up @@ -30,6 +30,9 @@
<action date="d96e4e7" dev="renan" type="fix" issue="173" system="github">
Fixing parsing True/False keywords in namespaces: Usage of true and false keywords are allowed in namespace declarations in PHP.
</action>
<action date="" dev="manuelpichler" due-to="pupsschluepfer" type="fix" issue="170" system="github">
invalid xml-report after parsing traits
</action>
<action date="73d32f3" dev="Deltachaos" type="fix" issue="167" system="github">
Fix Invalid argument supplied for foreach() in FileCacheDriver.php
</action>
Expand Down

0 comments on commit 1d1bec0

Please sign in to comment.