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   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 50
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A key() 0 4 1
A __construct() 0 9 2
A current() 0 4 1
A next() 0 10 3
A valid() 0 4 1
A rewind() 0 6 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