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 ( 882132...509951 )
by James Ekow Abaka
02:54
created

QueryEngine   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 91.07%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 0
loc 112
ccs 51
cts 56
cp 0.9107
rs 10
c 0
b 0
f 0

7 Methods

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