@@ -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; |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * @return QueryStatement |
| 87 | 87 | */ |
| 88 | 88 | public function query($query) { |
| 89 | - return $this->buildQueryStatement($query, function ($query) { |
|
| 89 | + return $this->buildQueryStatement($query, function($query) { |
|
| 90 | 90 | return $this->pdo->query($query); |
| 91 | 91 | }); |
| 92 | 92 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * @return QueryStatement |
| 97 | 97 | */ |
| 98 | 98 | public function prepare($query) { |
| 99 | - return $this->buildQueryStatement((string) $query, function ($query) { |
|
| 99 | + return $this->buildQueryStatement((string) $query, function($query) { |
|
| 100 | 100 | return $this->pdo->prepare($query); |
| 101 | 101 | }); |
| 102 | 102 | } |
@@ -107,11 +107,11 @@ discard block |
||
| 107 | 107 | * @return int |
| 108 | 108 | */ |
| 109 | 109 | public function exec($query, array $params = []) { |
| 110 | - return $this->exceptionHandler(function () use ($query, $params) { |
|
| 110 | + return $this->exceptionHandler(function() use ($query, $params) { |
|
| 111 | 111 | $stmt = $this->pdo->prepare($query); |
| 112 | 112 | $timer = microtime(true); |
| 113 | 113 | $stmt->execute($params); |
| 114 | - $this->queryLoggers->log($query, microtime(true) - $timer); |
|
| 114 | + $this->queryLoggers->log($query, microtime(true)-$timer); |
|
| 115 | 115 | $result = $stmt->rowCount(); |
| 116 | 116 | $stmt->closeCursor(); |
| 117 | 117 | return $result; |
@@ -131,12 +131,12 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | public function getTableFields($table) { |
| 133 | 133 | $table = $this->select()->aliasReplacer()->replace($table); |
| 134 | - if(array_key_exists($table, self::$tableFields)) { |
|
| 134 | + if (array_key_exists($table, self::$tableFields)) { |
|
| 135 | 135 | return self::$tableFields[$table]; |
| 136 | 136 | } |
| 137 | 137 | $stmt = $this->pdo->query("DESCRIBE {$table}"); |
| 138 | 138 | $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); |
| 139 | - self::$tableFields[$table] = array_map(static function ($row) { return $row['Field']; }, $rows); |
|
| 139 | + self::$tableFields[$table] = array_map(static function($row) { return $row['Field']; }, $rows); |
|
| 140 | 140 | $stmt->closeCursor(); |
| 141 | 141 | return self::$tableFields[$table]; |
| 142 | 142 | } |
@@ -148,12 +148,12 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | public function quoteExpression($expression, array $arguments = array()) { |
| 150 | 150 | $index = -1; |
| 151 | - $func = function () use ($arguments, &$index) { |
|
| 151 | + $func = function() use ($arguments, &$index) { |
|
| 152 | 152 | $index++; |
| 153 | - if(array_key_exists($index, $arguments)) { |
|
| 153 | + if (array_key_exists($index, $arguments)) { |
|
| 154 | 154 | $argument = $arguments[$index]; |
| 155 | 155 | $value = $this->quote($argument); |
| 156 | - } elseif(count($arguments) > 0) { |
|
| 156 | + } elseif (count($arguments) > 0) { |
|
| 157 | 157 | $args = $arguments; |
| 158 | 158 | $value = array_pop($args); |
| 159 | 159 | $value = $this->quote($value); |
@@ -171,14 +171,14 @@ discard block |
||
| 171 | 171 | * @return string |
| 172 | 172 | */ |
| 173 | 173 | public function quote($value) { |
| 174 | - if(is_null($value)) { |
|
| 174 | + if (is_null($value)) { |
|
| 175 | 175 | $result = 'NULL'; |
| 176 | - } elseif($value instanceof Builder\DBExpr) { |
|
| 176 | + } elseif ($value instanceof Builder\DBExpr) { |
|
| 177 | 177 | $result = $value->getExpression(); |
| 178 | - } elseif($value instanceof Builder\Select) { |
|
| 178 | + } elseif ($value instanceof Builder\Select) { |
|
| 179 | 179 | $result = sprintf('(%s)', (string) $value); |
| 180 | - } elseif(is_array($value)) { |
|
| 181 | - $result = implode(', ', array_map(function ($value) { return $this->quote($value); }, $value)); |
|
| 180 | + } elseif (is_array($value)) { |
|
| 181 | + $result = implode(', ', array_map(function($value) { return $this->quote($value); }, $value)); |
|
| 182 | 182 | } else { |
| 183 | 183 | $result = $this->pdo->quote($value); |
| 184 | 184 | } |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | if (is_numeric($field) || !is_string($field)) { |
| 194 | 194 | throw new UnexpectedValueException('Field name is invalid'); |
| 195 | 195 | } |
| 196 | - if(strpos($field, '`') !== false) { |
|
| 196 | + if (strpos($field, '`') !== false) { |
|
| 197 | 197 | return $field; |
| 198 | 198 | } |
| 199 | 199 | $parts = explode('.', $field); |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | $select = array_key_exists('select-factory', $this->options) |
| 209 | 209 | ? call_user_func($this->options['select-factory'], $this, $this->options['select-options']) |
| 210 | 210 | : new Builder\RunnableSelect($this, $this->options['select-options']); |
| 211 | - if($fields !== null) { |
|
| 211 | + if ($fields !== null) { |
|
| 212 | 212 | $select->fields($fields); |
| 213 | 213 | } |
| 214 | 214 | return $select; |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | $insert = array_key_exists('insert-factory', $this->options) |
| 223 | 223 | ? call_user_func($this->options['insert-factory'], $this, $this->options['insert-options']) |
| 224 | 224 | : new Builder\RunnableInsert($this, $this->options['insert-options']); |
| 225 | - if($fields !== null) { |
|
| 225 | + if ($fields !== null) { |
|
| 226 | 226 | $insert->addAll($fields); |
| 227 | 227 | } |
| 228 | 228 | return $insert; |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | $update = array_key_exists('update-factory', $this->options) |
| 237 | 237 | ? call_user_func($this->options['update-factory'], $this, $this->options['update-options']) |
| 238 | 238 | : new Builder\RunnableUpdate($this, $this->options['update-options']); |
| 239 | - if($fields !== null) { |
|
| 239 | + if ($fields !== null) { |
|
| 240 | 240 | $update->setAll($fields); |
| 241 | 241 | } |
| 242 | 242 | return $update; |
@@ -255,8 +255,8 @@ discard block |
||
| 255 | 255 | * @return $this |
| 256 | 256 | */ |
| 257 | 257 | public function transactionStart() { |
| 258 | - if($this->transactionLevel === 0) { |
|
| 259 | - if($this->pdo->inTransaction()) { |
|
| 258 | + if ($this->transactionLevel === 0) { |
|
| 259 | + if ($this->pdo->inTransaction()) { |
|
| 260 | 260 | $this->outerTransaction = true; |
| 261 | 261 | } else { |
| 262 | 262 | $this->pdo->beginTransaction(); |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * @return $this |
| 271 | 271 | */ |
| 272 | 272 | public function transactionCommit() { |
| 273 | - return $this->transactionEnd(function () { |
|
| 273 | + return $this->transactionEnd(function() { |
|
| 274 | 274 | $this->pdo->commit(); |
| 275 | 275 | }); |
| 276 | 276 | } |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | * @return $this |
| 280 | 280 | */ |
| 281 | 281 | public function transactionRollback() { |
| 282 | - return $this->transactionEnd(function () { |
|
| 282 | + return $this->transactionEnd(function() { |
|
| 283 | 283 | $this->pdo->rollBack(); |
| 284 | 284 | }); |
| 285 | 285 | } |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | * @return mixed |
| 290 | 290 | */ |
| 291 | 291 | public function dryRun($callback = null) { |
| 292 | - if(!$this->pdo->inTransaction()) { |
|
| 292 | + if (!$this->pdo->inTransaction()) { |
|
| 293 | 293 | $this->transactionStart(); |
| 294 | 294 | try { |
| 295 | 295 | return $callback($this); |
@@ -313,14 +313,14 @@ discard block |
||
| 313 | 313 | */ |
| 314 | 314 | public function transaction(callable $callback = null) { |
| 315 | 315 | $result = null; |
| 316 | - if(!$this->pdo->inTransaction()) { |
|
| 316 | + if (!$this->pdo->inTransaction()) { |
|
| 317 | 317 | $this->transactionStart(); |
| 318 | 318 | try { |
| 319 | 319 | $result = $callback($this); |
| 320 | 320 | $this->transactionCommit(); |
| 321 | 321 | return $result; |
| 322 | 322 | } catch (Throwable $e) { |
| 323 | - if($this->pdo->inTransaction()) { |
|
| 323 | + if ($this->pdo->inTransaction()) { |
|
| 324 | 324 | $this->transactionRollback(); |
| 325 | 325 | } |
| 326 | 326 | throw $e; |
@@ -344,11 +344,11 @@ discard block |
||
| 344 | 344 | */ |
| 345 | 345 | private function transactionEnd($fn) { |
| 346 | 346 | $this->transactionLevel--; |
| 347 | - if($this->transactionLevel < 0) { |
|
| 347 | + if ($this->transactionLevel < 0) { |
|
| 348 | 348 | throw new RuntimeException("Transaction-Nesting-Problem: Trying to invoke commit on a already closed transaction"); |
| 349 | 349 | } |
| 350 | - if($this->transactionLevel < 1) { |
|
| 351 | - if($this->outerTransaction) { |
|
| 350 | + if ($this->transactionLevel < 1) { |
|
| 351 | + if ($this->outerTransaction) { |
|
| 352 | 352 | $this->outerTransaction = false; |
| 353 | 353 | } else { |
| 354 | 354 | $fn(); |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | */ |
| 365 | 365 | private function buildQueryStatement($query, $fn) { |
| 366 | 366 | $stmt = $fn($query); |
| 367 | - if(!$stmt) { |
|
| 367 | + if (!$stmt) { |
|
| 368 | 368 | throw new RuntimeException("Could not execute statement:\n{$query}"); |
| 369 | 369 | } |
| 370 | 370 | return new QueryStatement($stmt, $query, $this->exceptionInterpreter, $this->queryLoggers); |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * @return mixed[] |
| 92 | 92 | */ |
| 93 | 93 | public function fetchRow(Closure $callback = null) { |
| 94 | - return $this->fetch($callback, PDO::FETCH_ASSOC, null, static function ($row) { |
|
| 94 | + return $this->fetch($callback, PDO::FETCH_ASSOC, null, static function($row) { |
|
| 95 | 95 | return ['valid' => is_array($row), 'default' => []]; |
| 96 | 96 | }); |
| 97 | 97 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @return object[] |
| 123 | 123 | */ |
| 124 | 124 | public function fetchObject($className = null, Closure $callback = null) { |
| 125 | - return $this->fetch($callback, PDO::FETCH_CLASS, $className ?: $this->defaultClassName, static function ($row) { |
|
| 125 | + return $this->fetch($callback, PDO::FETCH_CLASS, $className ?: $this->defaultClassName, static function($row) { |
|
| 126 | 126 | return ['valid' => is_object($row), 'default' => null]; |
| 127 | 127 | }); |
| 128 | 128 | } |
@@ -132,11 +132,11 @@ discard block |
||
| 132 | 132 | * @return mixed[] |
| 133 | 133 | */ |
| 134 | 134 | public function fetchKeyValue($treatValueAsArray = false) { |
| 135 | - return $this->createTempStatement(static function (QueryStatement $statement) use ($treatValueAsArray) { |
|
| 136 | - if($treatValueAsArray) { |
|
| 135 | + return $this->createTempStatement(static function(QueryStatement $statement) use ($treatValueAsArray) { |
|
| 136 | + if ($treatValueAsArray) { |
|
| 137 | 137 | $rows = $statement->fetchAll(PDO::FETCH_ASSOC); |
| 138 | 138 | $result = []; |
| 139 | - foreach($rows as $row) { |
|
| 139 | + foreach ($rows as $row) { |
|
| 140 | 140 | list($key) = array_values($row); |
| 141 | 141 | $result[$key] = $row; |
| 142 | 142 | } |
@@ -153,12 +153,12 @@ discard block |
||
| 153 | 153 | public function fetchGroups(array $fields) { |
| 154 | 154 | $rows = $this->fetchRows(); |
| 155 | 155 | $result = []; |
| 156 | - foreach($rows as $row) { |
|
| 156 | + foreach ($rows as $row) { |
|
| 157 | 157 | /** @var array $tmp */ |
| 158 | 158 | $tmp = &$result; |
| 159 | - foreach($fields as $field) { |
|
| 159 | + foreach ($fields as $field) { |
|
| 160 | 160 | $value = (string) $row[$field]; |
| 161 | - if(!array_key_exists($value, $tmp)) { |
|
| 161 | + if (!array_key_exists($value, $tmp)) { |
|
| 162 | 162 | $tmp[$value] = []; |
| 163 | 163 | } |
| 164 | 164 | $tmp = &$tmp[$value]; |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * @return string[] |
| 173 | 173 | */ |
| 174 | 174 | public function fetchArray() { |
| 175 | - return $this->createTempStatement(static function (QueryStatement $stmt) { |
|
| 175 | + return $this->createTempStatement(static function(QueryStatement $stmt) { |
|
| 176 | 176 | return $stmt->fetchAll(PDO::FETCH_COLUMN); |
| 177 | 177 | }); |
| 178 | 178 | } |
@@ -182,9 +182,9 @@ discard block |
||
| 182 | 182 | * @return null|bool|string|int|float |
| 183 | 183 | */ |
| 184 | 184 | public function fetchValue($default = null) { |
| 185 | - return $this->createTempStatement(static function (QueryStatement $stmt) use ($default) { |
|
| 185 | + return $this->createTempStatement(static function(QueryStatement $stmt) use ($default) { |
|
| 186 | 186 | $result = $stmt->fetch(PDO::FETCH_NUM); |
| 187 | - if($result !== false) { |
|
| 187 | + if ($result !== false) { |
|
| 188 | 188 | return $result[0]; |
| 189 | 189 | } |
| 190 | 190 | return $default; |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | $query = $this->__toString(); |
| 220 | 220 | $statement = $db->prepare($query); |
| 221 | 221 | $statement->execute($this->values); |
| 222 | - if($this->getCalcFoundRows()) { |
|
| 222 | + if ($this->getCalcFoundRows()) { |
|
| 223 | 223 | $this->foundRows = (int) $db->query('SELECT FOUND_ROWS()')->fetchColumn(); |
| 224 | 224 | } |
| 225 | 225 | return $statement; |
@@ -241,18 +241,18 @@ discard block |
||
| 241 | 241 | * @return mixed |
| 242 | 242 | */ |
| 243 | 243 | private function fetchAll(Closure $callback = null, $mode, $arg0 = null) { |
| 244 | - return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0) { |
|
| 244 | + return $this->createTempStatement(function(QueryStatement $statement) use ($callback, $mode, $arg0) { |
|
| 245 | 245 | $statement->setFetchMode($mode, $arg0); |
| 246 | 246 | $data = $statement->fetchAll(); |
| 247 | - if($this->preserveTypes) { |
|
| 247 | + if ($this->preserveTypes) { |
|
| 248 | 248 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
| 249 | - $data = array_map(static function ($row) use ($columnDefinitions) { return FieldValueConverter::convertValues($row, $columnDefinitions); }, $data); |
|
| 249 | + $data = array_map(static function($row) use ($columnDefinitions) { return FieldValueConverter::convertValues($row, $columnDefinitions); }, $data); |
|
| 250 | 250 | } |
| 251 | - if($callback !== null) { |
|
| 252 | - return call_user_func(static function ($resultData = []) use ($data, $callback) { |
|
| 253 | - foreach($data as $row) { |
|
| 251 | + if ($callback !== null) { |
|
| 252 | + return call_user_func(static function($resultData = []) use ($data, $callback) { |
|
| 253 | + foreach ($data as $row) { |
|
| 254 | 254 | $result = $callback($row); |
| 255 | - if($result !== null && !($result instanceof DBIgnoreRow)) { |
|
| 255 | + if ($result !== null && !($result instanceof DBIgnoreRow)) { |
|
| 256 | 256 | $resultData[] = $result; |
| 257 | 257 | } else { |
| 258 | 258 | $resultData[] = $row; |
@@ -286,20 +286,20 @@ discard block |
||
| 286 | 286 | * @return mixed |
| 287 | 287 | */ |
| 288 | 288 | private function fetch(Closure $callback = null, $mode, $arg0 = null, Closure $resultValidator = null) { |
| 289 | - return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) { |
|
| 289 | + return $this->createTempStatement(function(QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) { |
|
| 290 | 290 | $statement->setFetchMode($mode, $arg0); |
| 291 | 291 | $row = $statement->fetch(); |
| 292 | 292 | $result = $resultValidator($row); |
| 293 | - if(!$result['valid']) { |
|
| 293 | + if (!$result['valid']) { |
|
| 294 | 294 | return $result['default']; |
| 295 | 295 | } |
| 296 | - if($this->preserveTypes) { |
|
| 296 | + if ($this->preserveTypes) { |
|
| 297 | 297 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
| 298 | 298 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
| 299 | 299 | } |
| 300 | - if($callback !== null) { |
|
| 300 | + if ($callback !== null) { |
|
| 301 | 301 | $result = $callback($row); |
| 302 | - if($result !== null) { |
|
| 302 | + if ($result !== null) { |
|
| 303 | 303 | $row = $result; |
| 304 | 304 | } |
| 305 | 305 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @return $this |
| 30 | 30 | */ |
| 31 | 31 | public function from($alias, $table = null) { |
| 32 | - if($table !== null) { |
|
| 32 | + if ($table !== null) { |
|
| 33 | 33 | $this->aliases[] = $alias; |
| 34 | 34 | } |
| 35 | 35 | $this->addTable($alias, $table); |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | public function __toString() { |
| 43 | 43 | $query = "DELETE "; |
| 44 | 44 | $query .= implode(', ', $this->aliases); |
| 45 | - $query = trim($query) . " FROM\n"; |
|
| 45 | + $query = trim($query)." FROM\n"; |
|
| 46 | 46 | $query = $this->buildTables($query); |
| 47 | 47 | $query = $this->buildJoins($query); |
| 48 | 48 | $query = $this->buildWhereConditions($query); |
@@ -34,8 +34,8 @@ |
||
| 34 | 34 | * @return DBExprFilter |
| 35 | 35 | */ |
| 36 | 36 | public function __invoke($expression, $keyPath, $validator = null) { |
| 37 | - return new DBExprFilter($expression, $this->map, $keyPath, $validator, static function ($result, array $data) { |
|
| 38 | - if(!$result) { |
|
| 37 | + return new DBExprFilter($expression, $this->map, $keyPath, $validator, static function($result, array $data) { |
|
| 38 | + if (!$result) { |
|
| 39 | 39 | throw new RequiredValueNotFoundException(sprintf("Required value %s not found", $data['key'])); |
| 40 | 40 | } |
| 41 | 41 | }); |
@@ -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 = static function () {}; |
|
| 38 | + if ($validationResultHandler === null) { |
|
| 39 | + $validationResultHandler = static 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 | - foreach($path as $idxValue) { |
|
| 110 | + foreach ($path as $idxValue) { |
|
| 111 | 111 | $part = $idxValue; |
| 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]; |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * @return $this |
| 87 | 87 | */ |
| 88 | 88 | public function addExpr($str, ...$args) { |
| 89 | - if(count($args) > 0) { |
|
| 89 | + if (count($args) > 0) { |
|
| 90 | 90 | $this->fields[] = func_get_args(); |
| 91 | 91 | } else { |
| 92 | 92 | $this->fields[] = $str; |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | * @return $this |
| 101 | 101 | */ |
| 102 | 102 | public function updateExpr($str, ...$args) { |
| 103 | - if(count($args) > 0) { |
|
| 103 | + if (count($args) > 0) { |
|
| 104 | 104 | $this->update[] = func_get_args(); |
| 105 | 105 | } else { |
| 106 | 106 | $this->update[] = $str; |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * @return $this |
| 115 | 115 | */ |
| 116 | 116 | public function addOrUpdateExpr($expr, ...$args) { |
| 117 | - if(count($args) > 0) { |
|
| 117 | + if (count($args) > 0) { |
|
| 118 | 118 | $this->fields[] = func_get_args(); |
| 119 | 119 | $this->update[] = func_get_args(); |
| 120 | 120 | } else { |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * @return $this |
| 132 | 132 | */ |
| 133 | 133 | public function addAll(array $data, array $mask = null, array $excludeFields = null) { |
| 134 | - $this->addAllTo($data, $mask, $excludeFields, function ($field, $value) { |
|
| 134 | + $this->addAllTo($data, $mask, $excludeFields, function($field, $value) { |
|
| 135 | 135 | $this->add($field, $value); |
| 136 | 136 | }); |
| 137 | 137 | return $this; |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @return $this |
| 145 | 145 | */ |
| 146 | 146 | public function updateAll(array $data, array $mask = null, array $excludeFields = null) { |
| 147 | - $this->addAllTo($data, $mask, $excludeFields, function ($field, $value) { |
|
| 147 | + $this->addAllTo($data, $mask, $excludeFields, function($field, $value) { |
|
| 148 | 148 | if ($field !== $this->keyField) { |
| 149 | 149 | $this->update($field, $value); |
| 150 | 150 | } |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | $ignoreStr = $this->ignore ? ' IGNORE' : ''; |
| 188 | 188 | $queryArr[] = "INSERT{$ignoreStr} INTO\n\t{$tableName}\n"; |
| 189 | 189 | |
| 190 | - if($this->from !== null) { |
|
| 190 | + if ($this->from !== null) { |
|
| 191 | 191 | $fields = $this->from->getFields(); |
| 192 | 192 | $queryArr[] = sprintf("\t(%s)\n", implode(', ', array_keys($fields))); |
| 193 | 193 | $queryArr[] = $this->from; |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | $updateData = $this->buildUpdate(); |
| 204 | - if($updateData) { |
|
| 204 | + if ($updateData) { |
|
| 205 | 205 | $queryArr[] = "{$updateData}\n"; |
| 206 | 206 | } |
| 207 | 207 | |
@@ -232,12 +232,12 @@ discard block |
||
| 232 | 232 | * @return $this |
| 233 | 233 | */ |
| 234 | 234 | private function addAllTo(array $data, array $mask = null, array $excludeFields = null, $fn) { |
| 235 | - if($mask !== null) { |
|
| 235 | + if ($mask !== null) { |
|
| 236 | 236 | $data = array_intersect_key($data, array_combine($mask, $mask)); |
| 237 | 237 | } |
| 238 | - if($excludeFields !== null) { |
|
| 239 | - foreach($excludeFields as $excludeField) { |
|
| 240 | - if(array_key_exists($excludeField, $data)) { |
|
| 238 | + if ($excludeFields !== null) { |
|
| 239 | + foreach ($excludeFields as $excludeField) { |
|
| 240 | + if (array_key_exists($excludeField, $data)) { |
|
| 241 | 241 | unset($data[$excludeField]); |
| 242 | 242 | } |
| 243 | 243 | } |
@@ -254,10 +254,10 @@ discard block |
||
| 254 | 254 | */ |
| 255 | 255 | private function buildUpdate() { |
| 256 | 256 | $queryArr = []; |
| 257 | - if(!empty($this->update)) { |
|
| 257 | + if (!empty($this->update)) { |
|
| 258 | 258 | $queryArr[] = "ON DUPLICATE KEY UPDATE\n"; |
| 259 | 259 | $updateArr = []; |
| 260 | - if($this->keyField !== null) { |
|
| 260 | + if ($this->keyField !== null) { |
|
| 261 | 261 | $updateArr[] = "\t`{$this->keyField}` = LAST_INSERT_ID({$this->keyField})"; |
| 262 | 262 | } |
| 263 | 263 | $updateArr = $this->buildFieldList($this->update, $updateArr); |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | * @return array |
| 281 | 281 | */ |
| 282 | 282 | private function clearValues(array $values) { |
| 283 | - if(!count($values)) { |
|
| 283 | + if (!count($values)) { |
|
| 284 | 284 | return []; |
| 285 | 285 | } |
| 286 | 286 | |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | $result = []; |
| 290 | 290 | |
| 291 | 291 | foreach ($values as $fieldName => $fieldValue) { |
| 292 | - if(in_array($fieldName, $fields)) { |
|
| 292 | + if (in_array($fieldName, $fields)) { |
|
| 293 | 293 | $result[$fieldName] = $fieldValue; |
| 294 | 294 | } |
| 295 | 295 | } |
@@ -12,15 +12,15 @@ |
||
| 12 | 12 | * @return string |
| 13 | 13 | */ |
| 14 | 14 | public static function build(Database $db, $query, array $conditions, $token) { |
| 15 | - if(!count($conditions)) { |
|
| 15 | + if (!count($conditions)) { |
|
| 16 | 16 | return $query; |
| 17 | 17 | } |
| 18 | 18 | $query .= "{$token}\n"; |
| 19 | 19 | $arr = []; |
| 20 | - foreach($conditions as list($expression, $arguments)) { |
|
| 21 | - if(is_array($expression)) { |
|
| 22 | - foreach($expression as $key => $value) { |
|
| 23 | - if($value === null) { |
|
| 20 | + foreach ($conditions as list($expression, $arguments)) { |
|
| 21 | + if (is_array($expression)) { |
|
| 22 | + foreach ($expression as $key => $value) { |
|
| 23 | + if ($value === null) { |
|
| 24 | 24 | $arr = self::buildCondition($arr, "ISNULL(`{$key}`)", [$value], $db); |
| 25 | 25 | } else { |
| 26 | 26 | $arr = self::buildCondition($arr, "`{$key}`=?", [$value], $db); |
@@ -47,15 +47,15 @@ |
||
| 47 | 47 | */ |
| 48 | 48 | protected function buildJoins($query) { |
| 49 | 49 | $arr = []; |
| 50 | - foreach($this->joinTables as $table) { |
|
| 50 | + foreach ($this->joinTables as $table) { |
|
| 51 | 51 | $join = $table['type']." JOIN\n"; |
| 52 | - $join .= "\t" . $this->buildTableName($table['alias'], $table['name']); |
|
| 53 | - if($table['expression']) { |
|
| 54 | - $join .= " ON " . $this->db()->quoteExpression($table['expression'], $table['arguments']); |
|
| 52 | + $join .= "\t".$this->buildTableName($table['alias'], $table['name']); |
|
| 53 | + if ($table['expression']) { |
|
| 54 | + $join .= " ON ".$this->db()->quoteExpression($table['expression'], $table['arguments']); |
|
| 55 | 55 | } |
| 56 | 56 | $arr[] = $join; |
| 57 | 57 | } |
| 58 | - if(count($arr)) { |
|
| 58 | + if (count($arr)) { |
|
| 59 | 59 | $query .= implode("\n", $arr)."\n"; |
| 60 | 60 | } |
| 61 | 61 | return $query; |
@@ -13,34 +13,34 @@ |
||
| 13 | 13 | * @return string |
| 14 | 14 | */ |
| 15 | 15 | protected function buildTableName($alias, $name) { |
| 16 | - if(is_object($name) && !($name instanceof VirtualTable) && method_exists($name, '__toString')) { |
|
| 16 | + if (is_object($name) && !($name instanceof VirtualTable) && method_exists($name, '__toString')) { |
|
| 17 | 17 | $name = (string) $name; |
| 18 | 18 | $lines = explode("\n", $name); |
| 19 | - $lines = array_map(static function (string $line) { return "\t{$line}"; }, $lines); |
|
| 19 | + $lines = array_map(static function(string $line) { return "\t{$line}"; }, $lines); |
|
| 20 | 20 | $name = implode("\n", $lines); |
| 21 | - $name = '(' . trim(rtrim(trim($name), ';')) . ')'; |
|
| 21 | + $name = '('.trim(rtrim(trim($name), ';')).')'; |
|
| 22 | 22 | } |
| 23 | - if(is_array($name)) { |
|
| 23 | + if (is_array($name)) { |
|
| 24 | 24 | $parts = []; |
| 25 | - foreach($name as $index => $bucket) { |
|
| 26 | - if(is_scalar($bucket) && ctype_digit((string) $index)) { |
|
| 25 | + foreach ($name as $index => $bucket) { |
|
| 26 | + if (is_scalar($bucket) && ctype_digit((string) $index)) { |
|
| 27 | 27 | $parts[] = "SELECT {$this->db()->quote($bucket)} AS {$this->db()->quoteField('value')}"; |
| 28 | 28 | } else { |
| 29 | 29 | $values = []; |
| 30 | - foreach($bucket as $field => $value) { |
|
| 30 | + foreach ($bucket as $field => $value) { |
|
| 31 | 31 | $values[] = sprintf('%s AS %s', $this->db()->quote($value), $this->db()->quoteField($field)); |
| 32 | 32 | } |
| 33 | 33 | $parts[] = sprintf("SELECT %s", implode(', ', $values)); |
| 34 | 34 | } |
| 35 | 35 | } |
| 36 | - $name = '(' . implode("\n\tUNION\n\t", $parts) . ')'; |
|
| 36 | + $name = '('.implode("\n\tUNION\n\t", $parts).')'; |
|
| 37 | 37 | } |
| 38 | - if($this->db()->getVirtualTables()->has($name)) { |
|
| 38 | + if ($this->db()->getVirtualTables()->has($name)) { |
|
| 39 | 39 | $select = (string) $this->db()->getVirtualTables()->get($name); |
| 40 | 40 | $name = sprintf('(%s)', implode("\n\t", explode("\n", trim($select)))); |
| 41 | 41 | } |
| 42 | 42 | $name = $this->aliasReplacer()->replace($name); |
| 43 | - if($alias !== null) { |
|
| 43 | + if ($alias !== null) { |
|
| 44 | 44 | return sprintf("%s %s", $name, $alias); |
| 45 | 45 | } |
| 46 | 46 | return $name; |