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

SQLServerCompiler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 65.22 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 15
loc 23
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A compileLimit() 15 15 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}