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

GenericSolrDefinitions   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 46
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B create() 0 40 1
1
<?php
2
3
namespace RulerZ\Target\Operators;
4
5
class GenericSolrDefinitions
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('-(%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 TO *]', $a, $b);
30
            },
31
            '>=' => function ($a, $b) {
32
                return sprintf('%s:[%s TO *]', $a, $b);
33
            },
34
            '<' => function ($a, $b) {
35
                return sprintf('%s:[* TO %s}', $a, $b);
36
            },
37
            '<=' => function ($a, $b) {
38
                return sprintf('%s:[* TO %s]', $a, $b);
39
            },
40
            'in' => function ($a, $b) {
41
                return sprintf('%s:(%s)', $a, implode(' OR ', $b));
42
            },
43
        ];
44
45
        $definitions = new Definitions();
46
        $definitions->defineInlineOperators($defaultInlineOperators);
47
48
        return $definitions->mergeWith($customOperators);
49
    }
50
}
51