Completed
Pull Request — release/3.0 (#204)
by
unknown
04:44
created

ElementIterator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 41
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A count() 0 9 2
A accept() 0 6 1
1
<?php
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
    public function __construct(\Iterator $iterator, $name)
29
    {
30
        parent::__construct($iterator);
31
        $this->name = $name;
32
    }
33
34
    /**
35
     * override PHP's count implementation.
36
     * @return int
37
     */
38
    public function count()
39
    {
40
        $count = 0;
41
        foreach ($this as $node) {
42
            $count++;
43
        }
44
45
        return $count;
46
    }
47
48
    /**
49
     * @return boolean True if the current element's name matches the expected one
50
     */
51
    public function accept()
52
    {
53
        $element = $this->getInnerIterator()->current();
54
55
        return (0 == strcasecmp($this->name, $element->getName()));
56
    }
57
}
58