Passed
Push — master ( 7b8926...d11737 )
by Adam
10:03 queued 07:07
created

Operators::isOperatorPrepared()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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