Completed
Push — master ( fb357f...51b9c7 )
by Peter
06:58
created

LimitableTrait::setLimit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * This software package is licensed under AGPL or Commercial license.
5
 *
6
 * @package maslosoft/mangan
7
 * @licence AGPL or Commercial
8
 * @copyright Copyright (c) Piotr Masełkowski <[email protected]>
9
 * @copyright Copyright (c) Maslosoft
10
 * @copyright Copyright (c) Others as mentioned in code
11
 * @link http://maslosoft.com/mangan/
12
 */
13
14
namespace Maslosoft\Mangan\Traits\Criteria;
15
16
use Maslosoft\Mangan\Interfaces\Criteria\LimitableInterface;
17
18
/**
19
 * LimitableTrait
20
 * @see LimitableInterface
21
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
22
 */
23
trait LimitableTrait
24
{
25
26
	private $_limit = null;
27
	private $_offset = null;
28
29
	/**
30
	 * Set limit
31
	 * Multiple calls will overrride previous value of limit.
32
	 *
33
	 * Pass `false` to disable limit.
34
	 *
35
	 * @param integer|bool $limit limit
36
	 * @return static
37
	 */
38 1
	public function limit($limit)
39
	{
40 1
		if (false === $limit)
41
		{
42
			$this->_limit = null;
43
			return $this;
44
		}
45 1
		$this->_limit = intval($limit);
46 1
		return $this;
47
	}
48
49
	/**
50
	 * Set offset
51
	 * Multiple calls will override previous value
52
	 *
53
	 * Pass `false` to disable offset.
54
	 *
55
	 * @return static
56
	 */
57 1
	public function offset($offset)
58
	{
59 1
		if (false === $offset)
60
		{
61
			$this->_offset = null;
62
			return $this;
63
		}
64 1
		$this->_offset = intval($offset);
65 1
		return $this;
66
	}
67
68
	/**
69
	 * @since v1.0
70
	 */
71 82
	public function getLimit()
72
	{
73 82
		return $this->_limit;
74
	}
75
76
	/**
77
78
	 * @return static
79
	 */
80 1
	public function setLimit($limit)
81
	{
82 1
		$this->limit($limit);
83 1
		return $this;
84
	}
85
86
	/**
87
	 * @return static
88
	 */
89 82
	public function getOffset()
90
	{
91 82
		return $this->_offset;
92
	}
93
94
	/**
95
	 * @since v1.0
96
	 */
97 1
	public function setOffset($offset)
98
	{
99 1
		$this->offset($offset);
100 1
		return $this;
101
	}
102
103
}
104