Passed
Branch v1.5.1 (d792f9)
by Wanderson
01:51
created

Pagination::setCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Win\Common;
4
5
/**
6
 * Auxilia criar paginações
7
 */
8
class Pagination
9
{
10
	/** @var int */
11
	private $pageSize = 0;
12
13
	/** @var int */
14
	private $current = 0;
15
16
	/** @var int */
17
	private $count = 0;
18
19
	/**
20
	 * @param int $pageSize
21
	 * @param int $currentPage
22
	 */
23
	public function setPage($pageSize, $currentPage)
24
	{
25
		$this->pageSize = $pageSize;
26
		$this->current = max($currentPage, 1);
27
	}
28
29
	public function setCount($count)
30
	{
31
		$this->count = $count;
32
		$this->current = min($this->last(), $this->current);
33
	}
34
35
	public function pageSize()
36
	{
37
		return $this->pageSize;
38
	}
39
40
	public function count()
41
	{
42
		return $this->count;
43
	}
44
45
	public function offset()
46
	{
47
		return $this->pageSize * ($this->current - 1);
48
	}
49
50
	public function current()
51
	{
52
		return $this->current;
53
	}
54
55
	public function first()
56
	{
57
		return 1;
58
	}
59
60
	public function last()
61
	{
62
		return ceil($this->count / $this->pageSize);
63
	}
64
65
	public function prev()
66
	{
67
		return max(1, $this->current - 1);
68
	}
69
70
	public function next()
71
	{
72
		return min($this->last(), $this->current + 1);
73
	}
74
}
75