Failed Conditions
Push — refactor/improve-static-analys... ( 8da3ef...a7b39f )
by Bas
09:53
created

HandlesAqlGrammar::parameter()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\Aranguent\Query\Concerns;
6
7
trait HandlesAqlGrammar
8
{
9
    /**
10
     * Available predicate operators.
11
     *
12
     * @var array<string, int>
13
     */
14
    protected array $comparisonOperators = [
15
        '=='      => 1,
16
        '!='      => 1,
17
        '<'       => 1,
18
        '>'       => 1,
19
        '<='      => 1,
20
        '>='      => 1,
21
        'IN'      => 1,
22
        'NOT IN'  => 1,
23
        'LIKE'    => 1,
24
        '~'       => 1,
25
        '!~'      => 1,
26
        'ALL =='  => 1,
27
        'ALL !='  => 1,
28
        'ALL <'   => 1,
29
        'ALL >'   => 1,
30
        'ALL <='  => 1,
31
        'ALL >='  => 1,
32
        'ALL IN'  => 1,
33
        'ANY =='  => 1,
34
        'ANY !='  => 1,
35
        'ANY <'   => 1,
36
        'ANY >'   => 1,
37
        'ANY <='  => 1,
38
        'ANY >='  => 1,
39
        'ANY IN'  => 1,
40
        'NONE ==' => 1,
41
        'NONE !=' => 1,
42
        'NONE <'  => 1,
43
        'NONE >'  => 1,
44
        'NONE <=' => 1,
45
        'NONE >=' => 1,
46
        'NONE IN' => 1,
47
    ];
48
49
    /**
50
     * @var array|int[]
51
     */
52
    protected array $arithmeticOperators = [
53
        '+' => 1,
54
        '-' => 1,
55
        '*' => 1,
56
        '/' => 1,
57
        '%' => 1,
58
    ];
59
60
    /**
61
     * @var array|int[]
62
     */
63
    protected array $logicalOperators = [
64
        'AND' => 1,
65
        '&&'  => 1,
66
        'OR'  => 1,
67
        '||'  => 1,
68
        'NOT' => 1,
69
        '!'   => 1,
70
    ];
71
72
    protected string $rangeOperator = '..';
73
74
    /**
75
     * Get the format for database stored dates.
76
     *
77
     * @return string
78
     */
79
    public function getDateFormat(): string
80
    {
81
        return 'Y-m-d\TH:i:s.vp';
82
    }
83
84
    /**
85
     * Get the appropriate query parameter place-holder for a value.
86
     *
87
     * @param  mixed  $value
88
     */
89
    public function parameter($value): string
90
    {
91
        return $this->isExpression($value) ? $this->getValue($value) : (string) $value;
0 ignored issues
show
Bug introduced by
It seems like getValue() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

91
        return $this->isExpression($value) ? $this->/** @scrutinizer ignore-call */ getValue($value) : (string) $value;
Loading history...
Bug introduced by
It seems like isExpression() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

91
        return $this->/** @scrutinizer ignore-call */ isExpression($value) ? $this->getValue($value) : (string) $value;
Loading history...
92
    }
93
94
95
    /**
96
     * Quote the given string literal.
97
     *
98
     * @param  string|array  $value
99
     * @return string
100
     */
101
    public function quoteString($value)
102
    {
103
        if (is_array($value)) {
104
            return implode(', ', array_map([$this, __FUNCTION__], $value));
105
        }
106
107
        return "`$value`";
108
    }
109
110
    /**
111
     * Wrap a single string in keyword identifiers.
112
     *
113
     * @param  string  $value
114
     * @return string
115
     */
116
    protected function wrapValue($value)
117
    {
118
        if ($value !== '*') {
119
            return '`'.str_replace('`', '``', $value).'`';
120
        }
121
122
        return $value;
123
    }
124
125
}
126