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

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of the iterators package.
4
 *
5
 * Copyright (c) Dusan Vejin
6
 *
7
 * For full copyright and license information, please refer to the LICENSE file,
8
 * located at the package root folder.
9
 */
10
11
declare(strict_types=1);
12
13
namespace Dutek\Iterator;
14
15
use ArrayIterator;
16
use Iterator;
17
18
final class ChunkIterator implements Iterator
19
{
20
    protected $iterator;
21
    protected $size;
22
    protected $chunk;
23
    protected $position;
24
25 6
    public function __construct(iterable $iterable, int $size = null)
26
    {
27 6
        if (is_array($iterable)) {
28 5
            $iterable = new ArrayIterator($iterable);
29
        }
30
31 6
        $this->iterator = $iterable;
32 6
        $this->size = $size ?? 1;
33 6
    }
34
35 4
    public function current()
36
    {
37 4
        return $this->chunk;
38
    }
39
40 6
    public function next()
41
    {
42 6
        $this->chunk = [];
43 6
        $this->position++;
44
45 6
        for ($i = 0; $i < $this->size && $this->iterator->valid(); $i++) {
46 4
            $this->chunk[] = $this->iterator->current();
47 4
            $this->iterator->next();
48
        }
49 6
    }
50
51 4
    public function key()
52
    {
53 4
        return $this->position;
54
    }
55
56 6
    public function valid()
57
    {
58 6
        return (bool)$this->chunk;
59
    }
60
61 6
    public function rewind()
62
    {
63 6
        $this->iterator->rewind();
64 6
        $this->position = -1;
65 6
        $this->next();
66 6
    }
67
}
68