Completed
Push — master ( bc8abc...611a53 )
by Achille
9s
created

Paginator::getPage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Streak;
4
5
class Paginator
6
{
7
    protected $page;
8
    protected $limit;
9
    protected $results = [];
10
    protected $hasMore = true;
11
12
    /**
13
     * @param int $pageStart
14
     * @param int $limit
15
     */
16
    public function __construct($pageStart = 0, $limit = 500)
17
    {
18
        $this->page = $pageStart;
19
        $this->limit = $limit;
20
    }
21
22
    /**
23
     * @return array
24
     */
25
    public function getResults()
26
    {
27
        return $this->results;
28
    }
29
30
    /**
31
     * @param array $results
32
     */
33
    public function addResults(array $results)
34
    {
35
        if (0 === count($results)) {
36
            $this->hasMore = false;
37
        }
38
39
        $this->results = array_merge($this->results, $results);
40
    }
41
42
    /**
43
     * @return bool
44
     */
45
    public function hasMore()
46
    {
47
        return $this->hasMore;
48
    }
49
50
    public function nextPage()
51
    {
52
        if ($this->hasMore()) {
53
            $this->page++;
54
55
            return true;
56
        }
57
58
        return false;
59
    }
60
61
    /**
62
     * @return int
63
     */
64
    public function getPage()
65
    {
66
        return $this->page;
67
    }
68
69
    /**
70
     * @return int
71
     */
72
    public function getLimit()
73
    {
74
        return $this->limit;
75
    }
76
}
77