Refactor getFirstPage

This commit is contained in:
Stéphane Goetz 2015-07-18 01:14:44 +02:00
parent ce109d0429
commit 71d1041cb8

View File

@ -87,7 +87,7 @@ abstract class Entry
} }
/** /**
* @return Content * @return Content|false
*/ */
public function getFirstPage() public function getFirstPage()
{ {
@ -95,7 +95,10 @@ abstract class Entry
return $this->first_page; return $this->first_page;
} }
if ($this instanceof Directory) { if (!$this instanceof Directory) {
return false;
}
foreach ($this->value as $node) { foreach ($this->value as $node) {
if ($node instanceof Content) { if ($node instanceof Content) {
if (!count($node->getParents()) && $node->title == 'index') { if (!count($node->getParents()) && $node->title == 'index') {
@ -107,13 +110,14 @@ abstract class Entry
return $node; return $node;
} }
} }
foreach ($this->value as $node) { foreach ($this->value as $node) {
if ($node instanceof Directory && $page = $node->getFirstPage()) { if ($node instanceof Directory && $page = $node->getFirstPage()) {
$this->first_page = $page; $this->first_page = $page;
return $page; return $page;
} }
} }
}
return false; return false;
} }