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

GenericSqlDefinitions   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 27
wmc 2
lcom 0
cbo 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 21 2
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