From ebd7001b83cc8a5864f51ff3c609a99bdf118bef Mon Sep 17 00:00:00 2001 From: Arne Blankerts Date: Fri, 2 Jan 2015 19:29:09 +0100 Subject: [PATCH] Add directory collapsing code --- src/collector/project/SourceCollection.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/collector/project/SourceCollection.php b/src/collector/project/SourceCollection.php index 37c665cc..10636bbd 100644 --- a/src/collector/project/SourceCollection.php +++ b/src/collector/project/SourceCollection.php @@ -123,7 +123,7 @@ public function getVanishedFiles() { return $list; } - public function export() { + public function export($collapse = false) { if (count($this->collection) == 0) { return $this->workDom; } @@ -150,10 +150,13 @@ public function export() { } $this->collection = array(); + + if ($collapse) { + $this->collapseDirectory(); + } return $this->workDom; } - private function importDirNode(fDOMElement $dir, $path) { $path .= $dir->getAttribute('name'); foreach($dir->query('phpdox:file') as $file) { @@ -173,6 +176,20 @@ private function isChanged($path) { return $org->getAttribute('sha1') != $new->getAttribute('sha1'); } + private function collapseDirectory() { + $first = $this->workDom->queryOne('/phpdox:source/phpdox:dir'); + if ($first->query('phpdox:file')->length == 0 && + $first->query('phpdox:dir')->length == 1) { + $dir = $first->queryOne('phpdox:dir'); + foreach($dir->query('*') as $child) { + $first->appendChild($child); + } + $first->setAttribute('name', $first->getAttribute('name') . '/' . $dir->getAttribute('name')); + $first->removeChild($dir); + $this->collapseDirectory(); + } + } + }