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.
Completed
Push — master ( be1647...f30965 )
by James Ekow Abaka
06:37
created

QueryEngine   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 82.14%

Importance

Changes 0
Metric Value
wmc 11
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 104
ccs 46
cts 56
cp 0.8214
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setDriver() 0 3 1
A getInsertQuery() 0 15 2
A getBulkUpdateQuery() 0 13 2
A getUpdateQuery() 0 22 3
A getSelectQuery() 0 11 1
A getCountQuery() 0 7 1
A getDeleteQuery() 0 7 1
1
<?php
2
3
namespace ntentan\nibii;
4
5
class QueryEngine {
6
7
    private $db;
8
9 31
    public function setDriver($driver) {
10 31
        $this->db = $driver;
11 31
    }
12
13
    /**
14
     * Generates an SQL insert query string for the model based on the fields
15
     * currently stored in the model.
16
     * 
17
     * @param RecordWrapper $model
18
     * @return string
19
     */
20 6
    public function getInsertQuery($model) {
21 6
        $data = $model->getData();
22 6
        $table = $model->getDBStoreInformation()['quoted_table'];
23 6
        $fields = array_keys($data[0]);
24 6
        $quotedFields = [];
25 6
        $valueFields = [];
26
27 6
        foreach ($fields as $field) {
28 6
            $quotedFields[] = $this->db->quoteIdentifier($field);
29 6
            $valueFields[] = ":{$field}";
30
        }
31
32 6
        return "INSERT INTO " . $table .
33 6
            " (" . implode(", ", $quotedFields) . ") VALUES (" . implode(', ', $valueFields) . ")";
34
    }
35
36 6
    public function getBulkUpdateQuery($data, $parameters) {
37 6
        $updateData = [];
38 6
        foreach ($data as $field => $value) {
39 6
            $updateData[] = "{$this->db->quoteIdentifier($field)} = :$field";
40
        }
41
42 6
        return sprintf(
43 6
            "UPDATE %s SET %s %s", 
44 6
            $parameters->getTable(), 
45 6
            implode(', ', $updateData), 
46 6
            $parameters->getWhereClause()
47
        );
48
    }
49
50
    /**
51
     * Generates an SQL update query string for the model based on the data
52
     * currently stored in the model.
53
     * 
54
     * @param RecordWrapper $model
55
     * @return string
56
     */    
57 2
    public function getUpdateQuery($model) {
58 2
        $data = $model->getData();
59 2
        $fields = array_keys($data[0]);
60 2
        $valueFields = [];
61 2
        $conditions = [];
62 2
        $primaryKey = $model->getDescription()->getPrimaryKey();
63
64 2
        foreach ($fields as $field) {
65 2
            $quotedField = $this->db->quoteIdentifier($field);
66
67 2
            if (array_search($field, $primaryKey) !== false) {
68 2
                $conditions[] = "{$quotedField} = :{$field}";
69
            } else {
70 2
                $valueFields[] = "{$quotedField} = :{$field}";
71
            }
72
        }
73
74
        return "UPDATE " .
75 2
            $model->getDBStoreInformation()['quoted_table'] .
76 2
            " SET " . implode(', ', $valueFields) .
77 2
            " WHERE " . implode(' AND ', $conditions);
78
    }
79
80 25
    public function getSelectQuery($parameters) {
81 25
        return sprintf(
82 25
            "SELECT %s FROM %s%s%s%s%s", 
83 25
            $parameters->getFields(), 
84 25
            $parameters->getTable(), 
85 25
            $parameters->getWhereClause(), 
86 25
            $parameters->getSorts(), 
87 25
            $parameters->getLimit(), 
88 25
            $parameters->getOffset()
89
        );
90
    }
91
92
    public function getCountQuery($parameters) {
93
        return sprintf(
94
            "SELECT count(*) as count FROM %s%s", 
95
            $parameters->getTable(), 
96
            $parameters->getWhereClause()
97
        );
98
    }
99
100
    public function getDeleteQuery($parameters) {
101
        return sprintf(
102
            "DELETE FROM %s%s", 
103
            $parameters->getTable(), 
104
            $parameters->getWhereClause()
105
        );
106
    }
107
108
}
109