ZipTrait::zip()   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\ZipIterator;
11
12 View Code Duplication
trait ZipTrait
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 where one or more iterables are zipped together
16
     *
17
     * This function returns a list of tuples, where the i-th tuple contains
18
     * the i-th element from each of the argument sequences or iterables.
19
     *
20
     * The returned list is truncated in length to the length of the
21
     * shortest argument sequence.
22
     *
23
     * > zip([1, 2, 3], ['a', 'b', 'c'])
24
     * [1, 'a'] [2, 'b'] [3, 'c']
25
     *
26
     * @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...
27
     * @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...
28
     * @return ZipIterator
29
     */
30 10
    public function zip(/* $iterable, $iterable2, ... */)
31
    {
32 10
        if ($this instanceof \Iterator) {
33 9
            $iterables = array_map(
34 9
                '\Zicht\Itertools\conversions\mixed_to_iterator',
35 9
                func_get_args()
36
            );
37 9
            $reflectorClass = new \ReflectionClass('\Zicht\Itertools\lib\ZipIterator');
38 9
            return $reflectorClass->newInstanceArgs(array_merge([$this], $iterables));
39
        }
40
41 1
        return null;
42
    }
43
}
44