@@ -42,16 +42,16 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function current() { |
| 44 | 44 | $row = $this->currentItem; |
| 45 | - if($this->preserveTypes) { |
|
| 45 | + if ($this->preserveTypes) { |
|
| 46 | 46 | $columnDefinitions = FieldTypeProvider::getFieldTypes($this->getStmt()); |
| 47 | 47 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
| 48 | 48 | } |
| 49 | 49 | $callback = $this->callback; |
| 50 | - if($callback !== null) { |
|
| 50 | + if ($callback !== null) { |
|
| 51 | 51 | $result = $callback($row); |
| 52 | - if($result instanceof DBIgnoreRow) { |
|
| 52 | + if ($result instanceof DBIgnoreRow) { |
|
| 53 | 53 | // Do nothing in this case |
| 54 | - } elseif($result !== null) { |
|
| 54 | + } elseif ($result !== null) { |
|
| 55 | 55 | return $result; |
| 56 | 56 | } else { |
| 57 | 57 | return $row; |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | public function valid() { |
| 81 | 81 | $result = !!$this->currentItem; |
| 82 | - if(!$result) { |
|
| 82 | + if (!$result) { |
|
| 83 | 83 | $this->closeCursor(); |
| 84 | 84 | } |
| 85 | 85 | return $result; |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | /** |
| 89 | 89 | */ |
| 90 | 90 | public function rewind() { |
| 91 | - if($this->stmt !== null) { |
|
| 91 | + if ($this->stmt !== null) { |
|
| 92 | 92 | throw new RuntimeException("It's not possible to rewind this iterator"); |
| 93 | 93 | } |
| 94 | 94 | $this->stmt = call_user_func($this->statementFactory); |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | * @return QueryStatement |
| 101 | 101 | */ |
| 102 | 102 | private function getStmt() { |
| 103 | - if($this->stmt === null) { |
|
| 103 | + if ($this->stmt === null) { |
|
| 104 | 104 | $this->rewind(); |
| 105 | 105 | } |
| 106 | 106 | return $this->stmt; |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | /** |
| 110 | 110 | */ |
| 111 | 111 | private function closeCursor() { |
| 112 | - if($this->stmt instanceof QueryStatement) { |
|
| 112 | + if ($this->stmt instanceof QueryStatement) { |
|
| 113 | 113 | $this->stmt->closeCursor(); |
| 114 | 114 | } |
| 115 | 115 | $this->stmt = null; |
@@ -16,8 +16,8 @@ |
||
| 16 | 16 | * @return $this |
| 17 | 17 | */ |
| 18 | 18 | public function having($expression, $_ = null) { |
| 19 | - if($expression instanceof OptionalExpression) { |
|
| 20 | - if($expression->isValid()) { |
|
| 19 | + if ($expression instanceof OptionalExpression) { |
|
| 20 | + if ($expression->isValid()) { |
|
| 21 | 21 | $this->having[] = [$expression->getExpression(), $expression->getValue()]; |
| 22 | 22 | } |
| 23 | 23 | } else { |
@@ -16,8 +16,8 @@ |
||
| 16 | 16 | * @return $this |
| 17 | 17 | */ |
| 18 | 18 | public function where($expression, $_ = null) { |
| 19 | - if($expression instanceof OptionalExpression) { |
|
| 20 | - if($expression->isValid()) { |
|
| 19 | + if ($expression instanceof OptionalExpression) { |
|
| 20 | + if ($expression->isValid()) { |
|
| 21 | 21 | $this->where[] = [$expression->getExpression(), $expression->getValue()]; |
| 22 | 22 | } |
| 23 | 23 | } else { |
@@ -30,10 +30,10 @@ |
||
| 30 | 30 | * @return Select|null |
| 31 | 31 | */ |
| 32 | 32 | public function get($tableName) { |
| 33 | - if($this->has($tableName)) { |
|
| 33 | + if ($this->has($tableName)) { |
|
| 34 | 34 | $table = $this->virtualTables[(string) $tableName]; |
| 35 | - if($table instanceof \Closure) { |
|
| 36 | - if($tableName instanceof VirtualTable) { |
|
| 35 | + if ($table instanceof \Closure) { |
|
| 36 | + if ($tableName instanceof VirtualTable) { |
|
| 37 | 37 | $params = $tableName->getParams(); |
| 38 | 38 | return call_user_func($table, $params); |
| 39 | 39 | } |
@@ -13,36 +13,36 @@ |
||
| 13 | 13 | * @return string |
| 14 | 14 | */ |
| 15 | 15 | protected function buildTableName($alias, $name) { |
| 16 | - if(is_object($name) && !($name instanceof VirtualTable)) { |
|
| 16 | + if (is_object($name) && !($name instanceof VirtualTable)) { |
|
| 17 | 17 | $name = (string) $name; |
| 18 | 18 | $lines = explode("\n", $name); |
| 19 | - foreach($lines as &$line) { |
|
| 19 | + foreach ($lines as &$line) { |
|
| 20 | 20 | $line = "\t{$line}"; |
| 21 | 21 | } |
| 22 | 22 | $name = join("\n", $lines); |
| 23 | - $name = '(' . trim(rtrim(trim($name), ';')) . ')'; |
|
| 23 | + $name = '('.trim(rtrim(trim($name), ';')).')'; |
|
| 24 | 24 | } |
| 25 | - if(is_array($name)) { |
|
| 25 | + if (is_array($name)) { |
|
| 26 | 26 | $parts = []; |
| 27 | - foreach($name as $index => $bucket) { |
|
| 28 | - if(ctype_digit((string) $index) && is_scalar($bucket)) { |
|
| 27 | + foreach ($name as $index => $bucket) { |
|
| 28 | + if (ctype_digit((string) $index) && is_scalar($bucket)) { |
|
| 29 | 29 | $parts[] = "SELECT {$this->db()->quote($bucket)} AS {$this->db()->quoteField('value')}"; |
| 30 | 30 | } else { |
| 31 | 31 | $values = []; |
| 32 | - foreach($bucket as $field => $value) { |
|
| 32 | + foreach ($bucket as $field => $value) { |
|
| 33 | 33 | $values[] = sprintf('%s AS %s', $this->db()->quote($value), $this->db()->quoteField($field)); |
| 34 | 34 | } |
| 35 | 35 | $parts[] = sprintf("SELECT %s", join(', ', $values)); |
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | - $name = '(' . join("\n\tUNION\n\t", $parts) . ')'; |
|
| 38 | + $name = '('.join("\n\tUNION\n\t", $parts).')'; |
|
| 39 | 39 | } |
| 40 | - if($this->db()->getVirtualTables()->has($name)) { |
|
| 40 | + if ($this->db()->getVirtualTables()->has($name)) { |
|
| 41 | 41 | $select = (string) $this->db()->getVirtualTables()->get($name); |
| 42 | 42 | $name = sprintf('(%s)', join("\n\t", explode("\n", trim($select)))); |
| 43 | 43 | } |
| 44 | 44 | $name = $this->aliasReplacer()->replace($name); |
| 45 | - if($alias !== null) { |
|
| 45 | + if ($alias !== null) { |
|
| 46 | 46 | return sprintf("%s %s", $name, $alias); |
| 47 | 47 | } |
| 48 | 48 | return $name; |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | $errorInfo = $exception->errorInfo; |
| 19 | 19 | $code = is_array($errorInfo) && isset($errorInfo[1]) ? ((int) $errorInfo[1]) : ((int) $exception->getCode()); |
| 20 | 20 | $message = (string) $exception->getMessage(); |
| 21 | - switch($code) { |
|
| 21 | + switch ($code) { |
|
| 22 | 22 | case 2006: throw new DatabaseHasGoneAwayException($message, $code, $exception); |
| 23 | 23 | case 1213: throw new SqlDeadLockException($message, $code, $exception); |
| 24 | 24 | case 1205: throw new LockWaitTimeoutExceededException($message, $code, $exception); |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | case 1452: throw new IntegrityConstraintViolationException($message, (int) $code, $exception); |
| 32 | 32 | } |
| 33 | 33 | /** @link http://php.net/manual/en/class.exception.php#Hcom115813 (cHao's comment) */ |
| 34 | - if(!is_string($message) || !is_int($code)) { |
|
| 34 | + if (!is_string($message) || !is_int($code)) { |
|
| 35 | 35 | throw new SqlException((string) $message, (int) $code, $exception); |
| 36 | 36 | } |
| 37 | 37 | throw $exception; |
@@ -27,16 +27,16 @@ discard block |
||
| 27 | 27 | $this->value = $data; |
| 28 | 28 | $this->keyPath = $this->buildKey($keyPath); |
| 29 | 29 | $this->value = $this->recursiveGet($data, $this->keyPath, null); |
| 30 | - if($validator === null) { |
|
| 31 | - $validator = function ($data) { |
|
| 32 | - if(is_array($data)) { |
|
| 30 | + if ($validator === null) { |
|
| 31 | + $validator = function($data) { |
|
| 32 | + if (is_array($data)) { |
|
| 33 | 33 | return $this->isValidArray($data); |
| 34 | 34 | } |
| 35 | 35 | return (string) $data !== ''; |
| 36 | 36 | }; |
| 37 | 37 | } |
| 38 | - if($validationResultHandler === null) { |
|
| 39 | - $validationResultHandler = function () {}; |
|
| 38 | + if ($validationResultHandler === null) { |
|
| 39 | + $validationResultHandler = function() {}; |
|
| 40 | 40 | } |
| 41 | 41 | $this->validator = $validator; |
| 42 | 42 | $this->validationResultHandler = $validationResultHandler; |
@@ -73,10 +73,10 @@ discard block |
||
| 73 | 73 | * @return string |
| 74 | 74 | */ |
| 75 | 75 | private function buildKey($keyPath) { |
| 76 | - if(is_string($keyPath)) { |
|
| 76 | + if (is_string($keyPath)) { |
|
| 77 | 77 | $keyPath = explode('.', $keyPath); |
| 78 | 78 | } |
| 79 | - if(!is_array($keyPath)) { |
|
| 79 | + if (!is_array($keyPath)) { |
|
| 80 | 80 | throw new RuntimeException('Invalid key'); |
| 81 | 81 | } |
| 82 | 82 | return $keyPath; |
@@ -87,8 +87,8 @@ discard block |
||
| 87 | 87 | * @return bool |
| 88 | 88 | */ |
| 89 | 89 | private function isValidArray(array $array) { |
| 90 | - $data = array_filter($array, function ($value) { |
|
| 91 | - if(is_array($value)) { |
|
| 90 | + $data = array_filter($array, function($value) { |
|
| 91 | + if (is_array($value)) { |
|
| 92 | 92 | return $this->isValidArray($value); |
| 93 | 93 | } |
| 94 | 94 | return (string) $value !== ''; |
@@ -107,9 +107,9 @@ discard block |
||
| 107 | 107 | if (!$count) { |
| 108 | 108 | return $default; |
| 109 | 109 | } |
| 110 | - for($idx = 0; $idx < $count; $idx++) { |
|
| 110 | + for ($idx = 0; $idx < $count; $idx++) { |
|
| 111 | 111 | $part = $path[$idx]; |
| 112 | - if(!array_key_exists($part, $array)) { |
|
| 112 | + if (!array_key_exists($part, $array)) { |
|
| 113 | 113 | return $default; |
| 114 | 114 | } |
| 115 | 115 | $array = $array[$part]; |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @param array $options |
| 42 | 42 | */ |
| 43 | 43 | public function __construct(PDO $pdo, array $options = []) { |
| 44 | - if($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) { |
|
| 44 | + if ($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) { |
|
| 45 | 45 | $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 46 | 46 | } |
| 47 | 47 | $this->pdo = $pdo; |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * @return VirtualTables |
| 76 | 76 | */ |
| 77 | 77 | public function getVirtualTables() { |
| 78 | - if($this->virtualTables === null) { |
|
| 78 | + if ($this->virtualTables === null) { |
|
| 79 | 79 | $this->virtualTables = new VirtualTables(); |
| 80 | 80 | } |
| 81 | 81 | return $this->virtualTables; |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @return QueryStatement |
| 88 | 88 | */ |
| 89 | 89 | public function query($query) { |
| 90 | - return $this->buildQueryStatement($query, function ($query) { |
|
| 90 | + return $this->buildQueryStatement($query, function($query) { |
|
| 91 | 91 | $stmt = $this->pdo->query($query); |
| 92 | 92 | return $stmt; |
| 93 | 93 | }); |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | * @return QueryStatement |
| 100 | 100 | */ |
| 101 | 101 | public function prepare($query) { |
| 102 | - return $this->buildQueryStatement((string) $query, function ($query) { |
|
| 102 | + return $this->buildQueryStatement((string) $query, function($query) { |
|
| 103 | 103 | $stmt = $this->pdo->prepare($query); |
| 104 | 104 | return $stmt; |
| 105 | 105 | }); |
@@ -111,11 +111,11 @@ discard block |
||
| 111 | 111 | * @return int |
| 112 | 112 | */ |
| 113 | 113 | public function exec($query, array $params = []) { |
| 114 | - return $this->exceptionHandler(function () use ($query, $params) { |
|
| 114 | + return $this->exceptionHandler(function() use ($query, $params) { |
|
| 115 | 115 | $stmt = $this->pdo->prepare($query); |
| 116 | 116 | $timer = microtime(true); |
| 117 | 117 | $stmt->execute($params); |
| 118 | - $this->queryLoggers->log($query, microtime(true) - $timer); |
|
| 118 | + $this->queryLoggers->log($query, microtime(true)-$timer); |
|
| 119 | 119 | $result = $stmt->rowCount(); |
| 120 | 120 | $stmt->closeCursor(); |
| 121 | 121 | return $result; |
@@ -135,12 +135,12 @@ discard block |
||
| 135 | 135 | */ |
| 136 | 136 | public function getTableFields($table) { |
| 137 | 137 | $table = $this->select()->aliasReplacer()->replace($table); |
| 138 | - if(array_key_exists($table, self::$tableFields)) { |
|
| 138 | + if (array_key_exists($table, self::$tableFields)) { |
|
| 139 | 139 | return self::$tableFields[$table]; |
| 140 | 140 | } |
| 141 | 141 | $stmt = $this->pdo->query("DESCRIBE {$table}"); |
| 142 | 142 | $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC); |
| 143 | - self::$tableFields[$table] = array_map(function ($row) { return $row['Field']; }, $rows); |
|
| 143 | + self::$tableFields[$table] = array_map(function($row) { return $row['Field']; }, $rows); |
|
| 144 | 144 | $stmt->closeCursor(); |
| 145 | 145 | return self::$tableFields[$table]; |
| 146 | 146 | } |
@@ -152,12 +152,12 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | public function quoteExpression($expression, array $arguments = array()) { |
| 154 | 154 | $index = -1; |
| 155 | - $func = function () use ($arguments, &$index) { |
|
| 155 | + $func = function() use ($arguments, &$index) { |
|
| 156 | 156 | $index++; |
| 157 | - if(array_key_exists($index, $arguments)) { |
|
| 157 | + if (array_key_exists($index, $arguments)) { |
|
| 158 | 158 | $argument = $arguments[$index]; |
| 159 | 159 | $value = $this->quote($argument); |
| 160 | - } elseif(count($arguments) > 0) { |
|
| 160 | + } elseif (count($arguments) > 0) { |
|
| 161 | 161 | $args = $arguments; |
| 162 | 162 | $value = array_pop($args); |
| 163 | 163 | $value = $this->quote($value); |
@@ -175,14 +175,14 @@ discard block |
||
| 175 | 175 | * @return string |
| 176 | 176 | */ |
| 177 | 177 | public function quote($value) { |
| 178 | - if(is_null($value)) { |
|
| 178 | + if (is_null($value)) { |
|
| 179 | 179 | $result = 'NULL'; |
| 180 | - } elseif($value instanceof Builder\DBExpr) { |
|
| 180 | + } elseif ($value instanceof Builder\DBExpr) { |
|
| 181 | 181 | $result = $value->getExpression(); |
| 182 | - } elseif($value instanceof Builder\Select) { |
|
| 182 | + } elseif ($value instanceof Builder\Select) { |
|
| 183 | 183 | $result = sprintf('(%s)', (string) $value); |
| 184 | - } elseif(is_array($value)) { |
|
| 185 | - $result = join(', ', array_map(function ($value) { return $this->quote($value); }, $value)); |
|
| 184 | + } elseif (is_array($value)) { |
|
| 185 | + $result = join(', ', array_map(function($value) { return $this->quote($value); }, $value)); |
|
| 186 | 186 | } else { |
| 187 | 187 | $result = $this->pdo->quote($value); |
| 188 | 188 | } |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | if (is_numeric($field) || !is_string($field)) { |
| 198 | 198 | throw new UnexpectedValueException('Field name is invalid'); |
| 199 | 199 | } |
| 200 | - if(strpos($field, '`') !== false) { |
|
| 200 | + if (strpos($field, '`') !== false) { |
|
| 201 | 201 | return (string) $field; |
| 202 | 202 | } |
| 203 | 203 | $parts = explode('.', $field); |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | $select = array_key_exists('select-factory', $this->options) |
| 213 | 213 | ? call_user_func($this->options['select-factory'], $this, $this->options['select-options']) |
| 214 | 214 | : new Builder\RunnableSelect($this, $this->options['select-options']); |
| 215 | - if($fields !== null) { |
|
| 215 | + if ($fields !== null) { |
|
| 216 | 216 | $select->fields($fields); |
| 217 | 217 | } |
| 218 | 218 | return $select; |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | $insert = array_key_exists('insert-factory', $this->options) |
| 227 | 227 | ? call_user_func($this->options['insert-factory'], $this, $this->options['insert-options']) |
| 228 | 228 | : new Builder\RunnableInsert($this, $this->options['insert-options']); |
| 229 | - if($fields !== null) { |
|
| 229 | + if ($fields !== null) { |
|
| 230 | 230 | $insert->addAll($fields); |
| 231 | 231 | } |
| 232 | 232 | return $insert; |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | $update = array_key_exists('update-factory', $this->options) |
| 241 | 241 | ? call_user_func($this->options['update-factory'], $this, $this->options['update-options']) |
| 242 | 242 | : new Builder\RunnableUpdate($this, $this->options['update-options']); |
| 243 | - if($fields !== null) { |
|
| 243 | + if ($fields !== null) { |
|
| 244 | 244 | $update->setAll($fields); |
| 245 | 245 | } |
| 246 | 246 | return $update; |
@@ -259,8 +259,8 @@ discard block |
||
| 259 | 259 | * @return $this |
| 260 | 260 | */ |
| 261 | 261 | public function transactionStart() { |
| 262 | - if((int) $this->transactionLevel === 0) { |
|
| 263 | - if($this->pdo->inTransaction()) { |
|
| 262 | + if ((int) $this->transactionLevel === 0) { |
|
| 263 | + if ($this->pdo->inTransaction()) { |
|
| 264 | 264 | $this->outerTransaction = true; |
| 265 | 265 | } else { |
| 266 | 266 | $this->pdo->beginTransaction(); |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | * @return $this |
| 275 | 275 | */ |
| 276 | 276 | public function transactionCommit() { |
| 277 | - return $this->transactionEnd(function () { |
|
| 277 | + return $this->transactionEnd(function() { |
|
| 278 | 278 | $this->pdo->commit(); |
| 279 | 279 | }); |
| 280 | 280 | } |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | * @return $this |
| 284 | 284 | */ |
| 285 | 285 | public function transactionRollback() { |
| 286 | - return $this->transactionEnd(function () { |
|
| 286 | + return $this->transactionEnd(function() { |
|
| 287 | 287 | $this->pdo->rollBack(); |
| 288 | 288 | }); |
| 289 | 289 | } |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | * @return mixed |
| 294 | 294 | */ |
| 295 | 295 | public function dryRun($callback = null) { |
| 296 | - if(!$this->pdo->inTransaction()) { |
|
| 296 | + if (!$this->pdo->inTransaction()) { |
|
| 297 | 297 | $this->transactionStart(); |
| 298 | 298 | try { |
| 299 | 299 | return call_user_func($callback, $this); |
@@ -317,26 +317,26 @@ discard block |
||
| 317 | 317 | */ |
| 318 | 318 | public function transaction(callable $callback = null) { |
| 319 | 319 | $result = null; |
| 320 | - if(!$this->pdo->inTransaction()) { |
|
| 320 | + if (!$this->pdo->inTransaction()) { |
|
| 321 | 321 | $this->transactionStart(); |
| 322 | 322 | try { |
| 323 | 323 | $result = call_user_func($callback, $this); |
| 324 | 324 | $exception = null; |
| 325 | 325 | $this->transactionCommit(); |
| 326 | 326 | } finally { |
| 327 | - if($this->pdo->inTransaction()) { |
|
| 327 | + if ($this->pdo->inTransaction()) { |
|
| 328 | 328 | $this->transactionRollback(); |
| 329 | 329 | } |
| 330 | 330 | } |
| 331 | 331 | } else { |
| 332 | 332 | $uniqueId = $this->genUniqueId(); |
| 333 | 333 | $this->exec("SAVEPOINT {$uniqueId}"); |
| 334 | - $finally = function () use ($uniqueId) { |
|
| 334 | + $finally = function() use ($uniqueId) { |
|
| 335 | 335 | $this->exec("ROLLBACK TO {$uniqueId}"); |
| 336 | 336 | }; |
| 337 | 337 | try { |
| 338 | 338 | $result = call_user_func($callback, $this); |
| 339 | - $finally = function () use ($uniqueId) { |
|
| 339 | + $finally = function() use ($uniqueId) { |
|
| 340 | 340 | $this->exec("RELEASE SAVEPOINT {$uniqueId}"); |
| 341 | 341 | }; |
| 342 | 342 | } finally { |
@@ -353,11 +353,11 @@ discard block |
||
| 353 | 353 | */ |
| 354 | 354 | private function transactionEnd($fn) { |
| 355 | 355 | $this->transactionLevel--; |
| 356 | - if($this->transactionLevel < 0) { |
|
| 356 | + if ($this->transactionLevel < 0) { |
|
| 357 | 357 | throw new RuntimeException("Transaction-Nesting-Problem: Trying to invoke commit on a already closed transaction"); |
| 358 | 358 | } |
| 359 | - if((int) $this->transactionLevel === 0) { |
|
| 360 | - if($this->outerTransaction) { |
|
| 359 | + if ((int) $this->transactionLevel === 0) { |
|
| 360 | + if ($this->outerTransaction) { |
|
| 361 | 361 | $this->outerTransaction = false; |
| 362 | 362 | } else { |
| 363 | 363 | call_user_func($fn); |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | */ |
| 375 | 375 | private function buildQueryStatement($query, $fn) { |
| 376 | 376 | $stmt = call_user_func($fn, $query); |
| 377 | - if(!$stmt) { |
|
| 377 | + if (!$stmt) { |
|
| 378 | 378 | throw new RuntimeException("Could not execute statement:\n{$query}"); |
| 379 | 379 | } |
| 380 | 380 | $stmtWrapper = new QueryStatement($stmt, $query, $this->exceptionInterpreter, $this->queryLoggers); |
@@ -15,8 +15,8 @@ discard block |
||
| 15 | 15 | * @return $this |
| 16 | 16 | */ |
| 17 | 17 | public function orderBy($expression, $direction = 'asc') { |
| 18 | - if($expression instanceof OrderBySpecification) { |
|
| 19 | - foreach($expression->getFields() as $field) { |
|
| 18 | + if ($expression instanceof OrderBySpecification) { |
|
| 19 | + foreach ($expression->getFields() as $field) { |
|
| 20 | 20 | $this->addOrder($field[0], $field[1]); |
| 21 | 21 | } |
| 22 | 22 | return $this; |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | public function orderByValues($fieldName, array $values) { |
| 34 | 34 | $expr = []; |
| 35 | - foreach(array_values($values) as $idx => $value) { |
|
| 35 | + foreach (array_values($values) as $idx => $value) { |
|
| 36 | 36 | $expr[] = $this->db()->quoteExpression("WHEN ? THEN ?", [$value, $idx]); |
| 37 | 37 | } |
| 38 | 38 | $this->orderBy[] = [sprintf("CASE %s\n\t\t%s\n\tEND", $this->db()->quoteField($fieldName), join("\n\t\t", $expr)), 'ASC']; |
@@ -44,12 +44,12 @@ discard block |
||
| 44 | 44 | * @return string |
| 45 | 45 | */ |
| 46 | 46 | protected function buildOrder($query) { |
| 47 | - if(!count($this->orderBy)) { |
|
| 47 | + if (!count($this->orderBy)) { |
|
| 48 | 48 | return $query; |
| 49 | 49 | } |
| 50 | 50 | $query .= "ORDER BY\n"; |
| 51 | 51 | $arr = []; |
| 52 | - foreach($this->orderBy as $order) { |
|
| 52 | + foreach ($this->orderBy as $order) { |
|
| 53 | 53 | list($expression, $direction) = $order; |
| 54 | 54 | $arr[] = sprintf("\t%s %s", $expression, strtoupper($direction)); |
| 55 | 55 | } |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | private function addOrder($expression, $direction) { |
| 64 | 64 | $direction = $this->fixDirection($direction); |
| 65 | - if(is_array($expression)) { |
|
| 66 | - if(!count($expression)) { |
|
| 65 | + if (is_array($expression)) { |
|
| 66 | + if (!count($expression)) { |
|
| 67 | 67 | return; |
| 68 | 68 | } |
| 69 | 69 | $arguments = [ |