Completed
Push — master ( 3c0b40...28fa0e )
by Kévin
10s
created

GenericSqlDefinitions::create()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 43
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 27
nc 1
nop 1
1
<?php
2
3
namespace RulerZ\Target\Operators;
4
5
class GenericSqlDefinitions
6
{
7
    /**
8
     * @return Definitions
9
     */
10
    public static function create(Definitions $customOperators)
11
    {
12
        $defaultInlineOperators = [
13
            'and' => function ($a, $b) {
14
                return sprintf('(%s AND %s)', $a, $b);
15
            },
16
            'or' => function ($a, $b) {
17
                return sprintf('(%s OR %s)', $a, $b);
18
            },
19
            'not' => function ($a) {
20
                return sprintf('NOT (%s)', $a);
21
            },
22
            '=' => function ($a, $b) {
23
                return sprintf('%s = %s', $a, $b);
24
            },
25
            '!=' => function ($a, $b) {
26
                return sprintf('%s != %s', $a, $b);
27
            },
28
            '>' => function ($a, $b) {
29
                return sprintf('%s > %s', $a, $b);
30
            },
31
            '>=' => function ($a, $b) {
32
                return sprintf('%s >= %s', $a, $b);
33
            },
34
            '<' => function ($a, $b) {
35
                return sprintf('%s < %s', $a, $b);
36
            },
37
            '<=' => function ($a, $b) {
38
                return sprintf('%s <= %s', $a, $b);
39
            },
40
            'in' => function ($a, $b) {
41
                return sprintf('%s IN %s', $a, $b[0] === '(' ? $b : '('.$b.')');
42
            },
43
            'like' => function ($a, $b) {
44
                return sprintf('%s LIKE %s', $a, $b);
45
            },
46
        ];
47
48
        $definitions = new Definitions();
49
        $definitions->defineInlineOperators($defaultInlineOperators);
50
51
        return $definitions->mergeWith($customOperators);
52
    }
53
}
54