Completed
Branch feature/pre-split (80980a)
by Anton
04:00
created

MySQLCompiler::orderParameters()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 15
nc 2
nop 5
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B MySQLCompiler::compileLimit() 18 18 7
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
9
namespace Spiral\Database\Drivers\MySQL;
10
11
use Spiral\Database\Entities\QueryCompiler as AbstractCompiler;
12
use Spiral\Database\Injections\ParameterInterface;
13
14
/**
15
 * MySQL syntax specific compiler.
16
 */
17
class MySQLCompiler extends AbstractCompiler
18
{
19
    /**
20
     * {@inheritdoc}
21
     *
22
     * @link http://dev.mysql.com/doc/refman/5.0/en/select.html#id4651990
23
     */
24 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...
25
    {
26
        if (empty($limit) && empty($offset)) {
27
            return '';
28
        }
29
30
        $statement = '';
31
        if (!empty($limit) || !empty($offset)) {
32
            //When limit is not provided but offset does we can replace limit value with PHP_INT_MAX
33
            $statement = 'LIMIT ' . ($limit ?: '18446744073709551615') . ' ';
34
        }
35
36
        if (!empty($offset)) {
37
            $statement .= "OFFSET {$offset}";
38
        }
39
40
        return trim($statement);
41
    }
42
43
    /**
44
     * Resolve operator value based on value value. ;).
45
     *
46
     * @param mixed  $parameter
47
     * @param string $operator
48
     *
49
     * @return string
50
     */
51
    protected function prepareOperator($parameter, string $operator): string
52
    {
53
        if (!$parameter instanceof ParameterInterface) {
54
            //Probably fragment
55
            return $operator;
56
        }
57
58
        if ($parameter->getType() == \PDO::PARAM_NULL) {
59
            switch ($operator) {
60
                case '=':
61
                    return 'IS';
62
                case '!=':
63
                    return 'IS NOT';
64
            }
65
        }
66
67
        return parent::prepareOperator($parameter, $operator);
68
    }
69
}
70