Skip to content

Commit ebd7001

Browse files
committed
Add directory collapsing code
1 parent 1867dfb commit ebd7001

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/collector/project/SourceCollection.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function getVanishedFiles() {
123123
return $list;
124124
}
125125

126-
public function export() {
126+
public function export($collapse = false) {
127127
if (count($this->collection) == 0) {
128128
return $this->workDom;
129129
}
@@ -150,10 +150,13 @@ public function export() {
150150
}
151151

152152
$this->collection = array();
153+
154+
if ($collapse) {
155+
$this->collapseDirectory();
156+
}
153157
return $this->workDom;
154158
}
155159

156-
157160
private function importDirNode(fDOMElement $dir, $path) {
158161
$path .= $dir->getAttribute('name');
159162
foreach($dir->query('phpdox:file') as $file) {
@@ -173,6 +176,20 @@ private function isChanged($path) {
173176
return $org->getAttribute('sha1') != $new->getAttribute('sha1');
174177
}
175178

179+
private function collapseDirectory() {
180+
$first = $this->workDom->queryOne('/phpdox:source/phpdox:dir');
181+
if ($first->query('phpdox:file')->length == 0 &&
182+
$first->query('phpdox:dir')->length == 1) {
183+
$dir = $first->queryOne('phpdox:dir');
184+
foreach($dir->query('*') as $child) {
185+
$first->appendChild($child);
186+
}
187+
$first->setAttribute('name', $first->getAttribute('name') . '/' . $dir->getAttribute('name'));
188+
$first->removeChild($dir);
189+
$this->collapseDirectory();
190+
}
191+
}
192+
176193
}
177194

178195

0 commit comments

Comments
 (0)