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.

ResourceCursor   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 22
c 1
b 0
f 1
dl 0
loc 94
rs 10
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A next() 0 10 3
A rewind() 0 5 1
A getLimit() 0 3 1
A current() 0 3 1
A key() 0 3 1
A valid() 0 3 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaignApi\Paginator;
7
8
/**
9
 * Class ResourceCursor
10
 */
11
class ResourceCursor implements ResourceCursorInterface
12
{
13
    /**
14
     * @var int|null
15
     */
16
    private $limit;
17
18
    /**
19
     * @var PageInterface
20
     */
21
    private $currentPage;
22
23
    /**
24
     * @var PageInterface
25
     */
26
    private $firstPage;
27
28
    /**
29
     * @var int
30
     */
31
    private $currentIndex = 0;
32
33
    /**
34
     * @var int
35
     */
36
    private $totalIndex = 0;
37
38
    /**
39
     * @param int|null $limit
40
     * @param PageInterface $firstPage
41
     */
42
    public function __construct(?int $limit, PageInterface $firstPage)
43
    {
44
        $this->limit = $limit;
45
        $this->currentPage = $firstPage;
46
        $this->firstPage = $firstPage;
47
    }
48
49
    /**
50
     * @inheritDoc
51
     */
52
    public function current()
53
    {
54
        return $this->currentPage->getItems()[$this->currentIndex];
55
    }
56
57
    /**
58
     * @inheritDoc
59
     */
60
    public function next()
61
    {
62
        $this->currentIndex++;
63
        $this->totalIndex++;
64
65
        $items = $this->currentPage->getItems();
66
67
        if (!isset($items[$this->currentIndex]) && $this->currentPage->hasNextPage()) {
68
            $this->currentIndex = 0;
69
            $this->currentPage = $this->currentPage->getNextPage();
70
        }
71
    }
72
73
    /**
74
     * @inheritDoc
75
     */
76
    public function key()
77
    {
78
        return $this->totalIndex;
79
    }
80
81
    /**
82
     * @inheritDoc
83
     */
84
    public function valid()
85
    {
86
        return isset($this->currentPage->getItems()[$this->currentIndex]);
87
    }
88
89
    /**
90
     * @inheritDoc
91
     */
92
    public function rewind()
93
    {
94
        $this->totalIndex = 0;
95
        $this->currentIndex = 0;
96
        $this->currentPage = $this->firstPage;
97
    }
98
99
    /**
100
     * @inheritDoc
101
     */
102
    public function getLimit(): ?int
103
    {
104
        return $this->limit;
105
    }
106
}
107