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.

PagedIterator::getTotalSize()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace IndependentReserve\Object;
4
5
use Closure;
6
use Elliotchance\Iterator\AbstractPagedIterator;
7
use IndependentReserve\PrivateClient;
8
9
class PagedIterator extends AbstractPagedIterator
10
{
11
    /**
12
     * @var int
13
     */
14
    protected $totalSize = -1;
15
16
    /**
17
     * @var PrivateClient
18
     */
19
    protected $client;
20
21
    /**
22
     * @var array
23
     */
24
    protected $params;
25
26
    /**
27
     * @var string
28
     */
29
    protected $endPoint;
30
31
    /**
32
     * @var Closure
33
     */
34
    protected $translator;
35
36
    /**
37
     * @param PrivateClient $client
38
     * @param string $endPoint
39
     * @param array $params
40
     * @param Closure $translator
41
     */
42 2
    public function __construct(PrivateClient $client, $endPoint, array $params, Closure $translator)
43
    {
44 2
        $this->client = $client;
45 2
        $this->endPoint = $endPoint;
46 2
        $this->params = $params;
47 2
        $this->translator = $translator;
48 2
    }
49
50
    /**
51
     * @return integer
52
     */
53 1
    public function getPageSize()
54
    {
55 1
        return $this->params['pageSize'];
56
    }
57
58
    /**
59
     * @return integer
60
     */
61 1
    public function getTotalSize()
62
    {
63 1
        if ($this->totalSize < 0) {
64 1
            $this->getPage(0);
65 1
        }
66 1
        return $this->totalSize;
67
    }
68
69
    /**
70
     * @param integer $pageNumber
71
     * @return array
72
     */
73 1
    public function getPage($pageNumber)
74
    {
75 1
        $result = json_decode($this->client->getPrivateEndpoint($this->endPoint, $this->params + [
76 1
            'pageIndex' => $pageNumber + 1,
77 1
        ]));
78 1
        $this->totalSize = $result->TotalItems;
79 1
        return array_map($this->translator, $result->Data);
80
    }
81
}
82