ElementIterator::accept()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of the feed-io package.
4
 *
5
 * (c) Alexandre Debril <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace FeedIo\Feed\Node;
12
13
/**
14
 * Iterator to filter elements by name
15
 * @see \FilterIterator
16
 */
17
class ElementIterator extends \FilterIterator
18
{
19
    /**
20
     * @var string $name Element name to accept
21
     */
22
    protected $name;
23
24
    /**
25
     * @param \Iterator $iterator Set of elements to filter
26
     * @param string    $name     Element name to accept
27
     */
28 19
    public function __construct(\Iterator $iterator, string $name)
29
    {
30 19
        parent::__construct($iterator);
31 19
        $this->name = $name;
32 19
    }
33
34
    /**
35
     * override PHP's count implementation.
36
     * @return int
37
     */
38 6
    public function count() : int
39
    {
40 6
        $count = 0;
41 6
        foreach ($this as $node) {
42 6
            $count++;
43
        }
44
45 6
        return $count;
46
    }
47
48
    /**
49
     * @return boolean True if the current element's name matches the expected one
50
     */
51 19
    public function accept() : bool
52
    {
53 19
        $element = $this->getInnerIterator()->current();
54
55 19
        return (0 == strcasecmp($this->name, $element->getName()));
56
    }
57
}
58