Completed
Push — master ( d914a1...8bcbeb )
by Adam
05:43
created

Operators   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 25%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 85
ccs 2
cts 8
cp 0.25
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isOperatorValid() 0 4 2
A isOperatorPrepared() 0 3 1
A getOperatorFormat() 0 4 2
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
    public static function isOperatorValid($operator){
77
        if(array_key_exists(strtoupper(strval($operator)), self::OPERATORS)){return true;}
78
        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
    public static function isOperatorPrepared($value){
87
        return self::OPERATORS[strtoupper(strval($value))]['prepared'];
88
    }
89
}
90