Passed
Push — master ( 9e9b54...8c04f5 )
by
unknown
38s
created

ReversedIterator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 36
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A key() 0 5 1
A current() 0 5 1
1
<?php
2
/**
3
 * @author Boudewijn Schoon <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
7
namespace Zicht\Itertools\lib;
8
9
use Zicht\Itertools\lib\Interfaces\FiniteIterableInterface;
10
use Zicht\Itertools\lib\Traits\FiniteIterableTrait;
11
12
/**
13
 * Class ReversedIterator
14
 *
15
 * @package Zicht\Itertools\lib
16
 */
17
class ReversedIterator extends \IteratorIterator implements FiniteIterableInterface
18
{
19
    use FiniteIterableTrait;
20
21
    /**
22
     * ReversedIterator constructor.
23
     *
24
     * @param \Iterator $iterable
25
     */
26 4
    public function __construct(\Iterator $iterable)
27
    {
28 4
        $data = [];
29 4
        foreach ($iterable as $key => $value) {
30 3
            $data [] = [$key, $value];
31
        }
32 4
        parent::__construct(new \ArrayIterator(array_reverse($data)));
33 4
    }
34
35
    /**
36
     * @{inheritDoc}
37
     */
38 2
    public function key()
39
    {
40 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...
41 2
        return $key;
42
    }
43
44
    /**
45
     * @{inheritDoc}
46
     */
47 2
    public function current()
48
    {
49 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...
50 2
        return $value;
51
    }
52
}
53