Passed
Branch v1.5.1 (ba2a89)
by Wanderson
03:18
created

Pagination::pageSize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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
	public $pageSize;
12
13
	/** @var int Current Page */
14
	public $current;
15
16
	/** @var int Total of records */
17
	public $count = 0;
18
19
	public $prev;
20
	public $next;
21
	public $last;
22
	public $offset;
23
24
	/**
25
	 * @param int $pageSize
26
	 * @param int $current
27
	 */
28
	public function __construct($pageSize, $current)
29
	{
30
		$this->pageSize = $pageSize;
31
		$this->current = max($current, 1);
32
	}
33
34
	public function setCount($count)
35
	{
36
		$this->count = $count;
37
		$this->last = ceil($count / $this->pageSize);
38
		$this->current = min($this->last, $this->current);
39
		$this->prev =  max(1, $this->current - 1);
40
		$this->next = min($this->last, $this->current + 1);
41
		$this->offset = $this->pageSize * ($this->current - 1);
42
	}
43
}
44