GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( f9513e...1e71bd )
by Simone
15:19 queued 10:20
created

Dictionary::getPublicOperators()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Mado\QueryBundle;
4
5
class Dictionary
6
{
7
    const DEFAULT_OPERATOR = 'eq';
8
9
    const NUMBER_EQUAL         = 'eq';
10
    const NUMBER_NOT_EQUAL     = 'neq';
11
    const NUMBER_GREATER       = 'gt';
12
    const NUMBER_GREATER_EQUAL = 'gte';
13
    const NUMBER_LITTLE        = 'lt';
14
    const NUMBER_LITTLE_EQUAL  = 'lte';
15
16
    const STRING_STARTS_WITH  = 'startswith';
17
    const STRING_CONTAINS     = 'contains';
18
    const STRING_NOT_CONTAINS = 'notcontains';
19
    const STRING_ENDS_WITH    = 'endswith';
20
21
    const FIELD_LIST        = 'list';
22
    const FIELD_NOT_IN_LIST = 'nlist';
23
    const FIELD_EQUALITY    = 'field_eq';
24
25
    private static $doctrineTypeToOperatorsMap = [
26
27
        'default' => [
28
            self::FIELD_LIST,
29
            self::FIELD_NOT_IN_LIST,
30
            self::FIELD_EQUALITY,
31
            self::NUMBER_EQUAL,
32
            self::NUMBER_NOT_EQUAL,
33
            self::NUMBER_GREATER,
34
            self::NUMBER_GREATER_EQUAL,
35
            self::NUMBER_LITTLE,
36
            self::NUMBER_LITTLE_EQUAL,
37
            self::STRING_STARTS_WITH,
38
            self::STRING_CONTAINS,
39
            self::STRING_NOT_CONTAINS,
40
            self::STRING_ENDS_WITH,
41
            'isnull',
42
            'isnotnull',
43
            'listcontains',
44
        ],
45
46
        'fields' => [
47
            self::FIELD_LIST,
48
            self::FIELD_NOT_IN_LIST,
49
            self::FIELD_EQUALITY,
50
        ],
51
52
        'integer' => [
53
            self::NUMBER_EQUAL,
54
            self::NUMBER_NOT_EQUAL,
55
            self::NUMBER_GREATER,
56
            self::NUMBER_GREATER_EQUAL,
57
            self::NUMBER_LITTLE,
58
            self::NUMBER_LITTLE_EQUAL,
59
        ],
60
61
        'string' => [
62
            self::STRING_STARTS_WITH,
63
            self::STRING_CONTAINS,
64
            self::STRING_NOT_CONTAINS,
65
            self::STRING_ENDS_WITH,
66
        ],
67
68
    ];
69
70
    private static $operatorMap = [
71
72
        self::NUMBER_EQUAL         => [ 'meta' => ' =' ],
73
        self::NUMBER_NOT_EQUAL     => [ 'meta' => '!=' ],
74
        self::NUMBER_GREATER       => [ 'meta' => '>'  ],
75
        self::NUMBER_GREATER_EQUAL => [ 'meta' => '>=' ],
76
        self::NUMBER_LITTLE        => [ 'meta' => '<'  ],
77
        self::NUMBER_LITTLE_EQUAL  => [ 'meta' => '<=' ],
78
79
        self::STRING_STARTS_WITH  => [ 'meta' => 'LIKE', 'substitution_pattern' => '{string}%' ],
80
        self::STRING_CONTAINS     => [ 'meta' => 'LIKE', 'substitution_pattern'     => '%{string}%' ],
81
        self::STRING_NOT_CONTAINS => [ 'meta' => 'NOT LIKE', 'substitution_pattern' => '%{string}%' ],
82
        self::STRING_ENDS_WITH    => [ 'meta' => 'LIKE', 'substitution_pattern' => '%{string}' ],
83
84
        self::FIELD_LIST        => [ 'meta' => 'IN', 'substitution_pattern'     => '({string})' ],
85
        self::FIELD_NOT_IN_LIST => [ 'meta' => 'NOT IN', 'substitution_pattern' => '({string})' ],
86
        self::FIELD_EQUALITY    => [ 'meta' => '=' ],
87
88
        'isnull' => [
89
            'meta' => 'IS NULL',
90
        ],
91
92
        'isnotnull' => [
93
            'meta' => 'IS NOT NULL',
94
        ],
95
96
        'listcontains' => [
97
            'meta' => 'LIKE',
98
            'substitution_pattern' => '({string})',
99
        ],
100
101
    ];
102
103
    public static function getOperators()
104
    {
105
        return self::$operatorMap;
106
    }
107
108
    public static function getPublicOperators()
109
    {
110
        return self::$doctrineTypeToOperatorsMap;
111
    }
112
113
    public static function getOperatorsFromDoctrineType(string $type)
114
    {
115
        try {
116
            self::ensureTypeIsDefined($type);
117
            return self::$doctrineTypeToOperatorsMap[$type];
118
        } catch (\Exception $e) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
119
120
        return self::$doctrineTypeToOperatorsMap['default'];
121
    }
122
123
    public static function ensureTypeIsDefined($type)
124
    {
125
        if (!isset(self::$doctrineTypeToOperatorsMap[$type])) {
126
            throw new \RuntimeException(
127
                'Oops! Type "'.$type.'" is not yet defined.'
128
            );
129
        }
130
    }
131
}
132
133