Operators::getOperatorFormat()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 2.5

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
rs 10
ccs 1
cts 2
cp 0.5
cc 2
nc 2
nop 1
crap 2.5
1
<?php
2
3
namespace DBAL\Modifiers;
4
5
class Operators
6
{
7
    const OPERATORS = array(
8
        '>' => array(
9
            'format' => '> ?',
10
            'prepared' => true
11
        ),
12
        '>=' => array(
13
            'format' => '>= ?',
14
            'prepared' => true
15
        ),
16
        '<' => array(
17
            'format' => '< ?',
18
            'prepared' => true
19
        ),
20
        '<=' => array(
21
            'format' => '<= ?',
22
            'prepared' => true
23
        ),
24
        '!=' => array(
25
            'format' => '!= ?',
26
            'prepared' => true
27
        ),
28
        'LIKE' => array(
29
            'format' => 'LIKE ?',
30
            'prepared' => true
31
        ),
32
        'NOT LIKE' => array(
33
            'format' => 'NOT LIKE ?',
34
            'prepared' => true
35
        ),
36
        'IN' => array(
37
            'format' => 'IN (%s)',
38
            'prepared' => true
39
        ),
40
        'NOT IN' => array(
41
            'format' => 'NOT IN (%s)',
42
            'prepared' => true
43
        ),
44
        'BETWEEN' => array(
45
            'format' => 'BETWEEN ? AND ?',
46
            'prepared' => true
47
        ),
48
        'NOT BETWEEN' => array(
49
            'format' => 'NOT BETWEEN ? AND ?',
50
            'prepared' => true
51
        ),
52
        'IS NULL' => array(
53
            'format' => 'IS NULL',
54
            'prepared' => false
55
        ),
56
        'IS NOT NULL' => array(
57
            'format' => 'IS NOT NULL',
58
            'prepared' => false
59
        )
60
    );
61
    
62
    /**
63
     * Gets the correct formated string for the operator
64
     * @param string $value This should be the operator value
65
     * @return string The string to add to the database will be added
66 2
     */
67 2
    public static function getOperatorFormat($value)
68
    {
69
        if (array_key_exists(strtoupper(strval($value)), self::OPERATORS)) {
70
            return self::OPERATORS[strtoupper($value)]['format'];
71
        }
72
        return '= ?';
73
    }
74
    
75
    /**
76 7
     * Checks to see if the operator is valid
77 7
     * @param string $operator This should be the operator value
78 6
     * @return boolean If the operator exists in the array will return true else returns false
79
     */
80
    public static function isOperatorValid($operator)
81
    {
82
        if (array_key_exists(strtoupper(strval($operator)), self::OPERATORS)) {
83
            return true;
84
        }
85
        return false;
86 1
    }
87 1
    
88
    /**
89
     * Checks to see if a prepared statement value should be added
90
     * @param string $value This should be the operator value
91
     * @return boolean If the operator should be prepared returns true else returns false
92
     */
93
    public static function isOperatorPrepared($value)
94
    {
95
        return self::OPERATORS[strtoupper(strval($value))]['prepared'];
96
    }
97
}
98