Passed
Pull Request — master (#26)
by Wanderson
02:55
created

Pagination::offset()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Win\Services;
4
5
/**
6
 * Auxilia criar paginações
7
 */
8
class Pagination
9
{
10
	public int $current = 1;
11
	public int $pageSize = 0;
12
	public int $count = 0;
13
	public int $last = 0;
14
15
	public function offset()
16
	{
17
		if ($this->pageSize && $this->count) {
18
			$this->last = ceil($this->count / $this->pageSize);
19
			$this->current = min(max($this->current, 1), $this->last);
20
		}
21
		return $this->pageSize * ($this->current - 1);
22
	}
23
}
24