ZipTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 96.88 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A zip() 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\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