Completed
Pull Request — master (#4)
by Kris
03:23 queued 01:34
created
lib/Server.php 1 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 1 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 1 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 1 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/Delete.php 1 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.
lib/Query/Select.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
     protected function getArgumentName($column)
58 58
     {
59 59
         $topQuery = $this->topQuery ?: $this;  
60
-        $arg = ':_' . str_replace('.', '_', $column); 
61
-        return $topQuery->sqlParameterExists($arg) ? $arg . uniqid() : $arg;
60
+        $arg = ':_'.str_replace('.', '_', $column); 
61
+        return $topQuery->sqlParameterExists($arg) ? $arg.uniqid() : $arg;
62 62
     }
63 63
     
64 64
     /**
@@ -70,22 +70,22 @@  discard block
 block discarded – undo
70 70
     private function sqlColumns()
71 71
     {
72 72
         // no columns givens select all (SELECT *)
73
-        if (!count($this->columns) > 0 ) {
73
+        if (!count($this->columns) > 0) {
74 74
             return '*';   
75 75
         }
76 76
 
77 77
         // use DISTINCT ?
78
-        $sqlDistinct    = $this->distinct ? 'DISTINCT ': '';
78
+        $sqlDistinct = $this->distinct ? 'DISTINCT ' : '';
79 79
 
80 80
         // parse columns
81 81
         $colsList = array();
82
-        foreach ($this->columns as $val){
83
-            switch ($val['type']){
82
+        foreach ($this->columns as $val) {
83
+            switch ($val['type']) {
84 84
                    
85 85
                 // 'classic' column
86 86
                 case 'column':
87 87
                     $name       = $this->escape($val['name']);
88
-                    $alias      = isset($val['alias']) ? 'AS '. $this->escape($val['alias']) : '';
88
+                    $alias      = isset($val['alias']) ? 'AS '.$this->escape($val['alias']) : '';
89 89
                     $colsList[] = trim(sprintf('%s %s', $name, $alias));
90 90
                     break;  
91 91
                    
@@ -97,17 +97,17 @@  discard block
 block discarded – undo
97 97
                 // SUM() column
98 98
                 case 'sum':
99 99
                     $name       = $this->escape($val['name']);
100
-                    $alias      = isset($val['alias']) ? 'AS '. $this->escape($val['alias']) : '';
101
-                    $colsList[] = sprintf('SUM(%s)', $name) . $alias;
100
+                    $alias      = isset($val['alias']) ? 'AS '.$this->escape($val['alias']) : '';
101
+                    $colsList[] = sprintf('SUM(%s)', $name).$alias;
102 102
                     break;  
103 103
 
104 104
                 // sub query
105 105
                 case 'sub_query':
106
-                    $colsList[] = '('. $val['query']->sql() .') AS '. $this->escape($val['alias']);
106
+                    $colsList[] = '('.$val['query']->sql().') AS '.$this->escape($val['alias']);
107 107
                     break;
108 108
            }
109 109
         }
110
-        return $sqlDistinct . implode(', ', $colsList);
110
+        return $sqlDistinct.implode(', ', $colsList);
111 111
     }
112 112
     
113 113
     /**
@@ -119,26 +119,26 @@  discard block
 block discarded – undo
119 119
     public function sql()
120 120
     {
121 121
         $topQuery = $this->topQuery ?: $this;  
122
-        $sqlJoins = empty($this->joins) ? '' : implode(' ', $this->joins) ; 
123
-        $sqlFromTable =  'FROM '. $this->escape($this->fromTable);
122
+        $sqlJoins = empty($this->joins) ? '' : implode(' ', $this->joins); 
123
+        $sqlFromTable = 'FROM '.$this->escape($this->fromTable);
124 124
         $sqlWhere = isset($this->where) ? $this->where->sql() : '';
125 125
         $sqlGroupBy = empty($this->groupBy) ? '' : 'GROUP BY '.implode(', ', $this->escapeList($this->groupBy));
126 126
         $sqlHaving = isset($this->having) ? $this->having->sql() : '';
127 127
 
128 128
         // order by
129 129
         $sqlOrderBy = '';
130
-        if (! empty($this->orderBy)){
130
+        if (!empty($this->orderBy)) {
131 131
             $sortArgs = [];
132
-            foreach ($this->orderBy as $item){
133
-                $sql = $item['column'] ? $this->escape($item['column']) . ' ' : '';
134
-                $sortArgs[] = $sql . $item['order'];
132
+            foreach ($this->orderBy as $item) {
133
+                $sql = $item['column'] ? $this->escape($item['column']).' ' : '';
134
+                $sortArgs[] = $sql.$item['order'];
135 135
             }
136
-            $sqlOrderBy = 'ORDER BY ' . implode(', ', $sortArgs);
136
+            $sqlOrderBy = 'ORDER BY '.implode(', ', $sortArgs);
137 137
         }
138 138
 
139 139
         // limit
140 140
         $sqlLimit = '';
141
-        if ($this->limit > 0){
141
+        if ($this->limit > 0) {
142 142
             $argName = $this->getArgumentName('LIMIT');   
143 143
             $topQuery->setSqlParameter($argName, $this->limit); 
144 144
             $sqlLimit = 'LIMIT '.$argName;
@@ -146,10 +146,10 @@  discard block
 block discarded – undo
146 146
 
147 147
         // offset
148 148
         $sqlOffset = '';
149
-        if ($this->offset > 0){
149
+        if ($this->offset > 0) {
150 150
             $argName = $this->getArgumentName('OFFSET');   
151 151
             $topQuery->setSqlParameter($argName, $this->offset); 
152
-            $sqlOffset = 'OFFSET ' . $argName;
152
+            $sqlOffset = 'OFFSET '.$argName;
153 153
         }
154 154
 
155 155
         return trim(implode(' ', ['SELECT', 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
     public function getColumn()
210 210
     {
211 211
         $this->limit(1);
212
-        return $this->execute() ? $this->pdoStatement->fetchColumn() : NULL ;
212
+        return $this->execute() ? $this->pdoStatement->fetchColumn() : NULL;
213 213
     }
214 214
 
215 215
 }
216 216
\ No newline at end of file
Please login to merge, or discard this patch.