Completed
Push — master ( 68be21...073c54 )
by Kévin
02:41
created

GenericSqlDefinitions::create()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 21
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 2
eloc 16
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) { return sprintf('(%s AND %s)', $a, $b); },
14
            'or' =>   function ($a, $b) { return sprintf('(%s OR %s)', $a, $b); },
15
            'not' =>  function ($a)     { return sprintf('NOT (%s)', $a); },
16
            '=' =>    function ($a, $b) { return sprintf('%s = %s', $a, $b); },
17
            '!=' =>   function ($a, $b) { return sprintf('%s != %s', $a, $b); },
18
            '>' =>    function ($a, $b) { return sprintf('%s > %s', $a,  $b); },
19
            '>=' =>   function ($a, $b) { return sprintf('%s >= %s', $a,  $b); },
20
            '<' =>    function ($a, $b) { return sprintf('%s < %s', $a,  $b); },
21
            '<=' =>   function ($a, $b) { return sprintf('%s <= %s', $a,  $b); },
22
            'in' =>   function ($a, $b) { return sprintf('%s IN %s', $a, $b[0] === '(' ? $b : '('.$b.')'); },
23
            'like' => function ($a, $b) { return sprintf('%s LIKE %s', $a, $b); },
24
        ];
25
26
        $definitions = new Definitions();
27
        $definitions->defineInlineOperators($defaultInlineOperators);
28
29
        return $definitions->mergeWith($customOperators);
30
    }
31
}
32