@@ -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); |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | public function __toString() { |
| 44 | 44 | $query = "DELETE "; |
| 45 | 45 | $query .= join(', ', $this->aliases); |
| 46 | - $query = trim($query) . " FROM\n"; |
|
| 46 | + $query = trim($query)." FROM\n"; |
|
| 47 | 47 | $query = $this->buildTables($query); |
| 48 | 48 | $query = $this->buildJoins($query); |
| 49 | 49 | $query = $this->buildWhereConditions($query); |
@@ -8,8 +8,8 @@ |
||
| 8 | 8 | * @return array |
| 9 | 9 | */ |
| 10 | 10 | public static function convertValues(array $row, array $columnDefinitions) { |
| 11 | - foreach($row as $key => &$value) { |
|
| 12 | - if($value !== null) { |
|
| 11 | + foreach ($row as $key => &$value) { |
|
| 12 | + if ($value !== null) { |
|
| 13 | 13 | $value = self::convertValue($value, $columnDefinitions[$key]); |
| 14 | 14 | } |
| 15 | 15 | } |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | public static function getFieldTypes(QueryStatement $statement) { |
| 12 | 12 | $c = $statement->columnCount(); |
| 13 | 13 | $fieldTypes = array(); |
| 14 | - for($i=0; $i<$c+20; $i++) { |
|
| 14 | + for ($i = 0; $i < $c+20; $i++) { |
|
| 15 | 15 | $column = $statement->getColumnMeta($i); |
| 16 | 16 | $fieldTypes[$column['name']] = self::getTypeFromNativeType($column['native_type']); |
| 17 | 17 | } |
@@ -21,14 +21,14 @@ |
||
| 21 | 21 | * @return array[]|\Generator |
| 22 | 22 | */ |
| 23 | 23 | public function generate(QueryStatement $statement, Closure $callback = null) { |
| 24 | - while($row = $statement->fetch(\PDO::FETCH_ASSOC)) { |
|
| 25 | - if($this->preserveTypes) { |
|
| 24 | + while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) { |
|
| 25 | + if ($this->preserveTypes) { |
|
| 26 | 26 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
| 27 | 27 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
| 28 | 28 | } |
| 29 | - if($callback !== null) { |
|
| 29 | + if ($callback !== null) { |
|
| 30 | 30 | $row = call_user_func($callback); |
| 31 | - if($row !== null) { |
|
| 31 | + if ($row !== null) { |
|
| 32 | 32 | yield $row; |
| 33 | 33 | } |
| 34 | 34 | } else { |
@@ -12,12 +12,12 @@ |
||
| 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 = array(); |
| 20 | - foreach($conditions as $condition) { |
|
| 20 | + foreach ($conditions as $condition) { |
|
| 21 | 21 | list($expression, $arguments) = $condition; |
| 22 | 22 | $expr = $db->quoteExpression($expression, $arguments); |
| 23 | 23 | $arr[] = "\t({$expr})"; |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | public function run(array $params = array()) { |
| 26 | 26 | $this->query->execute($params); |
| 27 | 27 | $response = $this->query->getStatement()->rowCount(); |
| 28 | - if($this->callbackFn !== null) { |
|
| 28 | + if ($this->callbackFn !== null) { |
|
| 29 | 29 | $response = call_user_func($this->callbackFn, $response); |
| 30 | 30 | } |
| 31 | 31 | return $response; |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * @return $this |
| 120 | 120 | */ |
| 121 | 121 | public function addAll(array $data, array $mask = null, array $excludeFields = null) { |
| 122 | - $this->addAllTo($data, $mask, $excludeFields, function ($field, $value) { |
|
| 122 | + $this->addAllTo($data, $mask, $excludeFields, function($field, $value) { |
|
| 123 | 123 | $this->add($field, $value); |
| 124 | 124 | }); |
| 125 | 125 | return $this; |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | * @return $this |
| 133 | 133 | */ |
| 134 | 134 | public function updateAll(array $data, array $mask = null, array $excludeFields = null) { |
| 135 | - $this->addAllTo($data, $mask, $excludeFields, function ($field, $value) { |
|
| 135 | + $this->addAllTo($data, $mask, $excludeFields, function($field, $value) { |
|
| 136 | 136 | if ($field !== $this->keyField) { |
| 137 | 137 | $this->update($field, $value); |
| 138 | 138 | } |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | $ignoreStr = $this->ignore ? ' IGNORE' : ''; |
| 177 | 177 | $queryArr[] = "INSERT{$ignoreStr} INTO\n\t{$tableName}\n"; |
| 178 | 178 | |
| 179 | - if($this->from !== null) { |
|
| 179 | + if ($this->from !== null) { |
|
| 180 | 180 | $fields = $this->from->getFields(); |
| 181 | 181 | $queryArr[] = sprintf("\t(%s)\n", join(', ', array_keys($fields))); |
| 182 | 182 | $queryArr[] = $this->from; |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | $updateData = $this->buildUpdate(); |
| 193 | - if($updateData) { |
|
| 193 | + if ($updateData) { |
|
| 194 | 194 | $queryArr[] = "{$updateData}\n"; |
| 195 | 195 | } |
| 196 | 196 | |
@@ -223,12 +223,12 @@ discard block |
||
| 223 | 223 | * @return $this |
| 224 | 224 | */ |
| 225 | 225 | private function addAllTo(array $data, array $mask = null, array $excludeFields = null, $fn) { |
| 226 | - if($mask !== null) { |
|
| 226 | + if ($mask !== null) { |
|
| 227 | 227 | $data = array_intersect_key($data, array_combine($mask, $mask)); |
| 228 | 228 | } |
| 229 | - if($excludeFields !== null) { |
|
| 230 | - foreach($excludeFields as $excludeField) { |
|
| 231 | - if(array_key_exists($excludeField, $data)) { |
|
| 229 | + if ($excludeFields !== null) { |
|
| 230 | + foreach ($excludeFields as $excludeField) { |
|
| 231 | + if (array_key_exists($excludeField, $data)) { |
|
| 232 | 232 | unset($data[$excludeField]); |
| 233 | 233 | } |
| 234 | 234 | } |
@@ -244,10 +244,10 @@ discard block |
||
| 244 | 244 | */ |
| 245 | 245 | private function buildUpdate() { |
| 246 | 246 | $queryArr = array(); |
| 247 | - if(!empty($this->update)) { |
|
| 247 | + if (!empty($this->update)) { |
|
| 248 | 248 | $queryArr[] = "ON DUPLICATE KEY UPDATE\n"; |
| 249 | 249 | $updateArr = array(); |
| 250 | - if($this->keyField !== null) { |
|
| 250 | + if ($this->keyField !== null) { |
|
| 251 | 251 | $updateArr[] = "\t`{$this->keyField}` = LAST_INSERT_ID({$this->keyField})"; |
| 252 | 252 | } |
| 253 | 253 | $updateArr = $this->buildFieldList($this->update, $updateArr); |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | * @throws Exception |
| 272 | 272 | */ |
| 273 | 273 | private function clearValues(array $values) { |
| 274 | - if(!count($values)) { |
|
| 274 | + if (!count($values)) { |
|
| 275 | 275 | return []; |
| 276 | 276 | } |
| 277 | 277 | |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | $result = array(); |
| 281 | 281 | |
| 282 | 282 | foreach ($values as $fieldName => $fieldValue) { |
| 283 | - if(in_array($fieldName, $fields)) { |
|
| 283 | + if (in_array($fieldName, $fields)) { |
|
| 284 | 284 | $result[$fieldName] = $fieldValue; |
| 285 | 285 | } |
| 286 | 286 | } |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | * @return string |
| 295 | 295 | */ |
| 296 | 296 | private function formatExtraArgs($expression, $args) { |
| 297 | - if(count($args) > 1) { |
|
| 297 | + if (count($args) > 1) { |
|
| 298 | 298 | $args = array_slice($args, 1); |
| 299 | 299 | $expression = $this->db()->quoteExpression($expression, $args); |
| 300 | 300 | } |