@@ -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, $_) { |
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 | } |
@@ -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 | } |
@@ -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, $_) { |
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, $_) { |
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 { |