ZipIterator::next()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Zicht Online <http://zicht.nl>
4
 */
5
6
namespace Zicht\Itertools\lib;
7
8
use Zicht\Itertools\lib\Interfaces\FiniteIterableInterface;
9
use Zicht\Itertools\lib\Traits\FiniteIterableTrait;
10
11
class ZipIterator extends \MultipleIterator implements FiniteIterableInterface
12
{
13
    use FiniteIterableTrait;
14
15
    /** @var int */
16
    private $key;
17
18 12
    public function __construct()
19
    {
20 12
        parent::__construct(\MultipleIterator::MIT_NEED_ALL | \MultipleIterator::MIT_KEYS_NUMERIC);
21 12 View Code Duplication
        foreach (func_get_args() as $iterable) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22 12
            if (!$iterable instanceof \Iterator) {
23 3
                throw new \InvalidArgumentException(sprintf('Not all arguments are iterators'));
24
            }
25 9
            $this->attachIterator($iterable);
26
        }
27 9
        $this->key = 0;
28 9
    }
29
30
    /**
31
     * {@inheritDoc}
32
     */
33 8
    public function rewind()
34
    {
35 8
        parent::rewind();
36 8
        $this->key = 0;
37 8
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42 4
    public function key()
43
    {
44 4
        return $this->key;
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50 4
    public function next()
51
    {
52 4
        parent::next();
53 4
        $this->key += 1;
54 4
    }
55
}
56