Passed
Branch master (ae2c6b)
by Kris
02:37
created
lib/Server.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
  *
31 31
  * Represents a connection to SQL database server
32 32
  */
33
- class Server extends Datasource
33
+    class Server extends Datasource
34 34
 {
35 35
 
36 36
     /**
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -143,7 +143,7 @@
 block discarded – undo
143 143
     public function dropDatabase($databaseName, $ifExists = false)
144 144
     {
145 145
         $sql = trim(sprintf('DROP DATABASE %s %s', 
146
-            $ifExists === true ? 'IF EXISTS': '',
146
+            $ifExists === true ? 'IF EXISTS' : '',
147 147
             $this->driver->escape($databaseName)));
148 148
         return $this->driver->prepareAndExecuteSql($sql);
149 149
     }
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
@@ -168,8 +168,8 @@
 block discarded – undo
168 168
      */
169 169
     public function rename($newName)
170 170
     {
171
-       $result = $this->database->renameTable($this->name, $newName);
172
-       if ($result){
171
+        $result = $this->database->renameTable($this->name, $newName);
172
+        if ($result){
173 173
             $this->name = $newName;
174 174
         }
175 175
         return $result;
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
     {
93 93
         $query = new Query\Update($this->database->getDriver(), $this->name);
94 94
         foreach ($parameters as $key => $val) {
95
-            $query->setValue($key,  $val);
95
+            $query->setValue($key, $val);
96 96
         }
97 97
         return $query;
98 98
     }
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
     {
121 121
         $query = new Query\Insert($this->database->getDriver(), $this->name);
122 122
         foreach ($parameters as $key => $val) {
123
-            $query->setValue($key,  $val);
123
+            $query->setValue($key, $val);
124 124
         }
125 125
         return $query;
126 126
     }
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
     public function rename($newName)
170 170
     {
171 171
        $result = $this->database->renameTable($this->name, $newName);
172
-       if ($result){
172
+       if ($result) {
173 173
             $this->name = $newName;
174 174
         }
175 175
         return $result;
Please login to merge, or discard this patch.
lib/Query/InsertBase.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@
 block discarded – undo
63 63
      */
64 64
     protected function getArgName($column)
65 65
     {
66
-         return '_' . str_replace('.', '_', $column);
66
+            return '_' . str_replace('.', '_', $column);
67 67
     }
68 68
 
69 69
     /**
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
      */
64 64
     protected function getArgName($column)
65 65
     {
66
-         return '_' . str_replace('.', '_', $column);
66
+         return '_'.str_replace('.', '_', $column);
67 67
     }
68 68
 
69 69
     /**
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
     {
79 79
         // Define column parameters
80 80
         $columns = func_get_args();
81
-        if (!empty($columns)){
81
+        if (!empty($columns)) {
82 82
 
83 83
             // clear current parameters
84 84
             unset($this->parameters);
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
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
      */
110 110
     public function column()
111 111
     {
112
-       $this->columns[] = func_get_args();
113
-       return $this;
112
+        $this->columns[] = func_get_args();
113
+        return $this;
114 114
     }
115 115
      
116 116
     /**
@@ -128,15 +128,15 @@  discard block
 block discarded – undo
128 128
      */
129 129
     public function fk($fkName, $srcColumn, $refTable, $refColumn, $onUpdate = 'CASCADE', $onDelete = 'RESTRICT')
130 130
     {
131
-       $this->foreignKeys[] = array(
131
+        $this->foreignKeys[] = array(
132 132
             'name'          => $fkName,
133 133
             'src_column'    => $srcColumn,
134 134
             'ref_table'     => $refTable,
135 135
             'ref_column'    => $refColumn,
136 136
             'on_update'     => $onUpdate,
137 137
             'on_delete'     => $onDelete
138
-       );
139
-       return $this;
138
+        );
139
+        return $this;
140 140
     }
141 141
 
142 142
     /**
@@ -239,11 +239,11 @@  discard block
 block discarded – undo
239 239
             // PK ?, UNIQUE ?, NULL? (PK cannot be null), DEFAULT?
240 240
             // AI is handle with sqltype
241 241
             $result[] = trim(implode(' ', [$sqlName, 
242
-                                           $sqlType, 
243
-                                           $isPk ? 'NOT NULL' : $sqlConstraintNullable,
244
-                                           $isPk ? 'PRIMARY KEY' : '',
245
-                                           $sqlConstraintUnique,
246
-                                           $sqlDefault]));
242
+                                            $sqlType, 
243
+                                            $isPk ? 'NOT NULL' : $sqlConstraintNullable,
244
+                                            $isPk ? 'PRIMARY KEY' : '',
245
+                                            $sqlConstraintUnique,
246
+                                            $sqlDefault]));
247 247
         }
248 248
 
249 249
         // FK CONSTRANT
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -148,50 +148,50 @@  discard block
 block discarded – undo
148 148
     private function sqlColumns()
149 149
     {
150 150
         $result = array();
151
-        foreach ($this->columns as $col){
151
+        foreach ($this->columns as $col) {
152 152
 
153 153
             // Parse arguments. First item is NAME and second is TYPE
154 154
             $sqlName   = $this->escape($col[0]);
155
-            $sqlType   = $col[1];  //TODO check type
155
+            $sqlType   = $col[1]; //TODO check type
156 156
             
157 157
             // following arguments
158
-            $args       = array_slice($col, 2);
158
+            $args = array_slice($col, 2);
159 159
             $currentIndex       = 0;
160 160
             $defaultValueIndex  = -1;
161 161
 
162
-            $sqlConstraintUnique    = '';       // UNIQUE ?, not by default
163
-            $sqlConstraintNullable  = 'NULL';   // allow null value by default
164
-            $isPk                   = false;    // PRIMARY KEY?
165
-            $sqlDefault             = '';       // DEFAULT VALUE?
162
+            $sqlConstraintUnique    = ''; // UNIQUE ?, not by default
163
+            $sqlConstraintNullable  = 'NULL'; // allow null value by default
164
+            $isPk                   = false; // PRIMARY KEY?
165
+            $sqlDefault             = ''; // DEFAULT VALUE?
166 166
 
167
-            foreach ($args as $arg){
167
+            foreach ($args as $arg) {
168 168
 
169 169
                 // last index was DEFAULT, so the current argument 
170 170
                 // is the value for default contsaint
171
-                if ($currentIndex === $defaultValueIndex){
171
+                if ($currentIndex === $defaultValueIndex) {
172 172
                     
173 173
                     // string
174
-                    if (is_string($arg)){
174
+                    if (is_string($arg)) {
175 175
                             
176 176
                         // escape everything except constants
177
-                        if (in_array(strtoupper($arg), $this->supportedDefaults)){
178
-                            $sqlDefault = 'DEFAULT ' . $arg;
177
+                        if (in_array(strtoupper($arg), $this->supportedDefaults)) {
178
+                            $sqlDefault = 'DEFAULT '.$arg;
179 179
                         } else {
180
-                            $sqlDefault = 'DEFAULT ' . $this->driver->escapeValue($arg);
180
+                            $sqlDefault = 'DEFAULT '.$this->driver->escapeValue($arg);
181 181
                         }
182 182
                         
183 183
                     // int/float are not escaped
184
-                    } elseif (is_int($arg) || is_float($arg)){
185
-                        $sqlDefault = 'DEFAULT ' . $arg;
184
+                    } elseif (is_int($arg) || is_float($arg)) {
185
+                        $sqlDefault = 'DEFAULT '.$arg;
186 186
 
187 187
                     // bool Type
188
-                    } elseif (is_bool($arg)){
189
-                        $sqlDefault = 'DEFAULT ' . ($arg ? 'TRUE' : 'FALSE');                            
188
+                    } elseif (is_bool($arg)) {
189
+                        $sqlDefault = 'DEFAULT '.($arg ? 'TRUE' : 'FALSE');                            
190 190
                     }
191 191
 
192 192
 
193 193
                 } else {
194
-                    switch (strtoupper($arg)){
194
+                    switch (strtoupper($arg)) {
195 195
                         
196 196
                         // NULL  /NOT NULL 
197 197
                         case 'NULL':
@@ -225,14 +225,14 @@  discard block
 block discarded – undo
225 225
                         // DEFAULT
226 226
                         case 'DEFAULT':
227 227
                             // define next index as the DefaultValue index
228
-                            $defaultValueIndex = $currentIndex +1;
228
+                            $defaultValueIndex = $currentIndex+1;
229 229
                             break;
230 230
                     
231 231
                     }
232 232
                 }
233 233
 
234 234
                 // update  current index
235
-                $currentIndex ++;
235
+                $currentIndex++;
236 236
             }
237 237
 
238 238
             // set optional params
@@ -247,8 +247,8 @@  discard block
 block discarded – undo
247 247
         }
248 248
 
249 249
         // FK CONSTRANT
250
-        foreach ($this->foreignKeys as $foreignKey){
251
-            $result[] =  trim(sprintf('CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s(%s)', 
250
+        foreach ($this->foreignKeys as $foreignKey) {
251
+            $result[] = trim(sprintf('CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s(%s)', 
252 252
                             $foreignKey['name'], 
253 253
                             $this->driver->escapeIdentifier($foreignKey['src_column']), 
254 254
                             $this->driver->escapeIdentifier($foreignKey['ref_table']),
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
     public function sql()
269 269
     {
270 270
         $sqlTableName = $this->driver->escape($this->tableName);
271
-        $sqlIfNotExists =  $this->isNotExists === true ? 'IF NOT EXISTS' : '';
271
+        $sqlIfNotExists = $this->isNotExists === true ? 'IF NOT EXISTS' : '';
272 272
 
273 273
         return trim(sprintf(
274 274
             'CREATE TABLE %s %s (%s) %s',
Please login to merge, or discard this patch.
lib/Query/Insert.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@
 block discarded – undo
46 46
         foreach ($this->parameters as $key => $val) {
47 47
             $arg = $this->getArgName($key);
48 48
             $columnsNames[]    = $this->escape($key); 
49
-            $columnsValues[]   = ':' . $arg;
49
+            $columnsValues[]   = ':'.$arg;
50 50
         }        
51 51
         return trim(sprintf(
52 52
             'INSERT INTO %s (%s) VALUES (%s)',
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
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
      */
110 110
     public function escape($str)
111 111
     {
112
-       return $this->driver->escape($str);
112
+        return $this->driver->escape($str);
113 113
     }
114 114
 
115 115
     /**
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
      */
187 187
     public function prepare()
188 188
     {
189
-         try {
189
+            try {
190 190
             // prepare is in a try catch block because sqlite for example could raise 
191 191
             // an exception when prepareing the statement (with invalid table name for example)
192 192
             // when mysql and postres wont. 
@@ -251,9 +251,9 @@  discard block
 block discarded – undo
251 251
         try {
252 252
             // prepare bind execute
253 253
             if (!isset($this->pdoStatement)){
254
-               if (!$this->prepare()){
255
-                   return false;
256
-               }
254
+                if (!$this->prepare()){
255
+                    return false;
256
+                }
257 257
             }
258 258
             $this->bindValues();
259 259
             return $this->pdoStatement ? $this->pdoStatement->execute() : false;
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
      *
138 138
      * @return string
139 139
      */
140
-    public function __construct( $driver)
140
+    public function __construct($driver)
141 141
     {
142 142
         $this->driver = $driver;
143 143
     }
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
             }
202 202
 
203 203
             // register error 
204
-            $this->error['code'] = (int)$e->getCode();
204
+            $this->error['code'] = (int) $e->getCode();
205 205
             $this->error['message'] = $e->getMessage();
206 206
             return false;
207 207
         }
@@ -225,13 +225,13 @@  discard block
 block discarded – undo
225 225
                 $paramType = \PDO::PARAM_STR; // default
226 226
 
227 227
                 if (!isset($val)) {
228
-                    $paramType =  \PDO::PARAM_NULL;
228
+                    $paramType = \PDO::PARAM_NULL;
229 229
                 
230 230
                 } elseif (is_int($val)) {
231
-                    $paramType =  \PDO::PARAM_INT;
231
+                    $paramType = \PDO::PARAM_INT;
232 232
                 
233 233
                 } elseif (is_bool($val)) {
234
-                    $paramType =  \PDO::PARAM_BOOL;
234
+                    $paramType = \PDO::PARAM_BOOL;
235 235
                 } 
236 236
                 
237 237
                 // bind value
@@ -250,8 +250,8 @@  discard block
 block discarded – undo
250 250
     {
251 251
         try {
252 252
             // prepare bind execute
253
-            if (!isset($this->pdoStatement)){
254
-               if (!$this->prepare()){
253
+            if (!isset($this->pdoStatement)) {
254
+               if (!$this->prepare()) {
255 255
                    return false;
256 256
                }
257 257
             }
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
             }
267 267
 
268 268
             // register error 
269
-            $this->error['code'] = (int)$e->getCode();
269
+            $this->error['code'] = (int) $e->getCode();
270 270
             $this->error['message'] = $e->getMessage();
271 271
             return false;
272 272
         }
@@ -296,22 +296,22 @@  discard block
 block discarded – undo
296 296
      */
297 297
     protected static function fetchOutput(QueryBuilder $query, $executed, $ouputFormat)
298 298
     {
299
-        switch ($ouputFormat){
299
+        switch ($ouputFormat) {
300 300
             case 'asso':    
301
-                return $executed ? $query->pdoStatement->fetchAll(\PDO::FETCH_ASSOC) :  array();
301
+                return $executed ? $query->pdoStatement->fetchAll(\PDO::FETCH_ASSOC) : array();
302 302
 
303 303
             case 'obj':     
304
-                return $executed ? $query->pdoStatement->fetchAll(\PDO::FETCH_OBJ) :    NULL;
304
+                return $executed ? $query->pdoStatement->fetchAll(\PDO::FETCH_OBJ) : NULL;
305 305
 
306 306
             case 'cols':     
307
-                return $executed ? $query->pdoStatement->fetchAll(\PDO::FETCH_COLUMN) :  array();
307
+                return $executed ? $query->pdoStatement->fetchAll(\PDO::FETCH_COLUMN) : array();
308 308
 
309 309
             case 'json':    
310
-                $results = $executed ? $query->pdoStatement->fetchAll(\PDO::FETCH_ASSOC) :  array();
310
+                $results = $executed ? $query->pdoStatement->fetchAll(\PDO::FETCH_ASSOC) : array();
311 311
                 return json_encode($results, JSON_NUMERIC_CHECK);   
312 312
 
313 313
             case 'jsonpp':    
314
-                $results = $executed ? $query->pdoStatement->fetchAll(\PDO::FETCH_ASSOC) :  array();
314
+                $results = $executed ? $query->pdoStatement->fetchAll(\PDO::FETCH_ASSOC) : array();
315 315
                 return json_encode($results, JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK);   
316 316
                 
317 317
             default:
Please login to merge, or discard this patch.
lib/Query/Delete.php 2 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -90,12 +90,12 @@
 block discarded – undo
90 90
      */
91 91
     public function sql()
92 92
     {
93
-       // Build sql where and escape table name
94
-       $sqlWhere = (isset($this->where)) ? $this->where->sql() : '';
95
-       $sqlTableName = $this->escape($this->tableName);
93
+        // Build sql where and escape table name
94
+        $sqlWhere = (isset($this->where)) ? $this->where->sql() : '';
95
+        $sqlTableName = $this->escape($this->tableName);
96 96
        
97
-       // DELETE query
98
-       return trim(sprintf('DELETE FROM %s %s', 
97
+        // DELETE query
98
+        return trim(sprintf('DELETE FROM %s %s', 
99 99
                             $sqlTableName, 
100 100
                             $sqlWhere));
101 101
     }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
      */
65 65
     public function where()
66 66
     {
67
-        if (!isset($this->where)){
67
+        if (!isset($this->where)) {
68 68
             $this->where = new Query\Where($this, $this->driver);
69 69
         }
70 70
         return $this->where; 
Please login to merge, or discard this patch.
lib/Query/QueryBase.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@
 block discarded – undo
58 58
      */
59 59
     public function errorCode()
60 60
     {
61
-        return !empty($this->error) ? $this->error['code']: null;
61
+        return !empty($this->error) ? $this->error['code'] : null;
62 62
     }
63 63
 
64 64
     /**
Please login to merge, or discard this patch.
lib/Query/Having.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
      */
54 54
     public function fn($function, $column, $operator, $value)
55 55
     {
56
-        $sql = $function .'('. ($column ? $this->query->escape($column): '') . ') ' . $operator . ' ';
56
+        $sql = $function.'('.($column ? $this->query->escape($column) : '').') '.$operator.' ';
57 57
         $this->addCondition($function, $sql, $column, $value);
58 58
         return $this->returnFunction();
59 59
     }
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
      */
70 70
     public function count($operator, $value)
71 71
     {
72
-        $sql = 'COUNT(*) '. $operator. ' ';
72
+        $sql = 'COUNT(*) '.$operator.' ';
73 73
         $this->addCondition('COUNT', $sql, 'COUNT', $value);
74 74
         return $this->returnFunction();
75 75
     }
Please login to merge, or discard this patch.