Completed
Pull Request — master (#87)
by joanhey
02:25 queued 01:15
created

sqlsrv_limit.php ➔ sqlsrv_limit()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 4
nop 3
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * KumbiaPHP web & app Framework
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the new BSD license that is bundled
8
 * with this package in the file LICENSE.txt.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://wiki.kumbiaphp.com/Licencia
11
 * If you did not receive a copy of the license and are unable to
12
 * obtain it through the world-wide-web, please send an email
13
 * to [email protected] so we can send you a copy immediately.
14
 *
15
 * @category   Kumbia
16
 * @package    ActiveRecord
17
 * @subpackage Query
18
 * @copyright  Copyright (c) 2005-2016  Kumbia Team (http://www.kumbiaphp.com)
19
 * @license    http://wiki.kumbiaphp.com/Licencia     New BSD License
20
 */
21
22
namespace Kumbia\ActiveRecord\Query;
23
24
/**
25
 * Adiciona limit y offset a la consulta sql en mssql
26
 *
27
 * @param string $sql consulta select
28
 * @param string $limit valor limit
29
 * @param string $offset valor offset
30
 * @return string
31
 */
32 View Code Duplication
function sqlsrv_limit($sql, $limit = null, $offset = null)
0 ignored issues
show
Duplication introduced by
This function 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...
33
{
34
    if ($limit !== null) {
35
        $limit = (int) $limit;
36
        $sql = preg_replace('/(DELETE|INSERT|SELECT|UPDATE)/i', '${1} TOP ' . $limit, $sql);
37
    }
38
39
    if ($offset !== null) {
40
        $offset = (int) $offset;
41
        $sql .= " OFFSET $offset";
42
    }
43
44
    return $sql;
45
}
46