ChainTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 36
loc 36
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A chain() 13 13 2

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
// phpcs:disable Zicht.Commenting.FunctionComment.ExtraParamComment
7
8
namespace Zicht\Itertools\lib\Traits;
9
10
use Zicht\Itertools\lib\ChainIterator;
11
12 View Code Duplication
trait ChainTrait
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
13
{
14
    /**
15
     * Returns an iterator that returns elements from the first iterable
16
     * until it is exhausted, then proceeds to the next iterable, until
17
     * all the iterables are exhausted.
18
     *
19
     * Used for creating consecutive sequences as a single sequence.
20
     *
21
     * Note that the keys of the returned ChainIterator follow 0, 1, etc,
22
     * regardless of the keys given in the iterables.
23
     *
24
     * > iter\iterable([1, 2, 3], [4, 5, 6])->chain()
25
     * 1 2 3 4 5 6
26
     *
27
     * > iter\iterable('ABC', 'DEF')->chain()
28
     * A B C D E F
29
     *
30
     * @param array|string|\Iterator $iterable
0 ignored issues
show
Bug introduced by
There is no parameter named $iterable. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
31
     * @param array|string|\Iterator $iterable2
0 ignored issues
show
Bug introduced by
There is no parameter named $iterable2. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
32
     * @return null|ChainIterator
33
     */
34 12
    public function chain(/* $iterable, $iterable2, ... */)
35
    {
36 12
        if ($this instanceof \Iterator) {
37 11
            $iterables = array_map(
38 11
                '\Zicht\Itertools\conversions\mixed_to_iterator',
39 11
                func_get_args()
40
            );
41 11
            $reflectorClass = new \ReflectionClass('\Zicht\Itertools\lib\ChainIterator');
42 11
            return $reflectorClass->newInstanceArgs(array_merge([$this], $iterables));
43
        }
44
45 1
        return null;
46
    }
47
}
48