@@ -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; |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | * @return $this |
| 89 | 89 | */ |
| 90 | 90 | public function addExpr($str) { |
| 91 | - if(count(func_get_args()) > 1) { |
|
| 91 | + if (count(func_get_args()) > 1) { |
|
| 92 | 92 | $this->fields[] = func_get_args(); |
| 93 | 93 | } else { |
| 94 | 94 | $this->fields[] = $str; |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | * @return $this |
| 103 | 103 | */ |
| 104 | 104 | public function updateExpr($str) { |
| 105 | - if(count(func_get_args()) > 1) { |
|
| 105 | + if (count(func_get_args()) > 1) { |
|
| 106 | 106 | $this->update[] = func_get_args(); |
| 107 | 107 | } else { |
| 108 | 108 | $this->update[] = $str; |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * @return $this |
| 116 | 116 | */ |
| 117 | 117 | public function addOrUpdateExpr($str) { |
| 118 | - if(count(func_get_args()) > 1) { |
|
| 118 | + if (count(func_get_args()) > 1) { |
|
| 119 | 119 | $this->fields[] = func_get_args(); |
| 120 | 120 | $this->update[] = func_get_args(); |
| 121 | 121 | } else { |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | * @return $this |
| 133 | 133 | */ |
| 134 | 134 | public function addAll(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 | $this->add($field, $value); |
| 137 | 137 | }); |
| 138 | 138 | return $this; |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | * @return $this |
| 146 | 146 | */ |
| 147 | 147 | public function updateAll(array $data, array $mask = null, array $excludeFields = null) { |
| 148 | - $this->addAllTo($data, $mask, $excludeFields, function ($field, $value) { |
|
| 148 | + $this->addAllTo($data, $mask, $excludeFields, function($field, $value) { |
|
| 149 | 149 | if ($field !== $this->keyField) { |
| 150 | 150 | $this->update($field, $value); |
| 151 | 151 | } |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | $ignoreStr = $this->ignore ? ' IGNORE' : ''; |
| 190 | 190 | $queryArr[] = "INSERT{$ignoreStr} INTO\n\t{$tableName}\n"; |
| 191 | 191 | |
| 192 | - if($this->from !== null) { |
|
| 192 | + if ($this->from !== null) { |
|
| 193 | 193 | $fields = $this->from->getFields(); |
| 194 | 194 | $queryArr[] = sprintf("\t(%s)\n", join(', ', array_keys($fields))); |
| 195 | 195 | $queryArr[] = $this->from; |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | $updateData = $this->buildUpdate(); |
| 206 | - if($updateData) { |
|
| 206 | + if ($updateData) { |
|
| 207 | 207 | $queryArr[] = "{$updateData}\n"; |
| 208 | 208 | } |
| 209 | 209 | |
@@ -236,12 +236,12 @@ discard block |
||
| 236 | 236 | * @return $this |
| 237 | 237 | */ |
| 238 | 238 | private function addAllTo(array $data, array $mask = null, array $excludeFields = null, $fn) { |
| 239 | - if($mask !== null) { |
|
| 239 | + if ($mask !== null) { |
|
| 240 | 240 | $data = array_intersect_key($data, array_combine($mask, $mask)); |
| 241 | 241 | } |
| 242 | - if($excludeFields !== null) { |
|
| 243 | - foreach($excludeFields as $excludeField) { |
|
| 244 | - if(array_key_exists($excludeField, $data)) { |
|
| 242 | + if ($excludeFields !== null) { |
|
| 243 | + foreach ($excludeFields as $excludeField) { |
|
| 244 | + if (array_key_exists($excludeField, $data)) { |
|
| 245 | 245 | unset($data[$excludeField]); |
| 246 | 246 | } |
| 247 | 247 | } |
@@ -257,10 +257,10 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | private function buildUpdate() { |
| 259 | 259 | $queryArr = array(); |
| 260 | - if(!empty($this->update)) { |
|
| 260 | + if (!empty($this->update)) { |
|
| 261 | 261 | $queryArr[] = "ON DUPLICATE KEY UPDATE\n"; |
| 262 | 262 | $updateArr = array(); |
| 263 | - if($this->keyField !== null) { |
|
| 263 | + if ($this->keyField !== null) { |
|
| 264 | 264 | $updateArr[] = "\t`{$this->keyField}` = LAST_INSERT_ID({$this->keyField})"; |
| 265 | 265 | } |
| 266 | 266 | $updateArr = $this->buildFieldList($this->update, $updateArr); |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | * @throws Exception |
| 285 | 285 | */ |
| 286 | 286 | private function clearValues(array $values) { |
| 287 | - if(!count($values)) { |
|
| 287 | + if (!count($values)) { |
|
| 288 | 288 | return []; |
| 289 | 289 | } |
| 290 | 290 | |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | $result = array(); |
| 294 | 294 | |
| 295 | 295 | foreach ($values as $fieldName => $fieldValue) { |
| 296 | - if(in_array($fieldName, $fields)) { |
|
| 296 | + if (in_array($fieldName, $fields)) { |
|
| 297 | 297 | $result[$fieldName] = $fieldValue; |
| 298 | 298 | } |
| 299 | 299 | } |