Passed
Push — master ( 9e9b54...8c04f5 )
by
unknown
38s
created

ZipIterator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 12.5 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
dl 6
loc 48
ccs 18
cts 18
cp 1
rs 10
c 3
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
 * @author Boudewijn Schoon <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
7
namespace Zicht\Itertools\lib;
8
9
use Zicht\Itertools\lib\Interfaces\FiniteIterableInterface;
10
use Zicht\Itertools\lib\Traits\FiniteIterableTrait;
11
12
/**
13
 * Class ZipIterator
14
 *
15
 * @package Zicht\Itertools\lib
16
 */
17
class ZipIterator extends \MultipleIterator implements FiniteIterableInterface
18
{
19
    use FiniteIterableTrait;
20
21
    /** @var int */
22
    private $key;
23
24
    /**
25
     * ZipIterator constructor.
26
     */
27 12
    public function __construct()
28
    {
29 12
        parent::__construct(\MultipleIterator::MIT_NEED_ALL | \MultipleIterator::MIT_KEYS_NUMERIC);
30 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...
31 12
            if (!$iterable instanceof \Iterator) {
32 3
                throw new \InvalidArgumentException(sprintf('Not all arguments are iterators'));
33
            }
34 9
            $this->attachIterator($iterable);
35
        }
36 9
        $this->key = 0;
37 9
    }
38
39
    /**
40
     * @{inheritDoc}
41
     */
42 8
    public function rewind()
43
    {
44 8
        parent::rewind();
45 8
        $this->key = 0;
46 8
    }
47
48
    /**
49
     * @{inheritDoc}
50
     */
51 4
    public function key()
52
    {
53 4
        return $this->key;
54
    }
55
56
    /**
57
     * @{inheritDoc}
58
     */
59 4
    public function next()
60
    {
61 4
        parent::next();
62 4
        $this->key += 1;
63 4
    }
64
}
65