doc/lib: Use TreeNodeIterator in the SectionFilterIterator

refs #6630
This commit is contained in:
Eric Lippmann 2015-02-10 17:06:11 +01:00
parent 9093795f64
commit 52de56fb65
1 changed files with 31 additions and 19 deletions

View File

@ -5,30 +5,34 @@ namespace Icinga\Module\Doc;
use Countable; use Countable;
use RecursiveFilterIterator; use RecursiveFilterIterator;
use Icinga\Data\Tree\NodeInterface; use Icinga\Data\Tree\TreeNodeIterator;
/** /**
* Recursive iterator over sections that are part of a particular chapter * Recursive filter iterator over sections that are part of a particular chapter
*
* @method TreeNodeIterator getInnerIterator() {
* {@inheritdoc}
* }
*/ */
class SectionFilterIterator extends RecursiveFilterIterator implements Countable class SectionFilterIterator extends RecursiveFilterIterator implements Countable
{ {
/** /**
* The chapter ID to filter for * Chapter to filter for
* *
* @var string * @type string
*/ */
protected $chapterId; protected $chapter;
/** /**
* Create a new SectionFilterIterator * Create a new recursive filter iterator over sections that are part of a particular chapter
* *
* @param NodeInterface $node Node * @param TreeNodeIterator $iterator
* @param string $chapterId The chapter ID to filter for * @param string $chapter The chapter to filter for
*/ */
public function __construct(NodeInterface $node, $chapterId) public function __construct(TreeNodeIterator $iterator, $chapter)
{ {
parent::__construct($node); parent::__construct($iterator);
$this->chapterId = $chapterId; $this->chapter = $chapter;
} }
/** /**
@ -39,29 +43,37 @@ class SectionFilterIterator extends RecursiveFilterIterator implements Countable
*/ */
public function accept() public function accept()
{ {
$section = $this->getInnerIterator()->current()->getValue(); $section = $this->current();
/* @var $section \Icinga\Module\Doc\Section */ /** @type \Icinga\Module\Doc\DocSection $section */
if ($section->getChapterId() === $this->chapterId) { if ($section->getChapter()->getId() === $this->chapter) {
return true; return true;
} }
return false; return false;
} }
/** /**
* (non-PHPDoc) * {@inheritdoc}
* @see RecursiveFilterIterator::getChildren()
*/ */
public function getChildren() public function getChildren()
{ {
return new static($this->getInnerIterator()->getChildren(), $this->chapterId); return new static($this->getInnerIterator()->getChildren(), $this->chapter);
} }
/** /**
* (non-PHPDoc) * {@inheritdoc}
* @see Countable::count()
*/ */
public function count() public function count()
{ {
return iterator_count($this); return iterator_count($this);
} }
/**
* Whether the filter swallowed every section
*
* @return bool
*/
public function isEmpty()
{
return $this->count() === 0;
}
} }