| Total Complexity | 5 |
| Total Lines | 61 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 25 | trait Limit |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * @var integer the maximum number of results to retrieve/update/delete |
||
| 29 | */ |
||
| 30 | protected $limit; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var integer the index of the first result to retrieve. |
||
| 34 | */ |
||
| 35 | protected $offset = 0; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Sets the maximum number of results to retrieve/update/delete |
||
| 39 | * |
||
| 40 | * @param integer $limit The maximum number of results to retrieve |
||
| 41 | * @param integer $offset The offset of the query |
||
| 42 | * |
||
| 43 | * @return $this |
||
| 44 | */ |
||
| 45 | 2 | public function limit(int $limit, int $offset = 0): self |
|
| 46 | { |
||
| 47 | 2 | $this->setLimit($limit); |
|
| 48 | 2 | $this->setOffset($offset); |
|
| 49 | 2 | return $this; |
|
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Setup limit for the query |
||
| 54 | * |
||
| 55 | * @param integer $limit |
||
| 56 | * |
||
| 57 | * @return $this |
||
| 58 | */ |
||
| 59 | 5 | public function setLimit(int $limit): self |
|
| 60 | { |
||
| 61 | 5 | $this->limit = $limit; |
|
| 62 | 5 | return $this; |
|
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Setup offset for the query |
||
| 67 | * |
||
| 68 | * @param integer $offset |
||
| 69 | * |
||
| 70 | * @return $this |
||
| 71 | */ |
||
| 72 | 4 | public function setOffset(int $offset): self |
|
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Prepare string to apply limit inside SQL query |
||
| 80 | * |
||
| 81 | * @return string |
||
| 82 | */ |
||
| 83 | 9 | protected function prepareLimit(): string |
|
| 88 |