Pagination   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setCount() 0 8 1
A __construct() 0 4 1
1
<?php
2
3
namespace Win\Common;
4
5
/**
6
 * Auxilia criar paginações
7
 */
8
class Pagination
9
{
10
	public int $current;
11
	public int $pageSize;
12
	public int $count = 0;
13
	public int $prev;
14
	public int $next;
15
	public int $last;
16
	public int $offset;
17
18
	/**
19
	 * @param int $pageSize
20
	 * @param int $current
21
	 */
22
	public function __construct($pageSize, $current)
23
	{
24
		$this->pageSize = $pageSize;
25
		$this->current = max($current, 1);
26
	}
27
28
	public function setCount($count)
29
	{
30
		$this->count = $count;
31
		$this->last = ceil($count / $this->pageSize);
32
		$this->current = min($this->last, $this->current);
33
		$this->prev = max(1, $this->current - 1);
34
		$this->next = min($this->last, $this->current + 1);
35
		$this->offset = $this->pageSize * ($this->current - 1);
36
	}
37
}
38