ManualCountIterator::count()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Indigo\Iterator;
4
5
/**
6
 * Wraps an iterator and allows to set the count manually.
7
 *
8
 * Example: based on database COUNT result.
9
 *
10
 * @author Márk Sági-Kazár <[email protected]>
11
 */
12
class ManualCountIterator extends \IteratorIterator implements \Countable
13
{
14
    /**
15
     * @var int
16
     */
17
    protected $count;
18
19
    /**
20
     * @param \Traversable $iterator
21
     * @param int          $count
22
     */
23 1
    public function __construct(\Traversable $iterator, $count)
24
    {
25 1
        $this->count = $count;
26
27 1
        parent::__construct($iterator);
28 1
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 1
    public function count()
34
    {
35 1
        return $this->count;
36
    }
37
}
38