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

GenericSolrDefinitions::create()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 25
nc 1
nop 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