ReversedIterator::current()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
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 ReversedIterator extends \IteratorIterator implements FiniteIterableInterface
12
{
13
    use FiniteIterableTrait;
14
15
    /**
16
     * @param \Iterator $iterable
17
     */
18 4
    public function __construct(\Iterator $iterable)
19
    {
20 4
        $data = [];
21 4
        foreach ($iterable as $key => $value) {
22 3
            $data [] = [$key, $value];
23
        }
24 4
        parent::__construct(new \ArrayIterator(array_reverse($data)));
25 4
    }
26
27
    /**
28
     * {@inheritDoc}
29
     */
30 2
    public function key()
31
    {
32 2
        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...
33 2
        return $key;
34
    }
35
36
    /**
37
     * {@inheritDoc}
38
     */
39 2
    public function current()
40
    {
41 2
        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...
42 2
        return $value;
43
    }
44
}
45