Total Complexity | 6 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
20 | trait Limit |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * @param int $limit |
||
25 | * @param null $offset |
||
|
|||
26 | * @return $this |
||
27 | * @throws QueryException |
||
28 | */ |
||
29 | public function limit( $limit, $offset = null ) |
||
30 | { |
||
31 | $limit = trim( $limit ); |
||
32 | |||
33 | if ( !QueryHelper::isInteger( $limit ) ) |
||
34 | throw new QueryException( 'Invalid Limit value', QueryException::QUERY_ERROR_INVALID_LIMIT ); |
||
35 | |||
36 | $limit = $this->queryStructure->bindParam('lim', (int)$limit); |
||
37 | |||
38 | if ( is_null( $offset ) ) { |
||
39 | $this->queryStructure->setElement( QueryStructure::LIMIT, $limit ); |
||
40 | |||
41 | return $this; |
||
42 | } |
||
43 | |||
44 | $offset = trim( $offset ); |
||
45 | |||
46 | if ( !QueryHelper::isInteger( $offset ) ) |
||
47 | throw new QueryException( 'Invalid Limit offset', QueryException::QUERY_ERROR_INVALID_LIMIT_OFFSET ); |
||
48 | |||
49 | $offset = $this->queryStructure->bindParam('ofs', (int)$offset); |
||
50 | |||
51 | $this->queryStructure->setElement( QueryStructure::LIMIT, $offset . ', ' . $limit ); |
||
52 | |||
53 | return $this; |
||
54 | } |
||
55 | |||
56 | private function getLimitSyntax() |
||
62 | } |
||
63 | |||
66 |