@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | /** |
244 | 244 | * @param Closure $callback |
245 | 245 | * @param int $mode |
246 | - * @param mixed $arg0 |
|
246 | + * @param string $arg0 |
|
247 | 247 | * @return mixed |
248 | 248 | * @throws RuntimeException |
249 | 249 | */ |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | /** |
278 | 278 | * @param Closure $callback |
279 | 279 | * @param int $mode |
280 | - * @param mixed $arg0 |
|
280 | + * @param string $arg0 |
|
281 | 281 | * @return Traversable|YieldPolyfillIterator|mixed[] |
282 | 282 | */ |
283 | 283 | private function fetchLazy(Closure $callback = null, $mode, $arg0 = null) { |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | /** |
298 | 298 | * @param Closure $callback |
299 | 299 | * @param int $mode |
300 | - * @param mixed $arg0 |
|
300 | + * @param null|string $arg0 |
|
301 | 301 | * @param Closure $resultValidator |
302 | 302 | * @return mixed |
303 | 303 | * @throws \Exception |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @throws \Exception |
95 | 95 | */ |
96 | 96 | public function fetchRow(Closure $callback = null) { |
97 | - return $this->fetch($callback, PDO::FETCH_ASSOC, null, function ($row) { |
|
97 | + return $this->fetch($callback, PDO::FETCH_ASSOC, null, function($row) { |
|
98 | 98 | return ['valid' => is_array($row), 'default' => []]; |
99 | 99 | }); |
100 | 100 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @throws \Exception |
126 | 126 | */ |
127 | 127 | public function fetchObject($className = null, Closure $callback = null) { |
128 | - return $this->fetch($callback, PDO::FETCH_CLASS, $className ?: $this->defaultClassName, function ($row) { |
|
128 | + return $this->fetch($callback, PDO::FETCH_CLASS, $className ?: $this->defaultClassName, function($row) { |
|
129 | 129 | return ['valid' => is_object($row), 'default' => null]; |
130 | 130 | }); |
131 | 131 | } |
@@ -135,11 +135,11 @@ discard block |
||
135 | 135 | * @return mixed[] |
136 | 136 | */ |
137 | 137 | public function fetchKeyValue($treatValueAsArray = false) { |
138 | - return $this->createTempStatement(function (QueryStatement $statement) use ($treatValueAsArray) { |
|
139 | - if($treatValueAsArray) { |
|
138 | + return $this->createTempStatement(function(QueryStatement $statement) use ($treatValueAsArray) { |
|
139 | + if ($treatValueAsArray) { |
|
140 | 140 | $rows = $statement->fetchAll(\PDO::FETCH_ASSOC); |
141 | 141 | $result = array(); |
142 | - foreach($rows as $row) { |
|
142 | + foreach ($rows as $row) { |
|
143 | 143 | list($key) = array_values($row); |
144 | 144 | $result[$key] = $row; |
145 | 145 | } |
@@ -156,11 +156,11 @@ discard block |
||
156 | 156 | public function fetchGroups(array $fields) { |
157 | 157 | $rows = $this->fetchRows(); |
158 | 158 | $result = array(); |
159 | - foreach($rows as $row) { |
|
159 | + foreach ($rows as $row) { |
|
160 | 160 | $tmp = &$result; |
161 | - foreach($fields as $field) { |
|
161 | + foreach ($fields as $field) { |
|
162 | 162 | $value = $row[$field]; |
163 | - if(!array_key_exists($value, $tmp)) { |
|
163 | + if (!array_key_exists($value, $tmp)) { |
|
164 | 164 | $tmp[$value] = []; |
165 | 165 | } |
166 | 166 | $tmp = &$tmp[$value]; |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * @return string[] |
175 | 175 | */ |
176 | 176 | public function fetchArray() { |
177 | - return $this->createTempStatement(function (QueryStatement $stmt) { |
|
177 | + return $this->createTempStatement(function(QueryStatement $stmt) { |
|
178 | 178 | return $stmt->fetchAll(\PDO::FETCH_COLUMN); |
179 | 179 | }); |
180 | 180 | } |
@@ -184,9 +184,9 @@ discard block |
||
184 | 184 | * @return null|bool|string|int|float |
185 | 185 | */ |
186 | 186 | public function fetchValue($default = null) { |
187 | - return $this->createTempStatement(function (QueryStatement $stmt) use ($default) { |
|
187 | + return $this->createTempStatement(function(QueryStatement $stmt) use ($default) { |
|
188 | 188 | $result = $stmt->fetch(\PDO::FETCH_NUM); |
189 | - if($result !== false) { |
|
189 | + if ($result !== false) { |
|
190 | 190 | return $result[0]; |
191 | 191 | } |
192 | 192 | return $default; |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | $query = $this->__toString(); |
228 | 228 | $statement = $db->prepare($query); |
229 | 229 | $statement->execute($this->values); |
230 | - if($this->getCalcFoundRows()) { |
|
230 | + if ($this->getCalcFoundRows()) { |
|
231 | 231 | $this->foundRows = (int) $db->query('SELECT FOUND_ROWS()')->fetchColumn(); |
232 | 232 | } |
233 | 233 | return $statement; |
@@ -248,20 +248,20 @@ discard block |
||
248 | 248 | * @throws RuntimeException |
249 | 249 | */ |
250 | 250 | private function fetchAll(Closure $callback = null, $mode, $arg0 = null) { |
251 | - return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0) { |
|
251 | + return $this->createTempStatement(function(QueryStatement $statement) use ($callback, $mode, $arg0) { |
|
252 | 252 | $statement->setFetchMode($mode, $arg0); |
253 | 253 | $data = $statement->fetchAll(); |
254 | - if($this->preserveTypes) { |
|
254 | + if ($this->preserveTypes) { |
|
255 | 255 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
256 | - foreach($data as &$row) { |
|
256 | + foreach ($data as &$row) { |
|
257 | 257 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
258 | 258 | } |
259 | 259 | } |
260 | - if($callback !== null) { |
|
261 | - return call_user_func(function ($resultData = []) use ($data, $callback) { |
|
262 | - foreach($data as $row) { |
|
260 | + if ($callback !== null) { |
|
261 | + return call_user_func(function($resultData = []) use ($data, $callback) { |
|
262 | + foreach ($data as $row) { |
|
263 | 263 | $result = $callback($row); |
264 | - if($result !== null && !($result instanceof DBIgnoreRow)) { |
|
264 | + if ($result !== null && !($result instanceof DBIgnoreRow)) { |
|
265 | 265 | $resultData[] = $result; |
266 | 266 | } else { |
267 | 267 | $resultData[] = $row; |
@@ -281,8 +281,8 @@ discard block |
||
281 | 281 | * @return Traversable|YieldPolyfillIterator|mixed[] |
282 | 282 | */ |
283 | 283 | private function fetchLazy(Closure $callback = null, $mode, $arg0 = null) { |
284 | - if(version_compare(PHP_VERSION, '5.5', '<')) { |
|
285 | - return new YieldPolyfillIterator($callback, $this->preserveTypes, function () use ($mode, $arg0) { |
|
284 | + if (version_compare(PHP_VERSION, '5.5', '<')) { |
|
285 | + return new YieldPolyfillIterator($callback, $this->preserveTypes, function() use ($mode, $arg0) { |
|
286 | 286 | $statement = $this->createStatement(); |
287 | 287 | $statement->setFetchMode($mode, $arg0); |
288 | 288 | return $statement; |
@@ -303,20 +303,20 @@ discard block |
||
303 | 303 | * @throws \Exception |
304 | 304 | */ |
305 | 305 | private function fetch(Closure $callback = null, $mode, $arg0 = null, Closure $resultValidator = null) { |
306 | - return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) { |
|
306 | + return $this->createTempStatement(function(QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) { |
|
307 | 307 | $statement->setFetchMode($mode, $arg0); |
308 | 308 | $row = $statement->fetch(); |
309 | 309 | $result = $resultValidator($row); |
310 | - if(!$result['valid']) { |
|
310 | + if (!$result['valid']) { |
|
311 | 311 | return $result['default']; |
312 | 312 | } |
313 | - if($this->preserveTypes) { |
|
313 | + if ($this->preserveTypes) { |
|
314 | 314 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
315 | 315 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
316 | 316 | } |
317 | - if($callback !== null) { |
|
317 | + if ($callback !== null) { |
|
318 | 318 | $result = $callback($row); |
319 | - if($result !== null) { |
|
319 | + if ($result !== null) { |
|
320 | 320 | $row = $result; |
321 | 321 | } |
322 | 322 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @return $this |
89 | 89 | */ |
90 | 90 | public function addExpr($str, $_ = null) { |
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, $_ = null) { |
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 | } |
@@ -258,10 +258,10 @@ discard block |
||
258 | 258 | */ |
259 | 259 | private function buildUpdate() { |
260 | 260 | $queryArr = array(); |
261 | - if(!empty($this->update)) { |
|
261 | + if (!empty($this->update)) { |
|
262 | 262 | $queryArr[] = "ON DUPLICATE KEY UPDATE\n"; |
263 | 263 | $updateArr = array(); |
264 | - if($this->keyField !== null) { |
|
264 | + if ($this->keyField !== null) { |
|
265 | 265 | $updateArr[] = "\t`{$this->keyField}` = LAST_INSERT_ID({$this->keyField})"; |
266 | 266 | } |
267 | 267 | $updateArr = $this->buildFieldList($this->update, $updateArr); |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | * @throws Exception |
286 | 286 | */ |
287 | 287 | private function clearValues(array $values) { |
288 | - if(!count($values)) { |
|
288 | + if (!count($values)) { |
|
289 | 289 | return []; |
290 | 290 | } |
291 | 291 | |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | $result = array(); |
295 | 295 | |
296 | 296 | foreach ($values as $fieldName => $fieldValue) { |
297 | - if(in_array($fieldName, $fields)) { |
|
297 | + if (in_array($fieldName, $fields)) { |
|
298 | 298 | $result[$fieldName] = $fieldValue; |
299 | 299 | } |
300 | 300 | } |
@@ -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; |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | public function throwMoreConcreteException(PDOException $exception) { |
18 | 18 | $code = $exception->getCode(); |
19 | 19 | $message = (string) $exception->getMessage(); |
20 | - switch($code) { |
|
20 | + switch ($code) { |
|
21 | 21 | case 2006: throw new DatabaseHasGoneAwayException($message, $code, $exception); |
22 | 22 | case 1213: throw new SqlDeadLockException($message, $code, $exception); |
23 | 23 | case 1205: throw new LockWaitTimeoutExceededException($message, $code, $exception); |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | case 1217: throw new IntegrityConstraintViolationException($message, (int) $code, $exception); |
30 | 30 | } |
31 | 31 | /** @link http://php.net/manual/en/class.exception.php#Hcom115813 (cHao's comment) */ |
32 | - if(!is_string($message) || !is_int($code)) { |
|
32 | + if (!is_string($message) || !is_int($code)) { |
|
33 | 33 | throw new SqlException((string) $message, (int) $code, $exception); |
34 | 34 | } |
35 | 35 | throw $exception; |