ActiveSalesmanFilterIterator::accept()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 4
cts 5
cp 0.8
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.032
1
<?php
2
namespace Germania\Salesmen;
3
4
class ActiveSalesmanFilterIterator extends \FilterIterator
5
{
6
7
    /**
8
     * @var boolean
9
     */
10
    public $active_flag = true;
11
12
    /**
13
     * @param \Traversable $collection      Collection of SalesmanIdProviderInterface
14
     * @param bool $active_flag
15
     */
16 32
    public function __construct( \Traversable $collection, $active_flag = true )
0 ignored issues
show
Unused Code introduced by
The parameter $active_flag is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
17
    {
18
        // Take care of Traversable's two faces,
19
        // since both IteratorAggregate and Iterator implement Traversable
20 32
        parent::__construct( $collection instanceOf \IteratorAggregate ? $collection->getIterator() : $collection );
21 32
    }
22
23 32
    public function accept()
24
    {
25 32
        $item = $this->getInnerIterator()->current();
26
27
        // Disclose items not implementing SalesmanIdProviderInterface
28 32
        if (!$item instanceOf SalesmanIdProviderInterface) {
29
            return false;
30
        }
31
32 32
        return $item->isActive() == $this->active_flag;
33
34
    }
35
36
}
37