Passed
Pull Request — master (#7)
by Kris
02:47
created
lib/Query/Update.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -58,15 +58,15 @@  discard block
 block discarded – undo
58 58
     {
59 59
         $columns = array();
60 60
         foreach ($this->parameters as $key => $val) {
61
-            $arg       = ':_' . str_replace('.', '_', $key); 
62
-            $columns[] = $this->escape($key) . ' =' .$arg; 
61
+            $arg       = ':_'.str_replace('.', '_', $key); 
62
+            $columns[] = $this->escape($key).' ='.$arg; 
63 63
             $this->pdoParameters[$arg] = $val; 
64 64
         }
65 65
         foreach ($this->incrementColumns as $key => $val) {
66
-            $columns[] = $this->escape($key) . ' =' . $this->escape($key) . '+' .$val ; 
66
+            $columns[] = $this->escape($key).' ='.$this->escape($key).'+'.$val; 
67 67
         }
68 68
         foreach ($this->decrementColumns as $key => $val) {
69
-            $columns[] = $this->escape($key) . ' =' . $this->escape($key) . '-' .$val ; 
69
+            $columns[] = $this->escape($key).' ='.$this->escape($key).'-'.$val; 
70 70
         }
71 71
         return implode(', ', $columns);
72 72
     }
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
      */
80 80
     public function where(): Where
81 81
     {
82
-        if (!isset($this->where)){
82
+        if (!isset($this->where)) {
83 83
             $this->where = new Query\Where($this, $this->driver);
84 84
         }
85 85
         return $this->where; 
Please login to merge, or discard this patch.
lib/Query/Where.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
      */
165 165
     public function in(string $column, array $values)
166 166
     {
167
-        if (! empty($values)) {
167
+        if (!empty($values)) {
168 168
             $this->addCondition('IN', $this->query->escape($column).' IN ', $column, $values);
169 169
         }
170 170
         return $this->returnFunction();
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
      */
182 182
     public function notIn(string $column, array $values)
183 183
     {
184
-        if (! empty($values)) {
184
+        if (!empty($values)) {
185 185
             $this->addCondition('NOT_IN', $this->query->escape($column).' NOT IN ', $column, $values);
186 186
         }
187 187
         return $this->returnFunction();
Please login to merge, or discard this patch.
lib/Query/QueryBuilder.php 2 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
      */
112 112
     public function escape(string $str): string
113 113
     {
114
-       return $this->driver->escape($str);
114
+        return $this->driver->escape($str);
115 115
     }
116 116
 
117 117
     /**
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
      */
189 189
     public function prepare()
190 190
     {
191
-         try {
191
+            try {
192 192
             // prepare is in a try catch block because sqlite for example could raise 
193 193
             // an exception when prepareing the statement (with invalid table name for example)
194 194
             // when mysql and postres wont. 
@@ -253,9 +253,9 @@  discard block
 block discarded – undo
253 253
         try {
254 254
             // prepare bind execute
255 255
             if (!isset($this->pdoStatement)){
256
-               if (!$this->prepare()){
257
-                   return false;
258
-               }
256
+                if (!$this->prepare()){
257
+                    return false;
258
+                }
259 259
             }
260 260
             $this->bindValues();
261 261
             return $this->pdoStatement ? $this->pdoStatement->execute() : false;
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
             }
204 204
 
205 205
             // register error 
206
-            $this->error['code'] = (int)$e->getCode();
206
+            $this->error['code'] = (int) $e->getCode();
207 207
             $this->error['message'] = $e->getMessage();
208 208
             return false;
209 209
         }
@@ -227,13 +227,13 @@  discard block
 block discarded – undo
227 227
                 $paramType = \PDO::PARAM_STR; // default
228 228
 
229 229
                 if (!isset($val)) {
230
-                    $paramType =  \PDO::PARAM_NULL;
230
+                    $paramType = \PDO::PARAM_NULL;
231 231
                 
232 232
                 } elseif (is_int($val)) {
233
-                    $paramType =  \PDO::PARAM_INT;
233
+                    $paramType = \PDO::PARAM_INT;
234 234
                 
235 235
                 } elseif (is_bool($val)) {
236
-                    $paramType =  \PDO::PARAM_BOOL;
236
+                    $paramType = \PDO::PARAM_BOOL;
237 237
                 } 
238 238
                 
239 239
                 // bind value
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
     {
253 253
         try {
254 254
             // prepare bind execute
255
-            if (!isset($this->pdoStatement)){
256
-               if (!$this->prepare()){
255
+            if (!isset($this->pdoStatement)) {
256
+               if (!$this->prepare()) {
257 257
                    return false;
258 258
                }
259 259
             }
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
             }
269 269
 
270 270
             // register error 
271
-            $this->error['code'] = (int)$e->getCode();
271
+            $this->error['code'] = (int) $e->getCode();
272 272
             $this->error['message'] = $e->getMessage();
273 273
             return false;
274 274
         }
@@ -296,23 +296,23 @@  discard block
 block discarded – undo
296 296
      */
297 297
     protected function fetchOutput(bool $executed, string $outputFormat)
298 298
     {
299
-        switch (strtoupper($outputFormat)){
299
+        switch (strtoupper($outputFormat)) {
300 300
 
301 301
             case Output::ASSOC:    
302
-                return $executed ? $this->pdoStatement->fetchAll(\PDO::FETCH_ASSOC) :  array();
302
+                return $executed ? $this->pdoStatement->fetchAll(\PDO::FETCH_ASSOC) : array();
303 303
 
304 304
             case Output::OBJ:    
305
-                return $executed ? $this->pdoStatement->fetchAll(\PDO::FETCH_OBJ) :    array();
305
+                return $executed ? $this->pdoStatement->fetchAll(\PDO::FETCH_OBJ) : array();
306 306
 
307 307
             case Output::COLUMN:    
308
-                return $executed ? $this->pdoStatement->fetchAll(\PDO::FETCH_COLUMN) :  array();
308
+                return $executed ? $this->pdoStatement->fetchAll(\PDO::FETCH_COLUMN) : array();
309 309
 
310 310
             case Output::JSON:
311
-                $results = $executed ? $this->pdoStatement->fetchAll(\PDO::FETCH_ASSOC) :  array();
311
+                $results = $executed ? $this->pdoStatement->fetchAll(\PDO::FETCH_ASSOC) : array();
312 312
                 return json_encode($results, JSON_NUMERIC_CHECK);   
313 313
 
314 314
             case Output::JSON_PRETTY_PRINT:    
315
-                $results = $executed ? $this->pdoStatement->fetchAll(\PDO::FETCH_ASSOC) :  array();
315
+                $results = $executed ? $this->pdoStatement->fetchAll(\PDO::FETCH_ASSOC) : array();
316 316
                 return json_encode($results, JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK);   
317 317
                 
318 318
             default:
Please login to merge, or discard this patch.
lib/Query/QueryFilter.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
      */
113 113
     private function getArgumentName(string $column): string
114 114
     {
115
-        $arg = ':__' . str_replace('.', '_', $column); 
116
-        return $this->topQuery->sqlParameterExists($arg) ? $arg . uniqid() : $arg;
115
+        $arg = ':__'.str_replace('.', '_', $column); 
116
+        return $this->topQuery->sqlParameterExists($arg) ? $arg.uniqid() : $arg;
117 117
     }
118 118
 
119 119
     /**
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
     {
216 216
         // define argument for each values
217 217
         $valueArgs = array();
218
-        foreach($item['value'] as $value){
218
+        foreach ($item['value'] as $value) {
219 219
             $arg = $this->getArgumentName($item['column']); 
220 220
             $valueArgs[] = $arg;
221 221
 
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
         }
225 225
         
226 226
         //build and return sql
227
-        return $item['sql']. '(' . implode(', ', $valueArgs) .')';
227
+        return $item['sql'].'('.implode(', ', $valueArgs).')';
228 228
     }
229 229
 
230 230
     /**
@@ -237,20 +237,20 @@  discard block
 block discarded – undo
237 237
     {
238 238
         $sql = '';
239 239
         if (!empty($this->conditions)) {
240
-            $sql = ' '. $this->sqlBase  .' ';  // start the SQL WHERE or HAVING clause
241
-            $currentOperator = 'AND';          // current condition operator
240
+            $sql = ' '.$this->sqlBase.' '; // start the SQL WHERE or HAVING clause
241
+            $currentOperator = 'AND'; // current condition operator
242 242
             
243 243
             foreach ($this->conditions as $key => $item) {
244 244
 
245 245
                 // need operator AND or OR, except for the first or if 
246 246
                 // previous item is a begin group item
247
-                $isSqlNeedOperator = $key > 0  && $this->conditions[$key -1]['type'] != 'group_start';
247
+                $isSqlNeedOperator = $key > 0 && $this->conditions[$key-1]['type'] != 'group_start';
248 248
 
249 249
                 switch ($item['type']) {
250 250
                     
251 251
                     case'group_start':
252 252
                         $currentOperator = $item['operator']; // register operator
253
-                        $sql .= '(' ;
253
+                        $sql .= '(';
254 254
                         break;
255 255
                     
256 256
                     case'group_end':
@@ -260,32 +260,32 @@  discard block
 block discarded – undo
260 260
 
261 261
                    case 'NULL':
262 262
                    case 'NOT_NULL':
263
-                        $sql .=  $isSqlNeedOperator ? ' '.$currentOperator.' ' : '';
264
-                        $sql .=  $item['sql'];
263
+                        $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : '';
264
+                        $sql .= $item['sql'];
265 265
                         break;
266 266
 
267 267
                     case 'IN':
268 268
                     case 'NOT_IN':
269
-                        $sql .=  $isSqlNeedOperator ? ' '.$currentOperator.' ' : '';
270
-                        $sql .=  $this->getSqlInOrNotIn($item);
269
+                        $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : '';
270
+                        $sql .= $this->getSqlInOrNotIn($item);
271 271
                         break;
272 272
 
273 273
                     default:
274 274
                         // support for column literral 
275 275
                         if (is_string($item['value']) && 
276
-                            strlen($item['value']) >  strlen(Patabase\Constants::COLUMN_LITERALL) &&
276
+                            strlen($item['value']) > strlen(Patabase\Constants::COLUMN_LITERALL) &&
277 277
                             substr($item['value'], 0, strlen(Patabase\Constants::COLUMN_LITERALL)) === 
278 278
                                                              Patabase\Constants::COLUMN_LITERALL) {
279 279
 
280 280
                             $arg = substr($item['value'], strlen(Patabase\Constants::COLUMN_LITERALL));
281
-                            $sql .=  $isSqlNeedOperator ? ' '.$currentOperator.' ' : '';
282
-                            $sql .=  $item['sql'] . $this->query->escape($arg);
281
+                            $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : '';
282
+                            $sql .= $item['sql'].$this->query->escape($arg);
283 283
 
284
-                        }   else {
284
+                        } else {
285 285
                                 // *normal* value 
286 286
                                 $arg = $this->getArgumentName($item['column']);
287
-                                $sql .=  $isSqlNeedOperator ? ' '.$currentOperator.' ' : '';
288
-                                $sql .=  $item['sql'] . $arg;
287
+                                $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : '';
288
+                                $sql .= $item['sql'].$arg;
289 289
                                
290 290
                                 // set parameters
291 291
                                 $this->topQuery->setSqlParameter($arg, $item['value']); 
Please login to merge, or discard this patch.
lib/Query/CreateTable.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
      */
104 104
     public function column()
105 105
     {
106
-       $this->columns[] = func_get_args();
107
-       return $this;
106
+        $this->columns[] = func_get_args();
107
+        return $this;
108 108
     }
109 109
      
110 110
     /**
@@ -122,15 +122,15 @@  discard block
 block discarded – undo
122 122
      */
123 123
     public function fk(string $fkName, string $srcColumn, string $refTable, string $refColumn, ?string $onUpdate = 'CASCADE', ?string $onDelete = 'RESTRICT')
124 124
     {
125
-       $this->foreignKeys[] = array(
125
+        $this->foreignKeys[] = array(
126 126
             'name'          => $fkName,
127 127
             'src_column'    => $srcColumn,
128 128
             'ref_table'     => $refTable,
129 129
             'ref_column'    => $refColumn,
130 130
             'on_update'     => $onUpdate,
131 131
             'on_delete'     => $onDelete
132
-       );
133
-       return $this;
132
+        );
133
+        return $this;
134 134
     }
135 135
 
136 136
     /**
@@ -233,11 +233,11 @@  discard block
 block discarded – undo
233 233
             // PK ?, UNIQUE ?, NULL? (PK cannot be null), DEFAULT?
234 234
             // AI is handle with sqltype
235 235
             $result[] = trim(implode(' ', [$sqlName, 
236
-                                           $sqlType, 
237
-                                           $isPk ? 'NOT NULL' : $sqlConstraintNullable,
238
-                                           $isPk ? 'PRIMARY KEY' : '',
239
-                                           $sqlConstraintUnique,
240
-                                           $sqlDefault]));
236
+                                            $sqlType, 
237
+                                            $isPk ? 'NOT NULL' : $sqlConstraintNullable,
238
+                                            $isPk ? 'PRIMARY KEY' : '',
239
+                                            $sqlConstraintUnique,
240
+                                            $sqlDefault]));
241 241
         }
242 242
 
243 243
         // FK CONSTRANT
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -142,50 +142,50 @@  discard block
 block discarded – undo
142 142
     private function sqlColumns(): string
143 143
     {
144 144
         $result = array();
145
-        foreach ($this->columns as $col){
145
+        foreach ($this->columns as $col) {
146 146
 
147 147
             // Parse arguments. First item is NAME and second is TYPE
148 148
             $sqlName   = $this->escape($col[0]);
149
-            $sqlType   = $col[1];  //TODO check type
149
+            $sqlType   = $col[1]; //TODO check type
150 150
             
151 151
             // following arguments
152
-            $args       = array_slice($col, 2);
152
+            $args = array_slice($col, 2);
153 153
             $currentIndex       = 0;
154 154
             $defaultValueIndex  = -1;
155 155
 
156
-            $sqlConstraintUnique    = '';       // UNIQUE ?, not by default
157
-            $sqlConstraintNullable  = 'NULL';   // allow null value by default
158
-            $isPk                   = false;    // PRIMARY KEY?
159
-            $sqlDefault             = '';       // DEFAULT VALUE?
156
+            $sqlConstraintUnique    = ''; // UNIQUE ?, not by default
157
+            $sqlConstraintNullable  = 'NULL'; // allow null value by default
158
+            $isPk                   = false; // PRIMARY KEY?
159
+            $sqlDefault             = ''; // DEFAULT VALUE?
160 160
 
161
-            foreach ($args as $arg){
161
+            foreach ($args as $arg) {
162 162
 
163 163
                 // last index was DEFAULT, so the current argument 
164 164
                 // is the value for default contsaint
165
-                if ($currentIndex === $defaultValueIndex){
165
+                if ($currentIndex === $defaultValueIndex) {
166 166
                     
167 167
                     // string
168
-                    if (is_string($arg)){
168
+                    if (is_string($arg)) {
169 169
                             
170 170
                         // escape everything except constants
171
-                        if (in_array(strtoupper($arg), $this->supportedDefaults)){
172
-                            $sqlDefault = 'DEFAULT ' . $arg;
171
+                        if (in_array(strtoupper($arg), $this->supportedDefaults)) {
172
+                            $sqlDefault = 'DEFAULT '.$arg;
173 173
                         } else {
174
-                            $sqlDefault = 'DEFAULT ' . $this->driver->escapeValue($arg);
174
+                            $sqlDefault = 'DEFAULT '.$this->driver->escapeValue($arg);
175 175
                         }
176 176
                         
177 177
                     // int/float are not escaped
178
-                    } elseif (is_int($arg) || is_float($arg)){
179
-                        $sqlDefault = 'DEFAULT ' . $arg;
178
+                    } elseif (is_int($arg) || is_float($arg)) {
179
+                        $sqlDefault = 'DEFAULT '.$arg;
180 180
 
181 181
                     // bool Type
182
-                    } elseif (is_bool($arg)){
183
-                        $sqlDefault = 'DEFAULT ' . ($arg ? 'TRUE' : 'FALSE');                            
182
+                    } elseif (is_bool($arg)) {
183
+                        $sqlDefault = 'DEFAULT '.($arg ? 'TRUE' : 'FALSE');                            
184 184
                     }
185 185
 
186 186
 
187 187
                 } else {
188
-                    switch (strtoupper($arg)){
188
+                    switch (strtoupper($arg)) {
189 189
                         
190 190
                         // NULL  /NOT NULL 
191 191
                         case 'NULL':
@@ -219,14 +219,14 @@  discard block
 block discarded – undo
219 219
                         // DEFAULT
220 220
                         case 'DEFAULT':
221 221
                             // define next index as the DefaultValue index
222
-                            $defaultValueIndex = $currentIndex +1;
222
+                            $defaultValueIndex = $currentIndex+1;
223 223
                             break;
224 224
                     
225 225
                     }
226 226
                 }
227 227
 
228 228
                 // update  current index
229
-                $currentIndex ++;
229
+                $currentIndex++;
230 230
             }
231 231
 
232 232
             // set optional params
@@ -241,8 +241,8 @@  discard block
 block discarded – undo
241 241
         }
242 242
 
243 243
         // FK CONSTRANT
244
-        foreach ($this->foreignKeys as $foreignKey){
245
-            $result[] =  trim(sprintf('CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s(%s)', 
244
+        foreach ($this->foreignKeys as $foreignKey) {
245
+            $result[] = trim(sprintf('CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s(%s)', 
246 246
                             $foreignKey['name'], 
247 247
                             $this->driver->escapeIdentifier($foreignKey['src_column']), 
248 248
                             $this->driver->escapeIdentifier($foreignKey['ref_table']),
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
     public function sql(): string
263 263
     {
264 264
         $sqlTableName = $this->driver->escape($this->tableName);
265
-        $sqlIfNotExists =  $this->isNotExists === true ? 'IF NOT EXISTS' : '';
265
+        $sqlIfNotExists = $this->isNotExists === true ? 'IF NOT EXISTS' : '';
266 266
 
267 267
         return trim(sprintf(
268 268
             'CREATE TABLE %s %s (%s) %s',
Please login to merge, or discard this patch.
lib/Table.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -170,8 +170,8 @@
 block discarded – undo
170 170
      */
171 171
     public function rename(string $newName): bool
172 172
     {
173
-       $result = $this->database->renameTable($this->name, $newName);
174
-       if ($result){
173
+        $result = $this->database->renameTable($this->name, $newName);
174
+        if ($result){
175 175
             $this->name = $newName;
176 176
         }
177 177
         return $result;
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
     {
95 95
         $query = new Query\Update($this->database->getDriver(), $this->name);
96 96
         foreach ($parameters as $key => $val) {
97
-            $query->setValue($key,  $val);
97
+            $query->setValue($key, $val);
98 98
         }
99 99
         return $query;
100 100
     }
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
     {
123 123
         $query = new Query\Insert($this->database->getDriver(), $this->name);
124 124
         foreach ($parameters as $key => $val) {
125
-            $query->setValue($key,  $val);
125
+            $query->setValue($key, $val);
126 126
         }
127 127
         return $query;
128 128
     }
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
     public function rename(string $newName): bool
172 172
     {
173 173
        $result = $this->database->renameTable($this->name, $newName);
174
-       if ($result){
174
+       if ($result) {
175 175
             $this->name = $newName;
176 176
         }
177 177
         return $result;
Please login to merge, or discard this patch.
lib/Server.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
26 26
  *
27 27
  * Represents a connection to SQL database server
28 28
  */
29
- class Server extends Datasource
29
+    class Server extends Datasource
30 30
 {
31 31
     /**
32 32
      * @access protected
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -144,7 +144,7 @@
 block discarded – undo
144 144
     public function dropDatabase(string $databaseName, bool $ifExists = false): bool
145 145
     {
146 146
         $sql = trim(sprintf('DROP DATABASE %s %s', 
147
-            $ifExists === true ? 'IF EXISTS': '',
147
+            $ifExists === true ? 'IF EXISTS' : '',
148 148
             $this->driver->escape($databaseName)));
149 149
         return $this->driver->prepareAndExecuteSql($sql);
150 150
     }
Please login to merge, or discard this patch.
lib/Datasource.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
      * @access protected
41 41
      * @var array               $settings   The driver settings
42 42
      */
43
-    protected $settings= null;
43
+    protected $settings = null;
44 44
 
45 45
     /**
46 46
      * Open a PDO connection
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
      */
147 147
     public function closeConnection(): void
148 148
     {
149
-        if ($this->driver){
149
+        if ($this->driver) {
150 150
             $this->driver->closeConnection();
151 151
             $this->driver = null;
152 152
         }
Please login to merge, or discard this patch.