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.
Completed
Push — master ( cb2deb...f49fbb )
by Dusan
04:20
created

ChunkIterator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 46
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 4 1
A __construct() 0 5 1
A next() 0 10 3
A key() 0 4 1
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
/**
16
 * @author Dusan Vejin <[email protected]>
17
 */
18
final class ChunkIterator implements \Iterator
19
{
20
    protected $iterator;
21
    protected $size;
22
    protected $chunk;
23
    protected $position;
24
25 4
    public function __construct(\Iterator $iterator, int $size = null)
26
    {
27 4
        $this->iterator = $iterator;
28 4
        $this->size = $size ?? 1;
29 4
    }
30
31 2
    public function current()
32
    {
33 2
        return $this->chunk;
34
    }
35
36 4
    public function next()
37
    {
38 4
        $this->chunk = [];
39 4
        $this->position++;
40
41 4
        for ($i = 0; $i < $this->size && $this->iterator->valid(); $i++) {
42 2
            $this->chunk[] = $this->iterator->current();
43 2
            $this->iterator->next();
44
        }
45 4
    }
46
47 2
    public function key()
48
    {
49 2
        return $this->position;
50
    }
51
52 4
    public function valid()
53
    {
54 4
        return (bool)$this->chunk;
55
    }
56
57 4
    public function rewind()
58
    {
59 4
        $this->iterator->rewind();
60 4
        $this->position = -1;
61 4
        $this->next();
62 4
    }
63
}
64