ZipIterator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 13.33 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 11 3
A rewind() 0 5 1
A key() 0 4 1
A next() 0 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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