@@ -21,16 +21,16 @@ |
||
21 | 21 | * @return array[]|\Generator |
22 | 22 | */ |
23 | 23 | public function generate(QueryStatement $statement, Closure $callback = null) { |
24 | - while($row = $statement->fetch()) { |
|
25 | - if($this->preserveTypes) { |
|
24 | + while ($row = $statement->fetch()) { |
|
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 | $result = $callback($row); |
31 | - if($result instanceof DBIgnoreRow) { |
|
31 | + if ($result instanceof DBIgnoreRow) { |
|
32 | 32 | // Do nothing in this case |
33 | - } elseif($result !== null) { |
|
33 | + } elseif ($result !== null) { |
|
34 | 34 | yield $result; |
35 | 35 | } else { |
36 | 36 | yield $row; |
@@ -63,20 +63,20 @@ discard block |
||
63 | 63 | * @return array[] |
64 | 64 | */ |
65 | 65 | public function fetchRows(Closure $callback = null) { |
66 | - return $this->createTempStatement(function (QueryStatement $statement) use ($callback) { |
|
66 | + return $this->createTempStatement(function(QueryStatement $statement) use ($callback) { |
|
67 | 67 | $statement->setFetchMode(PDO::FETCH_ASSOC); |
68 | 68 | $data = $statement->fetchAll(); |
69 | - if($this->preserveTypes) { |
|
69 | + if ($this->preserveTypes) { |
|
70 | 70 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
71 | - foreach($data as &$row) { |
|
71 | + foreach ($data as &$row) { |
|
72 | 72 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
73 | 73 | } |
74 | 74 | } |
75 | - if($callback !== null) { |
|
76 | - return call_user_func(function ($resultData = []) use ($data, $callback) { |
|
77 | - foreach($data as $row) { |
|
75 | + if ($callback !== null) { |
|
76 | + return call_user_func(function($resultData = []) use ($data, $callback) { |
|
77 | + foreach ($data as $row) { |
|
78 | 78 | $result = $callback($row); |
79 | - if($result !== null && !($result instanceof DBIgnoreRow)) { |
|
79 | + if ($result !== null && !($result instanceof DBIgnoreRow)) { |
|
80 | 80 | $resultData[] = $result; |
81 | 81 | } else { |
82 | 82 | $resultData[] = $row; |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | * @return array[]|\Generator |
95 | 95 | */ |
96 | 96 | public function fetchRowsLazy(Closure $callback = null) { |
97 | - if(version_compare(PHP_VERSION, '5.5', '<')) { |
|
98 | - return new YieldPolyfillIterator($callback, $this->preserveTypes, function () { |
|
97 | + if (version_compare(PHP_VERSION, '5.5', '<')) { |
|
98 | + return new YieldPolyfillIterator($callback, $this->preserveTypes, function() { |
|
99 | 99 | $statement = $this->createStatement(); |
100 | 100 | $statement->setFetchMode(PDO::FETCH_ASSOC); |
101 | 101 | return $statement; |
@@ -113,19 +113,19 @@ discard block |
||
113 | 113 | * @throws \Exception |
114 | 114 | */ |
115 | 115 | public function fetchRow(Closure $callback = null) { |
116 | - return $this->createTempStatement(function (QueryStatement $statement) use ($callback) { |
|
116 | + return $this->createTempStatement(function(QueryStatement $statement) use ($callback) { |
|
117 | 117 | $statement->setFetchMode(PDO::FETCH_ASSOC); |
118 | 118 | $row = $statement->fetch(); |
119 | - if(!is_array($row)) { |
|
119 | + if (!is_array($row)) { |
|
120 | 120 | return []; |
121 | 121 | } |
122 | - if($this->preserveTypes) { |
|
122 | + if ($this->preserveTypes) { |
|
123 | 123 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
124 | 124 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
125 | 125 | } |
126 | - if($callback !== null) { |
|
126 | + if ($callback !== null) { |
|
127 | 127 | $result = $callback($row); |
128 | - if($result !== null) { |
|
128 | + if ($result !== null) { |
|
129 | 129 | $row = $result; |
130 | 130 | } |
131 | 131 | } |
@@ -140,20 +140,20 @@ discard block |
||
140 | 140 | * @throws \Exception |
141 | 141 | */ |
142 | 142 | public function fetchObjects($className, Closure $callback = null) { |
143 | - return $this->createTempStatement(function (QueryStatement $statement) use ($className, $callback) { |
|
143 | + return $this->createTempStatement(function(QueryStatement $statement) use ($className, $callback) { |
|
144 | 144 | $statement->setFetchMode(PDO::FETCH_CLASS, $className); |
145 | 145 | $data = $statement->fetchAll(); |
146 | - if($this->preserveTypes) { |
|
146 | + if ($this->preserveTypes) { |
|
147 | 147 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
148 | - foreach($data as &$row) { |
|
148 | + foreach ($data as &$row) { |
|
149 | 149 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
150 | 150 | } |
151 | 151 | } |
152 | - if($callback !== null) { |
|
153 | - return call_user_func(function ($resultData = []) use ($data, $callback) { |
|
154 | - foreach($data as $row) { |
|
152 | + if ($callback !== null) { |
|
153 | + return call_user_func(function($resultData = []) use ($data, $callback) { |
|
154 | + foreach ($data as $row) { |
|
155 | 155 | $result = $callback($row); |
156 | - if($result !== null && !($result instanceof DBIgnoreRow)) { |
|
156 | + if ($result !== null && !($result instanceof DBIgnoreRow)) { |
|
157 | 157 | $resultData[] = $result; |
158 | 158 | } else { |
159 | 159 | $resultData[] = $row; |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | * @return array[]|Generator |
173 | 173 | */ |
174 | 174 | public function fetchObjectsLazy($className, Closure $callback = null) { |
175 | - if(version_compare(PHP_VERSION, '5.5', '<')) { |
|
176 | - return new YieldPolyfillIterator($callback, $this->preserveTypes, function () use ($className) { |
|
175 | + if (version_compare(PHP_VERSION, '5.5', '<')) { |
|
176 | + return new YieldPolyfillIterator($callback, $this->preserveTypes, function() use ($className) { |
|
177 | 177 | $statement = $this->createStatement(); |
178 | 178 | $statement->setFetchMode(PDO::FETCH_CLASS, $className); |
179 | 179 | return $statement; |
@@ -192,19 +192,19 @@ discard block |
||
192 | 192 | * @throws \Exception |
193 | 193 | */ |
194 | 194 | public function fetchObject($className, Closure $callback = null) { |
195 | - return $this->createTempStatement(function (QueryStatement $statement) use ($className, $callback) { |
|
195 | + return $this->createTempStatement(function(QueryStatement $statement) use ($className, $callback) { |
|
196 | 196 | $statement->setFetchMode(PDO::FETCH_CLASS, $className); |
197 | 197 | $row = $statement->fetch(); |
198 | - if(!is_array($row)) { |
|
198 | + if (!is_array($row)) { |
|
199 | 199 | return []; |
200 | 200 | } |
201 | - if($this->preserveTypes) { |
|
201 | + if ($this->preserveTypes) { |
|
202 | 202 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
203 | 203 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
204 | 204 | } |
205 | - if($callback !== null) { |
|
205 | + if ($callback !== null) { |
|
206 | 206 | $result = $callback($row); |
207 | - if($result !== null) { |
|
207 | + if ($result !== null) { |
|
208 | 208 | $row = $result; |
209 | 209 | } |
210 | 210 | } |
@@ -217,11 +217,11 @@ discard block |
||
217 | 217 | * @return mixed[] |
218 | 218 | */ |
219 | 219 | public function fetchKeyValue($treatValueAsArray = false) { |
220 | - return $this->createTempStatement(function (QueryStatement $statement) use ($treatValueAsArray) { |
|
221 | - if($treatValueAsArray) { |
|
220 | + return $this->createTempStatement(function(QueryStatement $statement) use ($treatValueAsArray) { |
|
221 | + if ($treatValueAsArray) { |
|
222 | 222 | $rows = $statement->fetchAll(\PDO::FETCH_ASSOC); |
223 | 223 | $result = array(); |
224 | - foreach($rows as $row) { |
|
224 | + foreach ($rows as $row) { |
|
225 | 225 | list($key) = array_values($row); |
226 | 226 | $result[$key] = $row; |
227 | 227 | } |
@@ -238,11 +238,11 @@ discard block |
||
238 | 238 | public function fetchGroups(array $fields) { |
239 | 239 | $rows = $this->fetchRows(); |
240 | 240 | $result = array(); |
241 | - foreach($rows as $row) { |
|
241 | + foreach ($rows as $row) { |
|
242 | 242 | $tmp = &$result; |
243 | - foreach($fields as $field) { |
|
243 | + foreach ($fields as $field) { |
|
244 | 244 | $value = $row[$field]; |
245 | - if(!array_key_exists($value, $tmp)) { |
|
245 | + if (!array_key_exists($value, $tmp)) { |
|
246 | 246 | $tmp[$value] = []; |
247 | 247 | } |
248 | 248 | $tmp = &$tmp[$value]; |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | * @return string[] |
257 | 257 | */ |
258 | 258 | public function fetchArray() { |
259 | - return $this->createTempStatement(function (QueryStatement $stmt) { |
|
259 | + return $this->createTempStatement(function(QueryStatement $stmt) { |
|
260 | 260 | return $stmt->fetchAll(\PDO::FETCH_COLUMN); |
261 | 261 | }); |
262 | 262 | } |
@@ -266,9 +266,9 @@ discard block |
||
266 | 266 | * @return null|bool|string|int|float |
267 | 267 | */ |
268 | 268 | public function fetchValue($default = null) { |
269 | - return $this->createTempStatement(function (QueryStatement $stmt) use ($default) { |
|
269 | + return $this->createTempStatement(function(QueryStatement $stmt) use ($default) { |
|
270 | 270 | $result = $stmt->fetch(\PDO::FETCH_NUM); |
271 | - if($result !== false) { |
|
271 | + if ($result !== false) { |
|
272 | 272 | return $result[0]; |
273 | 273 | } |
274 | 274 | return $default; |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | $query = $this->__toString(); |
309 | 309 | $statement = $db->prepare($query); |
310 | 310 | $statement->execute($this->values); |
311 | - if($this->getCalcFoundRows()) { |
|
311 | + if ($this->getCalcFoundRows()) { |
|
312 | 312 | $this->foundRows = (int) $db->query('SELECT FOUND_ROWS()')->fetchColumn(); |
313 | 313 | } |
314 | 314 | return $statement; |
@@ -46,12 +46,12 @@ discard block |
||
46 | 46 | * @return $this |
47 | 47 | */ |
48 | 48 | public function setFetchMode($mode, $arg0 = null, array $arg1 = null) { |
49 | - if($arg1 !== null) { |
|
49 | + if ($arg1 !== null) { |
|
50 | 50 | /** @noinspection PhpMethodParametersCountMismatchInspection */ |
51 | 51 | $this->statement->setFetchMode($mode, $arg0, $arg1); |
52 | 52 | return $this; |
53 | 53 | } |
54 | - if($arg0 !== null) { |
|
54 | + if ($arg0 !== null) { |
|
55 | 55 | /** @noinspection PhpMethodParametersCountMismatchInspection */ |
56 | 56 | $this->statement->setFetchMode($mode, $arg0); |
57 | 57 | return $this; |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $timer = microtime(true); |
71 | 71 | $response = $this->statement->execute($params); |
72 | 72 | $this->queryLoggers->log($this->query, microtime(true)-$timer); |
73 | - if(!$response) { |
|
73 | + if (!$response) { |
|
74 | 74 | throw new SqlException('Execution returned with "false".'); |
75 | 75 | } |
76 | 76 | }); |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public function fetchAll($fetchStyle = null, $fetchArgument = null, array $ctorArgs = []) { |
87 | 87 | return $this->exceptionHandler(function() use ($fetchStyle, $fetchArgument, $ctorArgs) { |
88 | - if($fetchArgument !== null) { |
|
88 | + if ($fetchArgument !== null) { |
|
89 | 89 | return $this->statement->fetchAll($fetchStyle, $fetchArgument, $ctorArgs); |
90 | 90 | } |
91 | 91 | return $this->statement->fetchAll($fetchStyle); |