Passed
Branch v1.6.0 (6d31de)
by Wanderson
02:23
created

Pagination::offset()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace Win\Common;
4
5
/**
6
 * Auxilia criar paginações
7
 */
8
class Pagination
9
{
10
	public int $current = 1;
11
	public ?int $pageSize = null;
12
	public int $count;
13
	public int $last;
14
15
	public function offset()
16
	{
17
		if ($this->pageSize) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->pageSize of type integer|null is loosely compared to true; this is ambiguous if the integer can be 0. 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...
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