@@ -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); |
@@ -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,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; |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | $errorInfo = $exception->errorInfo; |
19 | 19 | $code = is_array($errorInfo) && isset($errorInfo[1]) ? ((int) $errorInfo[1]) : ((int) $exception->getCode()); |
20 | 20 | $message = (string) $exception->getMessage(); |
21 | - switch($code) { |
|
21 | + switch ($code) { |
|
22 | 22 | case 2006: throw new DatabaseHasGoneAwayException($message, $code, $exception); |
23 | 23 | case 1213: throw new SqlDeadLockException($message, $code, $exception); |
24 | 24 | case 1205: throw new LockWaitTimeoutExceededException($message, $code, $exception); |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | case 1452: throw new IntegrityConstraintViolationException($message, (int) $code, $exception); |
32 | 32 | } |
33 | 33 | /** @link http://php.net/manual/en/class.exception.php#Hcom115813 (cHao's comment) */ |
34 | - if(!is_string($message) || !is_int($code)) { |
|
34 | + if (!is_string($message) || !is_int($code)) { |
|
35 | 35 | throw new SqlException((string) $message, (int) $code, $exception); |
36 | 36 | } |
37 | 37 | throw $exception; |
@@ -27,16 +27,16 @@ discard block |
||
27 | 27 | $this->value = $data; |
28 | 28 | $this->keyPath = $this->buildKey($keyPath); |
29 | 29 | $this->value = $this->recursiveGet($data, $this->keyPath, null); |
30 | - if($validator === null) { |
|
31 | - $validator = function ($data) { |
|
32 | - if(is_array($data)) { |
|
30 | + if ($validator === null) { |
|
31 | + $validator = function($data) { |
|
32 | + if (is_array($data)) { |
|
33 | 33 | return $this->isValidArray($data); |
34 | 34 | } |
35 | 35 | return (string) $data !== ''; |
36 | 36 | }; |
37 | 37 | } |
38 | - if($validationResultHandler === null) { |
|
39 | - $validationResultHandler = function () {}; |
|
38 | + if ($validationResultHandler === null) { |
|
39 | + $validationResultHandler = function() {}; |
|
40 | 40 | } |
41 | 41 | $this->validator = $validator; |
42 | 42 | $this->validationResultHandler = $validationResultHandler; |
@@ -73,10 +73,10 @@ discard block |
||
73 | 73 | * @return string |
74 | 74 | */ |
75 | 75 | private function buildKey($keyPath) { |
76 | - if(is_string($keyPath)) { |
|
76 | + if (is_string($keyPath)) { |
|
77 | 77 | $keyPath = explode('.', $keyPath); |
78 | 78 | } |
79 | - if(!is_array($keyPath)) { |
|
79 | + if (!is_array($keyPath)) { |
|
80 | 80 | throw new RuntimeException('Invalid key'); |
81 | 81 | } |
82 | 82 | return $keyPath; |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | * @return bool |
88 | 88 | */ |
89 | 89 | private function isValidArray(array $array) { |
90 | - $data = array_filter($array, function ($value) { |
|
91 | - if(is_array($value)) { |
|
90 | + $data = array_filter($array, function($value) { |
|
91 | + if (is_array($value)) { |
|
92 | 92 | return $this->isValidArray($value); |
93 | 93 | } |
94 | 94 | return (string) $value !== ''; |
@@ -107,9 +107,9 @@ discard block |
||
107 | 107 | if (!$count) { |
108 | 108 | return $default; |
109 | 109 | } |
110 | - for($idx = 0; $idx < $count; $idx++) { |
|
110 | + for ($idx = 0; $idx < $count; $idx++) { |
|
111 | 111 | $part = $path[$idx]; |
112 | - if(!array_key_exists($part, $array)) { |
|
112 | + if (!array_key_exists($part, $array)) { |
|
113 | 113 | return $default; |
114 | 114 | } |
115 | 115 | $array = $array[$part]; |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | /** |
236 | 236 | * @param Closure $callback |
237 | 237 | * @param int $mode |
238 | - * @param mixed $arg0 |
|
238 | + * @param string $arg0 |
|
239 | 239 | * @return mixed |
240 | 240 | */ |
241 | 241 | private function fetchAll(Closure $callback = null, $mode, $arg0 = null) { |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | /** |
269 | 269 | * @param Closure $callback |
270 | 270 | * @param int $mode |
271 | - * @param mixed $arg0 |
|
271 | + * @param string $arg0 |
|
272 | 272 | * @return Traversable|mixed[] |
273 | 273 | */ |
274 | 274 | private function fetchLazy(Closure $callback = null, $mode, $arg0 = null) { |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | /** |
282 | 282 | * @param Closure $callback |
283 | 283 | * @param int $mode |
284 | - * @param mixed $arg0 |
|
284 | + * @param null|string $arg0 |
|
285 | 285 | * @param Closure $resultValidator |
286 | 286 | * @return mixed |
287 | 287 | */ |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @return mixed[] |
92 | 92 | */ |
93 | 93 | public function fetchRow(Closure $callback = null) { |
94 | - return $this->fetch($callback, PDO::FETCH_ASSOC, null, function ($row) { |
|
94 | + return $this->fetch($callback, PDO::FETCH_ASSOC, null, function($row) { |
|
95 | 95 | return ['valid' => is_array($row), 'default' => []]; |
96 | 96 | }); |
97 | 97 | } |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * @return object[] |
121 | 121 | */ |
122 | 122 | public function fetchObject($className = null, Closure $callback = null) { |
123 | - return $this->fetch($callback, PDO::FETCH_CLASS, $className ?: $this->defaultClassName, function ($row) { |
|
123 | + return $this->fetch($callback, PDO::FETCH_CLASS, $className ?: $this->defaultClassName, function($row) { |
|
124 | 124 | return ['valid' => is_object($row), 'default' => null]; |
125 | 125 | }); |
126 | 126 | } |
@@ -130,11 +130,11 @@ discard block |
||
130 | 130 | * @return mixed[] |
131 | 131 | */ |
132 | 132 | public function fetchKeyValue($treatValueAsArray = false) { |
133 | - return $this->createTempStatement(function (QueryStatement $statement) use ($treatValueAsArray) { |
|
134 | - if($treatValueAsArray) { |
|
133 | + return $this->createTempStatement(function(QueryStatement $statement) use ($treatValueAsArray) { |
|
134 | + if ($treatValueAsArray) { |
|
135 | 135 | $rows = $statement->fetchAll(\PDO::FETCH_ASSOC); |
136 | 136 | $result = []; |
137 | - foreach($rows as $row) { |
|
137 | + foreach ($rows as $row) { |
|
138 | 138 | list($key) = array_values($row); |
139 | 139 | $result[$key] = $row; |
140 | 140 | } |
@@ -151,11 +151,11 @@ discard block |
||
151 | 151 | public function fetchGroups(array $fields) { |
152 | 152 | $rows = $this->fetchRows(); |
153 | 153 | $result = []; |
154 | - foreach($rows as $row) { |
|
154 | + foreach ($rows as $row) { |
|
155 | 155 | $tmp = &$result; |
156 | - foreach($fields as $field) { |
|
156 | + foreach ($fields as $field) { |
|
157 | 157 | $value = $row[$field]; |
158 | - if(!array_key_exists($value, $tmp)) { |
|
158 | + if (!array_key_exists($value, $tmp)) { |
|
159 | 159 | $tmp[$value] = []; |
160 | 160 | } |
161 | 161 | $tmp = &$tmp[$value]; |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | * @return string[] |
170 | 170 | */ |
171 | 171 | public function fetchArray() { |
172 | - return $this->createTempStatement(function (QueryStatement $stmt) { |
|
172 | + return $this->createTempStatement(function(QueryStatement $stmt) { |
|
173 | 173 | return $stmt->fetchAll(\PDO::FETCH_COLUMN); |
174 | 174 | }); |
175 | 175 | } |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | * @return null|bool|string|int|float |
180 | 180 | */ |
181 | 181 | public function fetchValue($default = null) { |
182 | - return $this->createTempStatement(function (QueryStatement $stmt) use ($default) { |
|
182 | + return $this->createTempStatement(function(QueryStatement $stmt) use ($default) { |
|
183 | 183 | $result = $stmt->fetch(\PDO::FETCH_NUM); |
184 | - if($result !== false) { |
|
184 | + if ($result !== false) { |
|
185 | 185 | return $result[0]; |
186 | 186 | } |
187 | 187 | return $default; |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | $query = $this->__toString(); |
220 | 220 | $statement = $db->prepare($query); |
221 | 221 | $statement->execute($this->values); |
222 | - if($this->getCalcFoundRows()) { |
|
222 | + if ($this->getCalcFoundRows()) { |
|
223 | 223 | $this->foundRows = (int) $db->query('SELECT FOUND_ROWS()')->fetchColumn(); |
224 | 224 | } |
225 | 225 | return $statement; |
@@ -239,20 +239,20 @@ discard block |
||
239 | 239 | * @return mixed |
240 | 240 | */ |
241 | 241 | private function fetchAll(Closure $callback = null, $mode, $arg0 = null) { |
242 | - return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0) { |
|
242 | + return $this->createTempStatement(function(QueryStatement $statement) use ($callback, $mode, $arg0) { |
|
243 | 243 | $statement->setFetchMode($mode, $arg0); |
244 | 244 | $data = $statement->fetchAll(); |
245 | - if($this->preserveTypes) { |
|
245 | + if ($this->preserveTypes) { |
|
246 | 246 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
247 | - foreach($data as &$row) { |
|
247 | + foreach ($data as &$row) { |
|
248 | 248 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
249 | 249 | } |
250 | 250 | } |
251 | - if($callback !== null) { |
|
252 | - return call_user_func(function ($resultData = []) use ($data, $callback) { |
|
253 | - foreach($data as $row) { |
|
251 | + if ($callback !== null) { |
|
252 | + return call_user_func(function($resultData = []) use ($data, $callback) { |
|
253 | + foreach ($data as $row) { |
|
254 | 254 | $result = $callback($row); |
255 | - if($result !== null && !($result instanceof DBIgnoreRow)) { |
|
255 | + if ($result !== null && !($result instanceof DBIgnoreRow)) { |
|
256 | 256 | $resultData[] = $result; |
257 | 257 | } else { |
258 | 258 | $resultData[] = $row; |
@@ -286,20 +286,20 @@ discard block |
||
286 | 286 | * @return mixed |
287 | 287 | */ |
288 | 288 | private function fetch(Closure $callback = null, $mode, $arg0 = null, Closure $resultValidator = null) { |
289 | - return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) { |
|
289 | + return $this->createTempStatement(function(QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) { |
|
290 | 290 | $statement->setFetchMode($mode, $arg0); |
291 | 291 | $row = $statement->fetch(); |
292 | 292 | $result = $resultValidator($row); |
293 | - if(!$result['valid']) { |
|
293 | + if (!$result['valid']) { |
|
294 | 294 | return $result['default']; |
295 | 295 | } |
296 | - if($this->preserveTypes) { |
|
296 | + if ($this->preserveTypes) { |
|
297 | 297 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
298 | 298 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
299 | 299 | } |
300 | - if($callback !== null) { |
|
300 | + if ($callback !== null) { |
|
301 | 301 | $result = $callback($row); |
302 | - if($result !== null) { |
|
302 | + if ($result !== null) { |
|
303 | 303 | $row = $result; |
304 | 304 | } |
305 | 305 | } |