ChainTrait::chain()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 13
loc 13
ccs 8
cts 8
cp 1
crap 2
rs 9.8333
c 0
b 0
f 0
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