GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ChunkIterator::rewind()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4286
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/**
4
 * Derived by Guzzle's ChunkedIterator https://github.com/guzzle/iterator/blob/master/ChunkedIterator.php
5
 * credit goes to the original authors.
6
 */
7
namespace Pipes\Iterator;
8
9
use Traversable;
10
11
class ChunkIterator extends \IteratorIterator
12
{
13
    protected $key = 0;
14
15
    /** @var int Size of each chunk */
16
    protected $size;
17
    /** @var array Current chunk */
18
    protected $chunk;
19
20
    /**
21
     * @param Traversable $iterator Traversable iterator
22
     * @param int         $size     Size to make each chunk
23
     *
24
     * @throws \InvalidArgumentException
25
     */
26
    public function __construct(Traversable $iterator, $size)
27
    {
28
        $size = (int) $size;
29
        if ($size < 0) {
30
            throw new \InvalidArgumentException("The chunk size must be equal or greater than zero; $size given");
31
        }
32
        parent::__construct($iterator);
33
        $this->size = $size;
34
    }
35
36
    public function rewind()
37
    {
38
        parent::rewind();
39
        $this->next();
40
        $this->key = 0;
41
    }
42
43
    public function next()
44
    {
45
        $this->chunk = array();
46
        for ($i = 0; $i < $this->size && parent::valid(); ++$i) {
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (valid() instead of next()). Are you sure this is correct? If so, you might want to change this to $this->valid().

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...
47
            $this->chunk[] = parent::current();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (current() instead of next()). 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...
48
            parent::next();
49
        }
50
        $this->chunk ? $this->key++ : null;
51
    }
52
53
    public function key()
54
    {
55
        return $this->key;
56
    }
57
58
    public function current()
59
    {
60
        return $this->chunk;
61
    }
62
63
    public function valid()
64
    {
65
        return (bool) $this->chunk;
66
    }
67
}
68