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

ChainIterator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 21.43 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 6
loc 28
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 0
wmc 4
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 10 3
A extend() 0 4 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\conversions;
10
use Zicht\Itertools\lib\Interfaces\FiniteIterableInterface;
11
use Zicht\Itertools\lib\Traits\FiniteIterableTrait;
12
13
/**
14
 * Class ChainIterator
15
 *
16
 * @package Zicht\Itertools\lib
17
 */
18
class ChainIterator extends \AppendIterator implements FiniteIterableInterface
19
{
20
    use FiniteIterableTrait;
21
22
    /**
23
     * ChainIterator constructor.
24
     */
25 18
    public function __construct()
26
    {
27 18
        parent::__construct();
28 18 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...
29 14
            if (!$iterable instanceof \Iterator) {
30 3
                throw new \InvalidArgumentException(sprintf('Not all arguments are iterators'));
31
            }
32 11
            $this->append($iterable);
33
        }
34 15
    }
35
36
    /**
37
     * Extend this iterator with the contents of $iterable
38
     *
39
     * @param array|string|\Iterator $iterable
40
     */
41 3
    public function extend($iterable)
42
    {
43 3
        parent::append(conversions\mixed_to_iterator($iterable));
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (append() instead of extend()). Are you sure this is correct? If so, you might want to change this to $this->append().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
44 3
    }
45
}
46