@@ -27,8 +27,8 @@ |
||
27 | 27 | * @return DBExprFilter |
28 | 28 | */ |
29 | 29 | public function __invoke($expression, $keyPath, $validator = null) { |
30 | - return new DBExprFilter($expression, $this->map, $keyPath, $validator, function ($result, array $data) { |
|
31 | - if(!$result) { |
|
30 | + return new DBExprFilter($expression, $this->map, $keyPath, $validator, function($result, array $data) { |
|
31 | + if (!$result) { |
|
32 | 32 | throw new RequiredValueNotFoundException(sprintf("Required value %s not found", $data['key'])); |
33 | 33 | } |
34 | 34 | }); |
@@ -28,16 +28,16 @@ discard block |
||
28 | 28 | $this->value = $data; |
29 | 29 | $this->keyPath = $this->buildKey($keyPath); |
30 | 30 | $this->value = $this->recursiveGet($data, $this->keyPath, null); |
31 | - if($validator === null) { |
|
32 | - $validator = function ($data) { |
|
33 | - if(is_array($data)) { |
|
31 | + if ($validator === null) { |
|
32 | + $validator = function($data) { |
|
33 | + if (is_array($data)) { |
|
34 | 34 | return $this->isValidArray($data); |
35 | 35 | } |
36 | 36 | return (string) $data !== ''; |
37 | 37 | }; |
38 | 38 | } |
39 | - if($validationResultHandler === null) { |
|
40 | - $validationResultHandler = function () {}; |
|
39 | + if ($validationResultHandler === null) { |
|
40 | + $validationResultHandler = function() {}; |
|
41 | 41 | } |
42 | 42 | $this->validator = $validator; |
43 | 43 | $this->validationResultHandler = $validationResultHandler; |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | * @throws Exception |
76 | 76 | */ |
77 | 77 | private function buildKey($keyPath) { |
78 | - if(is_string($keyPath)) { |
|
78 | + if (is_string($keyPath)) { |
|
79 | 79 | $keyPath = explode('.', $keyPath); |
80 | 80 | } |
81 | - if(!is_array($keyPath)) { |
|
81 | + if (!is_array($keyPath)) { |
|
82 | 82 | throw new Exception('Invalid key'); |
83 | 83 | } |
84 | 84 | return $keyPath; |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | * @return bool |
90 | 90 | */ |
91 | 91 | private function isValidArray(array $array) { |
92 | - $data = array_filter($array, function ($value) { |
|
93 | - if(is_array($value)) { |
|
92 | + $data = array_filter($array, function($value) { |
|
93 | + if (is_array($value)) { |
|
94 | 94 | return $this->isValidArray($value); |
95 | 95 | } |
96 | 96 | return (string) $value !== ''; |
@@ -109,9 +109,9 @@ discard block |
||
109 | 109 | if (!$count) { |
110 | 110 | return $default; |
111 | 111 | } |
112 | - for($idx = 0; $idx < $count; $idx++) { |
|
112 | + for ($idx = 0; $idx < $count; $idx++) { |
|
113 | 113 | $part = $path[$idx]; |
114 | - if(!array_key_exists($part, $array)) { |
|
114 | + if (!array_key_exists($part, $array)) { |
|
115 | 115 | return $default; |
116 | 116 | } |
117 | 117 | $array = $array[$part]; |
@@ -28,10 +28,10 @@ |
||
28 | 28 | */ |
29 | 29 | protected function buildLimit($query, $offset = null) { |
30 | 30 | $limit = $this->limit; |
31 | - if($limit === null && $offset !== null) { |
|
31 | + if ($limit === null && $offset !== null) { |
|
32 | 32 | $limit = '18446744073709551615'; |
33 | 33 | } |
34 | - if($limit !== null) { |
|
34 | + if ($limit !== null) { |
|
35 | 35 | $query .= "LIMIT\n\t{$limit}\n"; |
36 | 36 | } |
37 | 37 | return $query; |
@@ -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; |
@@ -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); |
@@ -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( |
@@ -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; |
@@ -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 | } |