Test Setup Failed
Pull Request — master (#49)
by
unknown
07:27
created

CollapseIterator::current()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Zicht Online <http://zicht.nl>
4
 */
5
6
namespace Zicht\Itertools\lib;
7
8
use Zicht\Itertools\lib\Interfaces\FiniteIterableInterface;
9
use Zicht\Itertools\lib\Traits\FiniteIterableTrait;
10
11
class CollapseIterator extends \IteratorIterator implements FiniteIterableInterface
12
{
13
    use FiniteIterableTrait;
14
15
    /**
16
     * @param \Iterator $iterable
17
     */
18
    public function __construct(\Iterator $iterable)
19
    {
20
        $data = [];
21
        foreach ($iterable as $subIterable) {
22
            if (is_array($subIterable) || $subIterable instanceof \Traversable) {
23
                foreach ($subIterable as $key => $value) {
24
                    $data [] = [$key, $value];
25
                }
26
            }
27
        }
28
        parent::__construct(new \ArrayIterator($data));
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function key()
35
    {
36
        list($key, $value) = parent::current();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (current() instead of key()). Are you sure this is correct? If so, you might want to change this to $this->current().

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...
Unused Code introduced by
The assignment to $value is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
37
        return $key;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function current()
44
    {
45
        list($key, $value) = parent::current();
0 ignored issues
show
Unused Code introduced by
The assignment to $key is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
46
        return $value;
47
    }
48
}
49