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 ( 4a2061...30729a )
by Asao
01:24
created

Inputs::setPaginate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Tuum\Pagination;
3
4
use Tuum\Pagination\Paginate\Paginate;
5
use Tuum\Pagination\Paginate\PaginateInterface;
6
use Tuum\Pagination\ToHtml\ToBootstrap3;
7
8
class Inputs
9
{
10
    /**
11
     * @var string
12
     */
13
    public $pagerKey = '_page';
14
15
    /**
16
     * @var string
17
     */
18
    public $limitKey = '_limit';
19
20
    /**
21
     * @var int|null
22
     */
23
    private $total = null;
24
25
    /**
26
     * @var array
27
     */
28
    private $list = [];
29
30
    /**
31
     * @var string
32
     */
33
    public $path = '';
34
35
    /**
36
     * @var array
37
     */
38
    public $inputs = [];
39
40
    /**
41
     * @var PaginateInterface
42
     */
43
    private $paginate;
44
45
    /**
46
     * Inputs constructor.
47
     *
48
     * @param PaginateInterface $paginate
49
     */
50
    public function __construct($paginate = null)
51
    {
52
        $this->paginate = $paginate;
53
    }
54
55
    /**
56
     * get the limit, i.e. number of data per page.
57
     *
58
     * @return int
59
     */
60
    public function getLimit()
61
    {
62
        return (int)isset($this->inputs[$this->limitKey]) ? $this->inputs[$this->limitKey] : 20;
63
    }
64
65
    /**
66
     * get the offset for retrieving data.
67
     *
68
     * @return int
69
     */
70
    public function getOffset()
71
    {
72
        return $this->getLimit() * ($this->getPage() - 1);
73
    }
74
75
    /**
76
     * get the current page number, starting from 1.
77
     *
78
     * @return int
79
     */
80
    public function getPage()
81
    {
82
        return (int)isset($this->inputs[$this->pagerKey]) ? $this->inputs[$this->pagerKey] : 1;
83
    }
84
85
    /**
86
     * get any key from query.
87
     *
88
     * @param string     $key
89
     * @param null|mixed $alt
90
     * @return null|mixed
91
     */
92
    public function get($key, $alt = null)
93
    {
94
        return array_key_exists($key, $this->inputs)
95
            ? $this->inputs[$key]
96
            : $this->inputs[$key] = $alt;
97
    }
98
99
    /**
100
     * get total number of data.
101
     * - total: number of all the possible data which can be retrieved.
102
     * - count: number of data in the current list.
103
     *
104
     * @return int|null
105
     */
106
    public function getTotal()
107
    {
108
        return $this->total;
109
    }
110
111
    /**
112
     * set the total of data.
113
     *
114
     * @param int|null $total
115
     */
116
    public function setTotal($total)
117
    {
118
        $this->total = $total;
119
    }
120
121
    /**
122
     * set the data for list.
123
     *
124
     * @param mixed $list
125
     */
126
    public function setList($list)
127
    {
128
        $this->list = $list;
0 ignored issues
show
Documentation Bug introduced by
It seems like $list of type * is incompatible with the declared type array of property $list.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
129
    }
130
131
    /**
132
     * get the data for list.
133
     *
134
     * @return null|array|mixed
135
     */
136
    public function getList()
137
    {
138
        return $this->list;
139
    }
140
141
    /**
142
     * get the count, i.e. number of data in the current list.
143
     * count is the number of data in the current list.
144
     *
145
     * @return int
146
     */
147
    public function getCount()
148
    {
149
        if (isset($this->list) && is_array($this->list)) {
150
            return count($this->list);
151
        }
152
        return 0;
153
    }
154
    
155
    /**
156
     * calculates the first page number, that is 1.
157
     *
158
     * @return int
159
     */
160
    public function calcFirstPage()
161
    {
162
        return 1;
163
    }
164
165
    /**
166
     * calculates the last pager number.
167
     *
168
     * @return int
169
     */
170
    public function calcLastPage()
171
    {
172
        $total = $this->getTotal();
173
        if (!$total) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $total of type integer|null is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
174
            return $this->getPage() + 1;
175
        }
176
        $pages = $this->getLimit();
177
        return (integer)(ceil($total / $pages));
178
    }
179
    
180
    /**
181
     * @param null|int $page
182
     * @return string
183
     */
184
    public function getPath($page = null)
185
    {
186
        if (is_null($page)) {
187
            return $this->path;
188
        }
189
        $page = (int)$page;
190
        return $this->path . '?' . $this->pagerKey . '=' . $page;
191
    }
192
193
    /**
194
     * @return PaginateInterface
195
     */
196
    public function getPagination()
197
    {
198
        $paginate = $this->paginate ? $this->paginate->setInputs($this): Paginate::forge($this);
199
        
200
        return $paginate;
201
    }
202
203
    /**
204
     * @param PaginateInterface $paginate
205
     */
206
    public function setPaginate($paginate)
207
    {
208
        $this->paginate = $paginate;
209
    }
210
}