@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | $this->topQuery = $query; |
121 | 121 | |
122 | 122 | // columns arguments |
123 | - if (! empty($args)) { |
|
123 | + if (!empty($args)) { |
|
124 | 124 | $this->parseColumnsArguments($args); |
125 | 125 | } |
126 | 126 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $cols = (count($args) === 1 && is_array($args[0])) ? $args[0] : $args; |
140 | 140 | |
141 | 141 | // parse column |
142 | - foreach ($cols as $key => $value){ |
|
142 | + foreach ($cols as $key => $value) { |
|
143 | 143 | |
144 | 144 | // Each arg could be a non indexed array of name, or |
145 | 145 | // an indexed array name => alias |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | */ |
374 | 374 | public function where() |
375 | 375 | { |
376 | - if (!isset($this->where)){ |
|
376 | + if (!isset($this->where)) { |
|
377 | 377 | $this->where = new Query\Where($this, $this->driver, $this->topQuery); |
378 | 378 | } |
379 | 379 | return $this->where; |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | */ |
401 | 401 | public function having() |
402 | 402 | { |
403 | - if (!isset($this->having)){ |
|
403 | + if (!isset($this->having)) { |
|
404 | 404 | $this->having = new Query\Having($this, $this->driver, $this->topQuery); |
405 | 405 | } |
406 | 406 | return $this->having; |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | */ |
488 | 488 | public function limit($value) |
489 | 489 | { |
490 | - if (! is_null($value)) { |
|
490 | + if (!is_null($value)) { |
|
491 | 491 | $this->limit = (int) $value; |
492 | 492 | } |
493 | 493 | return $this; |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | */ |
504 | 504 | public function offset($value) |
505 | 505 | { |
506 | - if (! is_null($value)) { |
|
506 | + if (!is_null($value)) { |
|
507 | 507 | $this->offset = (int) $value; |
508 | 508 | } |
509 | 509 | return $this; |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | */ |
169 | 169 | public function in($column, array $values) |
170 | 170 | { |
171 | - if (! empty($values)) { |
|
171 | + if (!empty($values)) { |
|
172 | 172 | $this->addCondition('IN', $this->query->escape($column).' IN ', $column, $values); |
173 | 173 | } |
174 | 174 | return $this->returnFunction(); |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | */ |
186 | 186 | public function notIn($column, array $values) |
187 | 187 | { |
188 | - if (! empty($values)) { |
|
188 | + if (!empty($values)) { |
|
189 | 189 | $this->addCondition('NOT_IN', $this->query->escape($column).' NOT IN ', $column, $values); |
190 | 190 | } |
191 | 191 | return $this->returnFunction(); |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | */ |
117 | 117 | private function getArgumentName($column) |
118 | 118 | { |
119 | - $arg = ':__' . str_replace('.', '_', $column); |
|
120 | - return $this->topQuery->sqlParameterExists($arg) ? $arg . uniqid() : $arg; |
|
119 | + $arg = ':__'.str_replace('.', '_', $column); |
|
120 | + return $this->topQuery->sqlParameterExists($arg) ? $arg.uniqid() : $arg; |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | { |
220 | 220 | // define argument for each values |
221 | 221 | $valueArgs = array(); |
222 | - foreach($item['value'] as $value){ |
|
222 | + foreach ($item['value'] as $value) { |
|
223 | 223 | $arg = $this->getArgumentName($item['column']); |
224 | 224 | $valueArgs[] = $arg; |
225 | 225 | |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | } |
229 | 229 | |
230 | 230 | //build and return sql |
231 | - return $item['sql']. '(' . implode(', ', $valueArgs) .')'; |
|
231 | + return $item['sql'].'('.implode(', ', $valueArgs).')'; |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
@@ -241,20 +241,20 @@ discard block |
||
241 | 241 | { |
242 | 242 | $sql = ''; |
243 | 243 | if (!empty($this->conditions)) { |
244 | - $sql = ' '. $this->sqlBase .' '; // start the SQL WHERE or HAVING clause |
|
245 | - $currentOperator = 'AND'; // current condition operator |
|
244 | + $sql = ' '.$this->sqlBase.' '; // start the SQL WHERE or HAVING clause |
|
245 | + $currentOperator = 'AND'; // current condition operator |
|
246 | 246 | |
247 | 247 | foreach ($this->conditions as $key => $item) { |
248 | 248 | |
249 | 249 | // need operator AND or OR, except for the first or if |
250 | 250 | // previous item is a begin group item |
251 | - $isSqlNeedOperator = $key > 0 && $this->conditions[$key -1]['type'] != 'group_start'; |
|
251 | + $isSqlNeedOperator = $key > 0 && $this->conditions[$key-1]['type'] != 'group_start'; |
|
252 | 252 | |
253 | 253 | switch ($item['type']) { |
254 | 254 | |
255 | 255 | case'group_start': |
256 | 256 | $currentOperator = $item['operator']; // register operator |
257 | - $sql .= '(' ; |
|
257 | + $sql .= '('; |
|
258 | 258 | break; |
259 | 259 | |
260 | 260 | case'group_end': |
@@ -264,32 +264,32 @@ discard block |
||
264 | 264 | |
265 | 265 | case 'NULL': |
266 | 266 | case 'NOT_NULL': |
267 | - $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
268 | - $sql .= $item['sql']; |
|
267 | + $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
268 | + $sql .= $item['sql']; |
|
269 | 269 | break; |
270 | 270 | |
271 | 271 | case 'IN': |
272 | 272 | case 'NOT_IN': |
273 | - $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
274 | - $sql .= $this->getSqlInOrNotIn($item); |
|
273 | + $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
274 | + $sql .= $this->getSqlInOrNotIn($item); |
|
275 | 275 | break; |
276 | 276 | |
277 | 277 | default: |
278 | 278 | // support for column literral |
279 | 279 | if (is_string($item['value']) && |
280 | - strlen($item['value']) > strlen(Patabase\Constants::COLUMN_LITERALL) && |
|
280 | + strlen($item['value']) > strlen(Patabase\Constants::COLUMN_LITERALL) && |
|
281 | 281 | substr($item['value'], 0, strlen(Patabase\Constants::COLUMN_LITERALL)) === |
282 | 282 | Patabase\Constants::COLUMN_LITERALL) { |
283 | 283 | |
284 | 284 | $arg = substr($item['value'], strlen(Patabase\Constants::COLUMN_LITERALL)); |
285 | - $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
286 | - $sql .= $item['sql'] . $this->query->escape($arg); |
|
285 | + $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
286 | + $sql .= $item['sql'].$this->query->escape($arg); |
|
287 | 287 | |
288 | - } else { |
|
288 | + } else { |
|
289 | 289 | // *normal* value |
290 | 290 | $arg = $this->getArgumentName($item['column']); |
291 | - $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
292 | - $sql .= $item['sql'] . $arg; |
|
291 | + $sql .= $isSqlNeedOperator ? ' '.$currentOperator.' ' : ''; |
|
292 | + $sql .= $item['sql'].$arg; |
|
293 | 293 | |
294 | 294 | // set parameters |
295 | 295 | $this->topQuery->setSqlParameter($arg, $item['value']); |
@@ -63,15 +63,15 @@ discard block |
||
63 | 63 | { |
64 | 64 | $columns = array(); |
65 | 65 | foreach ($this->parameters as $key => $val) { |
66 | - $arg = ':_' . str_replace('.', '_', $key); |
|
67 | - $columns[] = $this->escape($key) . ' =' .$arg; |
|
66 | + $arg = ':_'.str_replace('.', '_', $key); |
|
67 | + $columns[] = $this->escape($key).' ='.$arg; |
|
68 | 68 | $this->pdoParameters[$arg] = $val; |
69 | 69 | } |
70 | 70 | foreach ($this->incrementColumns as $key => $val) { |
71 | - $columns[] = $this->escape($key) . ' =' . $this->escape($key) . '+' .$val ; |
|
71 | + $columns[] = $this->escape($key).' ='.$this->escape($key).'+'.$val; |
|
72 | 72 | } |
73 | 73 | foreach ($this->decrementColumns as $key => $val) { |
74 | - $columns[] = $this->escape($key) . ' =' . $this->escape($key) . '-' .$val ; |
|
74 | + $columns[] = $this->escape($key).' ='.$this->escape($key).'-'.$val; |
|
75 | 75 | } |
76 | 76 | return implode(', ', $columns); |
77 | 77 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function where() |
86 | 86 | { |
87 | - if (!isset($this->where)){ |
|
87 | + if (!isset($this->where)) { |
|
88 | 88 | $this->where = new Query\Where($this, $this->driver); |
89 | 89 | } |
90 | 90 | return $this->where; |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @access protected |
44 | 44 | * @var array $settings The driver settings |
45 | 45 | */ |
46 | - protected $settings= null; |
|
46 | + protected $settings = null; |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * Open a PDO connection |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function closeConnection() |
151 | 151 | { |
152 | - if ($this->driver){ |
|
152 | + if ($this->driver) { |
|
153 | 153 | $this->driver->closeConnection(); |
154 | 154 | $this->driver = null; |
155 | 155 | } |
@@ -257,7 +257,7 @@ |
||
257 | 257 | */ |
258 | 258 | public function beginTransaction() |
259 | 259 | { |
260 | - if (! $this->inTransaction()) { |
|
260 | + if (!$this->inTransaction()) { |
|
261 | 261 | $this->getConnection()->beginTransaction(); |
262 | 262 | } |
263 | 263 | } |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function createConnection(array $settings) |
102 | 102 | { |
103 | - $port = !empty($settings['port']) ? ';port='.$settings['port'] : ''; |
|
104 | - $dbname = !empty($settings['database']) ? ';dbname='.$settings['database'] : ''; |
|
105 | - $dsn = 'pgsql:host='.$settings['hostname'] .$port .$dbname ; |
|
103 | + $port = !empty($settings['port']) ? ';port='.$settings['port'] : ''; |
|
104 | + $dbname = !empty($settings['database']) ? ';dbname='.$settings['database'] : ''; |
|
105 | + $dsn = 'pgsql:host='.$settings['hostname'].$port.$dbname; |
|
106 | 106 | |
107 | 107 | $this->pdo = new \PDO( |
108 | 108 | $dsn, |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | { |
209 | 209 | $sql = 'SELECT COUNT(*) FROM pg_database WHERE datname = :dbName'; |
210 | 210 | $query = $this->pdo->prepare($sql); |
211 | - $query->bindValue(':dbName', $databaseName, \PDO::PARAM_STR); |
|
211 | + $query->bindValue(':dbName', $databaseName, \PDO::PARAM_STR); |
|
212 | 212 | $query->execute(); |
213 | 213 | return (bool) $query->fetchColumn(); |
214 | 214 | } |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | { |
228 | 228 | $sql = trim(sprintf('CREATE DATABASE %s %s TEMPLATE %s', |
229 | 229 | $this->escape($databaseName), |
230 | - isset($owner) ? 'OWNER '. $this->escape($owner) : '', |
|
230 | + isset($owner) ? 'OWNER '.$this->escape($owner) : '', |
|
231 | 231 | $template |
232 | 232 | )); |
233 | 233 | return $this->prepareAndExecuteSql($sql); |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | { |
247 | 247 | $sql = trim(sprintf('CREATE USER %s PASSWORD %s', |
248 | 248 | $this->escape($userName), |
249 | - "'" . $userPassword ."'" |
|
249 | + "'".$userPassword."'" |
|
250 | 250 | )); |
251 | 251 | return $this->prepareAndExecuteSql($sql); |
252 | 252 | } |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | public function dropUser($userName, $ifExists = false) |
264 | 264 | { |
265 | 265 | $sql = trim(sprintf('DROP USER %s %s', |
266 | - $ifExists === true ? 'IF EXISTS': '', |
|
266 | + $ifExists === true ? 'IF EXISTS' : '', |
|
267 | 267 | $this->escape($userName) |
268 | 268 | )); |
269 | 269 | return $this->prepareAndExecuteSql($sql); |
@@ -164,15 +164,15 @@ discard block |
||
164 | 164 | { |
165 | 165 | // check for required attributes |
166 | 166 | foreach ($this->dsnAttributes as $attribute) { |
167 | - if (! array_key_exists($attribute, $settings)) { |
|
167 | + if (!array_key_exists($attribute, $settings)) { |
|
168 | 168 | throw new Exception\MissingArgException('This configuration parameter is missing: "'.$attribute.'"'); |
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | 172 | // defaut output format |
173 | - if (array_key_exists('default_output_format', $settings)){ |
|
173 | + if (array_key_exists('default_output_format', $settings)) { |
|
174 | 174 | $format = $settings['default_output_format']; |
175 | - if (!in_array($format, $this->outputFormats)){ |
|
175 | + if (!in_array($format, $this->outputFormats)) { |
|
176 | 176 | throw new Exception\InvalidArgException('The default output format specified is invalid.'); |
177 | 177 | } |
178 | 178 | $this->defaultOutputFormat = $format; |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | |
181 | 181 | $this->createConnection($settings); |
182 | 182 | $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
183 | - $this->hostname = array_key_exists('hostname',$settings) && $settings['hostname'] ? $settings['hostname'] : ''; |
|
183 | + $this->hostname = array_key_exists('hostname', $settings) && $settings['hostname'] ? $settings['hostname'] : ''; |
|
184 | 184 | $this->driverName = $settings['driver']; |
185 | 185 | } |
186 | 186 | |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | */ |
215 | 215 | public function errorCode() |
216 | 216 | { |
217 | - return !empty($this->error) ? $this->error['code']: ''; |
|
217 | + return !empty($this->error) ? $this->error['code'] : ''; |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | return $pdoStatement->execute($parameters); |
259 | 259 | } catch (\PDOException $e) { |
260 | 260 | // register error |
261 | - $this->error['code'] = (int)$e->getCode(); |
|
261 | + $this->error['code'] = (int) $e->getCode(); |
|
262 | 262 | $this->error['message'] = $e->getMessage(); |
263 | 263 | return false; |
264 | 264 | } |
@@ -41,7 +41,7 @@ |
||
41 | 41 | public function __construct(array $settings, $isServerConnection = false) |
42 | 42 | { |
43 | 43 | // remove database attribute for server connection |
44 | - if ($isServerConnection){ |
|
44 | + if ($isServerConnection) { |
|
45 | 45 | $dbKey = array_search('database', $this->dsnAttributes); |
46 | 46 | if ($dbKey !== false) { |
47 | 47 | unset($this->dsnAttributes[$dbKey]); |