@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | * @return $this |
16 | 16 | */ |
17 | 17 | public function orderBy($expression, $direction = 'asc') { |
18 | - if($expression instanceof OrderBySpecification) { |
|
19 | - foreach($expression->getFields() as $field) { |
|
18 | + if ($expression instanceof OrderBySpecification) { |
|
19 | + foreach ($expression->getFields() as $field) { |
|
20 | 20 | $this->addOrder($field[0], $field[1]); |
21 | 21 | } |
22 | 22 | return $this; |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function orderByValues($fieldName, array $values) { |
34 | 34 | $expr = []; |
35 | - foreach(array_values($values) as $idx => $value) { |
|
35 | + foreach (array_values($values) as $idx => $value) { |
|
36 | 36 | $expr[] = $this->db()->quoteExpression("WHEN ? THEN ?", array($value, $idx)); |
37 | 37 | } |
38 | 38 | $this->orderBy[] = array(sprintf("CASE %s\n\t\t%s\n\tEND", $this->db()->quoteField($fieldName), join("\n\t\t", $expr)), 'ASC'); |
@@ -44,12 +44,12 @@ discard block |
||
44 | 44 | * @return string |
45 | 45 | */ |
46 | 46 | protected function buildOrder($query) { |
47 | - if(!count($this->orderBy)) { |
|
47 | + if (!count($this->orderBy)) { |
|
48 | 48 | return $query; |
49 | 49 | } |
50 | 50 | $query .= "ORDER BY\n"; |
51 | 51 | $arr = array(); |
52 | - foreach($this->orderBy as $order) { |
|
52 | + foreach ($this->orderBy as $order) { |
|
53 | 53 | list($expression, $direction) = $order; |
54 | 54 | $arr[] = sprintf("\t%s %s", $expression, strtoupper($direction)); |
55 | 55 | } |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | */ |
63 | 63 | private function addOrder($expression, $direction) { |
64 | 64 | $direction = $this->fixDirection($direction); |
65 | - if(is_array($expression)) { |
|
66 | - if(!count($expression)) { |
|
65 | + if (is_array($expression)) { |
|
66 | + if (!count($expression)) { |
|
67 | 67 | return; |
68 | 68 | } |
69 | 69 | $arguments = array( |
@@ -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 { |
@@ -11,16 +11,16 @@ |
||
11 | 11 | */ |
12 | 12 | public function __construct($spec, $sortFieldsSpec) { |
13 | 13 | $expressions = []; |
14 | - foreach($spec as $specReference => $dbExpr) { |
|
15 | - if(is_int($specReference)) { |
|
14 | + foreach ($spec as $specReference => $dbExpr) { |
|
15 | + if (is_int($specReference)) { |
|
16 | 16 | $specReference = $dbExpr; |
17 | 17 | } |
18 | 18 | $expressions[$specReference] = $dbExpr; |
19 | 19 | } |
20 | - foreach($sortFieldsSpec as $sortFieldSpec) { |
|
21 | - if(array_key_exists(0, $sortFieldSpec) && array_key_exists($sortFieldSpec[0], $expressions)) { |
|
20 | + foreach ($sortFieldsSpec as $sortFieldSpec) { |
|
21 | + if (array_key_exists(0, $sortFieldSpec) && array_key_exists($sortFieldSpec[0], $expressions)) { |
|
22 | 22 | $direction = 'ASC'; |
23 | - if(array_key_exists(1, $sortFieldSpec) && strtoupper($sortFieldSpec[1]) !== 'ASC') { |
|
23 | + if (array_key_exists(1, $sortFieldSpec) && strtoupper($sortFieldSpec[1]) !== 'ASC') { |
|
24 | 24 | $direction = 'DESC'; |
25 | 25 | } |
26 | 26 | $this->fields[] = [ |
@@ -16,14 +16,14 @@ |
||
16 | 16 | public function throwMoreConcreteException(PDOException $exception) { |
17 | 17 | $code = $exception->getCode(); |
18 | 18 | $message = (string) $exception->getMessage(); |
19 | - switch($code) { |
|
19 | + switch ($code) { |
|
20 | 20 | case 2006: throw new DatabaseHasGoneAwayException($message, $code, $exception); |
21 | 21 | case 1213: throw new SqlDeadLockException($message, $code, $exception); |
22 | 22 | case 1205: throw new LockWaitTimeoutExceededException($message, $code, $exception); |
23 | 23 | case 1062: throw new DuplicateUniqueKeyException($message, $code, $exception); |
24 | 24 | } |
25 | 25 | /** @link http://php.net/manual/en/class.exception.php#Hcom115813 (cHao's comment) */ |
26 | - if(!is_string($message) || !is_int($code)) { |
|
26 | + if (!is_string($message) || !is_int($code)) { |
|
27 | 27 | throw new SqlException((string) $message, (int) $code, $exception); |
28 | 28 | } |
29 | 29 | throw $exception; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @throws \Exception |
81 | 81 | */ |
82 | 82 | public function fetchRow(Closure $callback = null) { |
83 | - return $this->fetch($callback, PDO::FETCH_ASSOC, null, function ($row) { |
|
83 | + return $this->fetch($callback, PDO::FETCH_ASSOC, null, function($row) { |
|
84 | 84 | return ['valid' => is_array($row), 'default' => []]; |
85 | 85 | }); |
86 | 86 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @throws \Exception |
112 | 112 | */ |
113 | 113 | public function fetchObject($className = 'stdClass', Closure $callback = null) { |
114 | - return $this->fetch($callback, PDO::FETCH_CLASS, $className, function ($row) { |
|
114 | + return $this->fetch($callback, PDO::FETCH_CLASS, $className, function($row) { |
|
115 | 115 | return ['valid' => is_object($row), 'default' => null]; |
116 | 116 | }); |
117 | 117 | } |
@@ -121,11 +121,11 @@ discard block |
||
121 | 121 | * @return mixed[] |
122 | 122 | */ |
123 | 123 | public function fetchKeyValue($treatValueAsArray = false) { |
124 | - return $this->createTempStatement(function (QueryStatement $statement) use ($treatValueAsArray) { |
|
125 | - if($treatValueAsArray) { |
|
124 | + return $this->createTempStatement(function(QueryStatement $statement) use ($treatValueAsArray) { |
|
125 | + if ($treatValueAsArray) { |
|
126 | 126 | $rows = $statement->fetchAll(\PDO::FETCH_ASSOC); |
127 | 127 | $result = array(); |
128 | - foreach($rows as $row) { |
|
128 | + foreach ($rows as $row) { |
|
129 | 129 | list($key) = array_values($row); |
130 | 130 | $result[$key] = $row; |
131 | 131 | } |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | public function fetchGroups(array $fields) { |
143 | 143 | $rows = $this->fetchRows(); |
144 | 144 | $result = array(); |
145 | - foreach($rows as $row) { |
|
145 | + foreach ($rows as $row) { |
|
146 | 146 | $tmp = &$result; |
147 | - foreach($fields as $field) { |
|
147 | + foreach ($fields as $field) { |
|
148 | 148 | $value = $row[$field]; |
149 | - if(!array_key_exists($value, $tmp)) { |
|
149 | + if (!array_key_exists($value, $tmp)) { |
|
150 | 150 | $tmp[$value] = []; |
151 | 151 | } |
152 | 152 | $tmp = &$tmp[$value]; |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * @return string[] |
161 | 161 | */ |
162 | 162 | public function fetchArray() { |
163 | - return $this->createTempStatement(function (QueryStatement $stmt) { |
|
163 | + return $this->createTempStatement(function(QueryStatement $stmt) { |
|
164 | 164 | return $stmt->fetchAll(\PDO::FETCH_COLUMN); |
165 | 165 | }); |
166 | 166 | } |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | * @return null|bool|string|int|float |
171 | 171 | */ |
172 | 172 | public function fetchValue($default = null) { |
173 | - return $this->createTempStatement(function (QueryStatement $stmt) use ($default) { |
|
173 | + return $this->createTempStatement(function(QueryStatement $stmt) use ($default) { |
|
174 | 174 | $result = $stmt->fetch(\PDO::FETCH_NUM); |
175 | - if($result !== false) { |
|
175 | + if ($result !== false) { |
|
176 | 176 | return $result[0]; |
177 | 177 | } |
178 | 178 | return $default; |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $query = $this->__toString(); |
213 | 213 | $statement = $db->prepare($query); |
214 | 214 | $statement->execute($this->values); |
215 | - if($this->getCalcFoundRows()) { |
|
215 | + if ($this->getCalcFoundRows()) { |
|
216 | 216 | $this->foundRows = (int) $db->query('SELECT FOUND_ROWS()')->fetchColumn(); |
217 | 217 | } |
218 | 218 | return $statement; |
@@ -233,20 +233,20 @@ discard block |
||
233 | 233 | * @throws \Exception |
234 | 234 | */ |
235 | 235 | private function fetchAll(Closure $callback = null, $mode, $arg0 = null) { |
236 | - return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0) { |
|
236 | + return $this->createTempStatement(function(QueryStatement $statement) use ($callback, $mode, $arg0) { |
|
237 | 237 | $statement->setFetchMode($mode, $arg0); |
238 | 238 | $data = $statement->fetchAll(); |
239 | - if($this->preserveTypes) { |
|
239 | + if ($this->preserveTypes) { |
|
240 | 240 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
241 | - foreach($data as &$row) { |
|
241 | + foreach ($data as &$row) { |
|
242 | 242 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
243 | 243 | } |
244 | 244 | } |
245 | - if($callback !== null) { |
|
246 | - return call_user_func(function ($resultData = []) use ($data, $callback) { |
|
247 | - foreach($data as $row) { |
|
245 | + if ($callback !== null) { |
|
246 | + return call_user_func(function($resultData = []) use ($data, $callback) { |
|
247 | + foreach ($data as $row) { |
|
248 | 248 | $result = $callback($row); |
249 | - if($result !== null && !($result instanceof DBIgnoreRow)) { |
|
249 | + if ($result !== null && !($result instanceof DBIgnoreRow)) { |
|
250 | 250 | $resultData[] = $result; |
251 | 251 | } else { |
252 | 252 | $resultData[] = $row; |
@@ -266,8 +266,8 @@ discard block |
||
266 | 266 | * @return Generator|YieldPolyfillIterator|mixed[] |
267 | 267 | */ |
268 | 268 | private function fetchLazy(Closure $callback = null, $mode, $arg0 = null) { |
269 | - if(version_compare(PHP_VERSION, '5.5', '<')) { |
|
270 | - return new YieldPolyfillIterator($callback, $this->preserveTypes, function () use ($mode, $arg0) { |
|
269 | + if (version_compare(PHP_VERSION, '5.5', '<')) { |
|
270 | + return new YieldPolyfillIterator($callback, $this->preserveTypes, function() use ($mode, $arg0) { |
|
271 | 271 | $statement = $this->createStatement(); |
272 | 272 | $statement->setFetchMode($mode, $arg0); |
273 | 273 | return $statement; |
@@ -288,20 +288,20 @@ discard block |
||
288 | 288 | * @throws \Exception |
289 | 289 | */ |
290 | 290 | private function fetch(Closure $callback = null, $mode, $arg0 = null, Closure $resultValidator = null) { |
291 | - return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) { |
|
291 | + return $this->createTempStatement(function(QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) { |
|
292 | 292 | $statement->setFetchMode($mode, $arg0); |
293 | 293 | $row = $statement->fetch(); |
294 | 294 | $result = $resultValidator($row); |
295 | - if(!$result['valid']) { |
|
295 | + if (!$result['valid']) { |
|
296 | 296 | return $result['default']; |
297 | 297 | } |
298 | - if($this->preserveTypes) { |
|
298 | + if ($this->preserveTypes) { |
|
299 | 299 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
300 | 300 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
301 | 301 | } |
302 | - if($callback !== null) { |
|
302 | + if ($callback !== null) { |
|
303 | 303 | $result = $callback($row); |
304 | - if($result !== null) { |
|
304 | + if ($result !== null) { |
|
305 | 305 | $row = $result; |
306 | 306 | } |
307 | 307 | } |