Completed
Branch feature/pre-split (1fb805)
by Anton
03:35
created

SQLServerCompiler::compileLimit()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 3
nop 2
dl 15
loc 15
rs 9.2
c 0
b 0
f 0
1
<?php
2
/**
3
 * components
4
 *
5
 * @author    Wolfy-J
6
 */
7
namespace Spiral\Database\Drivers\SQLServer;
8
9
use Spiral\Database\Entities\QueryCompiler;
10
11
/**
12
 * Microsoft SQL server specific syntax compiler.
13
 */
14
class SQLServerCompiler extends QueryCompiler
15
{
16
    /**
17
     * {@inheritdoc}
18
     *
19
     * @link http://stackoverflow.com/questions/2135418/equivalent-of-limit-and-offset-for-sql-server
20
     */
21 View Code Duplication
    protected function compileLimit(int $limit, int $offset): string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
    {
23
        if (empty($limit) && empty($offset)) {
24
            return '';
25
        }
26
27
        //Modern SQLServer are easier to work with
28
        $statement = "OFFSET {$offset} ROWS ";
29
30
        if (!empty($limit)) {
31
            $statement .= "FETCH NEXT {$limit} ROWS ONLY";
32
        }
33
34
        return trim($statement);
35
    }
36
}