@@ -61,7 +61,7 @@ |
||
61 | 61 | */ |
62 | 62 | protected function getArgName(string $column): string |
63 | 63 | { |
64 | - return '_' . str_replace('.', '_', $column); |
|
64 | + return '_' . str_replace('.', '_', $column); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | */ |
62 | 62 | protected function getArgName(string $column): string |
63 | 63 | { |
64 | - return '_' . str_replace('.', '_', $column); |
|
64 | + return '_'.str_replace('.', '_', $column); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | { |
77 | 77 | // Define column parameters |
78 | 78 | $columns = func_get_args(); |
79 | - if (!empty($columns)){ |
|
79 | + if (!empty($columns)) { |
|
80 | 80 | |
81 | 81 | // clear current parameters |
82 | 82 | unset($this->parameters); |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function fn(string $function, string $column, string $operator, $value) |
50 | 50 | { |
51 | - $sql = $function .'('. ($column ? $this->query->escape($column): '') . ') ' . $operator . ' '; |
|
51 | + $sql = $function.'('.($column ? $this->query->escape($column) : '').') '.$operator.' '; |
|
52 | 52 | $this->addCondition($function, $sql, $column, $value); |
53 | 53 | return $this->returnFunction(); |
54 | 54 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function count(string $operator, $value) |
66 | 66 | { |
67 | - $sql = 'COUNT(*) '. $operator. ' '; |
|
67 | + $sql = 'COUNT(*) '.$operator.' '; |
|
68 | 68 | $this->addCondition('COUNT', $sql, 'COUNT', $value); |
69 | 69 | return $this->returnFunction(); |
70 | 70 | } |
@@ -90,12 +90,12 @@ |
||
90 | 90 | */ |
91 | 91 | public function sql(): string |
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 | } |
@@ -61,7 +61,7 @@ |
||
61 | 61 | */ |
62 | 62 | public function where(): Where |
63 | 63 | { |
64 | - if (!isset($this->where)){ |
|
64 | + if (!isset($this->where)) { |
|
65 | 65 | $this->where = new Query\Where($this, $this->driver); |
66 | 66 | } |
67 | 67 | return $this->where; |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | * @access protected |
101 | 101 | * @var QueryBuilder |
102 | 102 | */ |
103 | - protected $topQuery = null; |
|
103 | + protected $topQuery = null; |
|
104 | 104 | |
105 | 105 | /** |
106 | 106 | * Constructor |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | - /** |
|
124 | + /** |
|
125 | 125 | * Parse the columns arguments for the select query |
126 | 126 | * |
127 | 127 | * @access protected |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | */ |
200 | 200 | public function count(string $alias) |
201 | 201 | { |
202 | - $this->columns[] = array( |
|
202 | + $this->columns[] = array( |
|
203 | 203 | 'type' => 'count', |
204 | 204 | 'alias' => $alias |
205 | 205 | ); |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | */ |
217 | 217 | public function sum(string $column, string $alias) |
218 | 218 | { |
219 | - $this->columns[] = array( |
|
219 | + $this->columns[] = array( |
|
220 | 220 | 'type' => 'sum', |
221 | 221 | 'name' => $column, |
222 | 222 | 'alias' => $alias |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | */ |
235 | 235 | public function min(string $column, string $alias) |
236 | 236 | { |
237 | - $this->columns[] = array( |
|
237 | + $this->columns[] = array( |
|
238 | 238 | 'type' => 'min', |
239 | 239 | 'name' => $column, |
240 | 240 | 'alias' => $alias |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | */ |
253 | 253 | public function max(string $column, string $alias) |
254 | 254 | { |
255 | - $this->columns[] = array( |
|
255 | + $this->columns[] = array( |
|
256 | 256 | 'type' => 'max', |
257 | 257 | 'name' => $column, |
258 | 258 | 'alias' => $alias |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | $this->topQuery = $query; |
117 | 117 | |
118 | 118 | // columns arguments |
119 | - if (! empty($args)) { |
|
119 | + if (!empty($args)) { |
|
120 | 120 | $this->parseColumnsArguments($args); |
121 | 121 | } |
122 | 122 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | $cols = (count($args) === 1 && is_array($args[0])) ? $args[0] : $args; |
136 | 136 | |
137 | 137 | // parse column |
138 | - foreach ($cols as $key => $value){ |
|
138 | + foreach ($cols as $key => $value) { |
|
139 | 139 | |
140 | 140 | // Each arg could be a non indexed array of name, or |
141 | 141 | // an indexed array name => alias |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | */ |
406 | 406 | public function where(): Where |
407 | 407 | { |
408 | - if (!isset($this->where)){ |
|
408 | + if (!isset($this->where)) { |
|
409 | 409 | $this->where = new Query\Where($this, $this->driver, $this->topQuery); |
410 | 410 | } |
411 | 411 | return $this->where; |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | */ |
436 | 436 | public function having(): Having |
437 | 437 | { |
438 | - if (!isset($this->having)){ |
|
438 | + if (!isset($this->having)) { |
|
439 | 439 | $this->having = new Query\Having($this, $this->driver, $this->topQuery); |
440 | 440 | } |
441 | 441 | return $this->having; |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | */ |
523 | 523 | public function limit($value) |
524 | 524 | { |
525 | - if (! is_null($value)) { |
|
525 | + if (!is_null($value)) { |
|
526 | 526 | $this->limit = (int) $value; |
527 | 527 | } |
528 | 528 | return $this; |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | */ |
539 | 539 | public function offset($value) |
540 | 540 | { |
541 | - if (! is_null($value)) { |
|
541 | + if (!is_null($value)) { |
|
542 | 542 | $this->offset = (int) $value; |
543 | 543 | } |
544 | 544 | return $this; |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | case 'sub_query': |
111 | 111 | $colsList[] = '('. $val['query']->sql() .') AS '. $this->escape($val['alias']); |
112 | 112 | break; |
113 | - } |
|
113 | + } |
|
114 | 114 | } |
115 | 115 | return $sqlDistinct . implode(', ', $colsList); |
116 | 116 | } |
@@ -158,15 +158,15 @@ discard block |
||
158 | 158 | } |
159 | 159 | |
160 | 160 | return trim(implode(' ', ['SELECT', |
161 | - $this->sqlColumns(), |
|
162 | - $sqlFromTable, |
|
163 | - $sqlJoins, |
|
164 | - $sqlWhere, |
|
165 | - $sqlGroupBy, |
|
166 | - $sqlHaving, |
|
167 | - $sqlOrderBy, |
|
168 | - $sqlLimit, |
|
169 | - $sqlOffset])); |
|
161 | + $this->sqlColumns(), |
|
162 | + $sqlFromTable, |
|
163 | + $sqlJoins, |
|
164 | + $sqlWhere, |
|
165 | + $sqlGroupBy, |
|
166 | + $sqlHaving, |
|
167 | + $sqlOrderBy, |
|
168 | + $sqlLimit, |
|
169 | + $sqlOffset])); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -180,10 +180,10 @@ discard block |
||
180 | 180 | public function getAll(string $outputFormat = 'default') |
181 | 181 | { |
182 | 182 | // execute query |
183 | - $exec = $this->execute(); |
|
183 | + $exec = $this->execute(); |
|
184 | 184 | |
185 | - // format |
|
186 | - $format = ($outputFormat === 'default') ? $this->driver->defaultOutputFormat() : $outputFormat; |
|
185 | + // format |
|
186 | + $format = ($outputFormat === 'default') ? $this->driver->defaultOutputFormat() : $outputFormat; |
|
187 | 187 | |
188 | 188 | // return output |
189 | 189 | return $this->fetchOutput($exec, $format); |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | protected function getArgumentName(string $column): string |
49 | 49 | { |
50 | 50 | $topQuery = $this->topQuery ?: $this; |
51 | - $arg = ':_' . str_replace('.', '_', $column); |
|
52 | - return $topQuery->sqlParameterExists($arg) ? $arg . uniqid() : $arg; |
|
51 | + $arg = ':_'.str_replace('.', '_', $column); |
|
52 | + return $topQuery->sqlParameterExists($arg) ? $arg.uniqid() : $arg; |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -61,22 +61,22 @@ discard block |
||
61 | 61 | private function sqlColumns(): string |
62 | 62 | { |
63 | 63 | // no columns givens select all (SELECT *) |
64 | - if (!count($this->columns) > 0 ) { |
|
64 | + if (!count($this->columns) > 0) { |
|
65 | 65 | return '*'; |
66 | 66 | } |
67 | 67 | |
68 | 68 | // use DISTINCT ? |
69 | - $sqlDistinct = $this->distinct ? 'DISTINCT ': ''; |
|
69 | + $sqlDistinct = $this->distinct ? 'DISTINCT ' : ''; |
|
70 | 70 | |
71 | 71 | // parse columns |
72 | 72 | $colsList = array(); |
73 | - foreach ($this->columns as $val){ |
|
74 | - switch ($val['type']){ |
|
73 | + foreach ($this->columns as $val) { |
|
74 | + switch ($val['type']) { |
|
75 | 75 | |
76 | 76 | // 'classic' column |
77 | 77 | case 'column': |
78 | 78 | $name = $this->escape($val['name']); |
79 | - $alias = isset($val['alias']) ? 'AS '. $this->escape($val['alias']) : ''; |
|
79 | + $alias = isset($val['alias']) ? 'AS '.$this->escape($val['alias']) : ''; |
|
80 | 80 | $colsList[] = trim(sprintf('%s %s', $name, $alias)); |
81 | 81 | break; |
82 | 82 | |
@@ -88,31 +88,31 @@ discard block |
||
88 | 88 | // SUM() column |
89 | 89 | case 'sum': |
90 | 90 | $name = $this->escape($val['name']); |
91 | - $alias = isset($val['alias']) ? ' AS '. $this->escape($val['alias']) : ''; |
|
92 | - $colsList[] = sprintf('SUM(%s)', $name) . $alias; |
|
91 | + $alias = isset($val['alias']) ? ' AS '.$this->escape($val['alias']) : ''; |
|
92 | + $colsList[] = sprintf('SUM(%s)', $name).$alias; |
|
93 | 93 | break; |
94 | 94 | |
95 | 95 | // MIN() column |
96 | 96 | case 'min': |
97 | 97 | $name = $this->escape($val['name']); |
98 | - $alias = isset($val['alias']) ? ' AS '. $this->escape($val['alias']) : ''; |
|
99 | - $colsList[] = sprintf('MIN(%s)', $name) . $alias; |
|
98 | + $alias = isset($val['alias']) ? ' AS '.$this->escape($val['alias']) : ''; |
|
99 | + $colsList[] = sprintf('MIN(%s)', $name).$alias; |
|
100 | 100 | break; |
101 | 101 | |
102 | 102 | // max() column |
103 | 103 | case 'max': |
104 | 104 | $name = $this->escape($val['name']); |
105 | - $alias = isset($val['alias']) ? ' AS '. $this->escape($val['alias']) : ''; |
|
106 | - $colsList[] = sprintf('MAX(%s)', $name) . $alias; |
|
105 | + $alias = isset($val['alias']) ? ' AS '.$this->escape($val['alias']) : ''; |
|
106 | + $colsList[] = sprintf('MAX(%s)', $name).$alias; |
|
107 | 107 | break; |
108 | 108 | |
109 | 109 | // sub query |
110 | 110 | case 'sub_query': |
111 | - $colsList[] = '('. $val['query']->sql() .') AS '. $this->escape($val['alias']); |
|
111 | + $colsList[] = '('.$val['query']->sql().') AS '.$this->escape($val['alias']); |
|
112 | 112 | break; |
113 | 113 | } |
114 | 114 | } |
115 | - return $sqlDistinct . implode(', ', $colsList); |
|
115 | + return $sqlDistinct.implode(', ', $colsList); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -124,26 +124,26 @@ discard block |
||
124 | 124 | public function sql(): string |
125 | 125 | { |
126 | 126 | $topQuery = $this->topQuery ?: $this; |
127 | - $sqlJoins = empty($this->joins) ? '' : implode(' ', $this->joins) ; |
|
128 | - $sqlFromTable = 'FROM '. $this->escape($this->fromTable); |
|
127 | + $sqlJoins = empty($this->joins) ? '' : implode(' ', $this->joins); |
|
128 | + $sqlFromTable = 'FROM '.$this->escape($this->fromTable); |
|
129 | 129 | $sqlWhere = isset($this->where) ? $this->where->sql() : ''; |
130 | 130 | $sqlGroupBy = empty($this->groupBy) ? '' : 'GROUP BY '.implode(', ', $this->escapeList($this->groupBy)); |
131 | 131 | $sqlHaving = isset($this->having) ? $this->having->sql() : ''; |
132 | 132 | |
133 | 133 | // order by |
134 | 134 | $sqlOrderBy = ''; |
135 | - if (! empty($this->orderBy)){ |
|
135 | + if (!empty($this->orderBy)) { |
|
136 | 136 | $sortArgs = []; |
137 | - foreach ($this->orderBy as $item){ |
|
138 | - $sql = $item['column'] ? $this->escape($item['column']) . ' ' : ''; |
|
139 | - $sortArgs[] = $sql . $item['order']; |
|
137 | + foreach ($this->orderBy as $item) { |
|
138 | + $sql = $item['column'] ? $this->escape($item['column']).' ' : ''; |
|
139 | + $sortArgs[] = $sql.$item['order']; |
|
140 | 140 | } |
141 | - $sqlOrderBy = 'ORDER BY ' . implode(', ', $sortArgs); |
|
141 | + $sqlOrderBy = 'ORDER BY '.implode(', ', $sortArgs); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | // limit |
145 | 145 | $sqlLimit = ''; |
146 | - if ($this->limit > 0){ |
|
146 | + if ($this->limit > 0) { |
|
147 | 147 | $argName = $this->getArgumentName('LIMIT'); |
148 | 148 | $topQuery->setSqlParameter($argName, $this->limit); |
149 | 149 | $sqlLimit = 'LIMIT '.$argName; |
@@ -151,10 +151,10 @@ discard block |
||
151 | 151 | |
152 | 152 | // offset |
153 | 153 | $sqlOffset = ''; |
154 | - if ($this->offset > 0){ |
|
154 | + if ($this->offset > 0) { |
|
155 | 155 | $argName = $this->getArgumentName('OFFSET'); |
156 | 156 | $topQuery->setSqlParameter($argName, $this->offset); |
157 | - $sqlOffset = 'OFFSET ' . $argName; |
|
157 | + $sqlOffset = 'OFFSET '.$argName; |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | return trim(implode(' ', ['SELECT', |
@@ -164,7 +164,7 @@ discard block |
||
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 |
||
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(); |
@@ -111,7 +111,7 @@ discard block |
||
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 |
||
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 |
||
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; |
@@ -203,7 +203,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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: |
@@ -103,8 +103,8 @@ discard block |
||
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 |
||
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 |
||
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 |
@@ -142,50 +142,50 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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', |
@@ -170,8 +170,8 @@ |
||
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; |
@@ -94,7 +94,7 @@ discard block |
||
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 |
||
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 |
||
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; |