| Conditions | 5 |
| Paths | 3 |
| Total Lines | 21 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 5 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 56 | 32 | protected function applyLimit($stm) |
|
| 57 | { |
||
| 58 | 32 | if (! $this->limit && ! $this->offset) { |
|
| 59 | 30 | return $stm; // no limit or offset |
|
| 60 | } |
||
| 61 | |||
| 62 | // limit but no offset? |
||
| 63 | 2 | if ($this->limit && ! $this->offset) { |
|
| 64 | // use TOP in place |
||
| 65 | 1 | return preg_replace( |
|
| 66 | 1 | '/^(SELECT( DISTINCT)?)/', |
|
| 67 | 1 | "$1 TOP {$this->limit}", |
|
| 68 | $stm |
||
| 69 | ); |
||
| 70 | } |
||
| 71 | |||
| 72 | // both limit and offset. must have an ORDER clause to work; OFFSET is |
||
| 73 | // a sub-clause of the ORDER clause. cannot use FETCH without OFFSET. |
||
| 74 | 2 | return $stm . PHP_EOL . "OFFSET {$this->offset} ROWS " |
|
| 75 | 2 | . "FETCH NEXT {$this->limit} ROWS ONLY"; |
|
| 76 | } |
||
| 77 | } |
||
| 78 |