@@ -14,17 +14,17 @@ discard block |
||
14 | 14 | */ |
15 | 15 | public function __construct(array $spec, array $sortFieldsSpec) { |
16 | 16 | $expressions = []; |
17 | - foreach($spec as $specReference => $dbExpr) { |
|
18 | - if(is_int($specReference)) { |
|
17 | + foreach ($spec as $specReference => $dbExpr) { |
|
18 | + if (is_int($specReference)) { |
|
19 | 19 | $specReference = $dbExpr; |
20 | 20 | } |
21 | 21 | $expressions[$specReference] = $dbExpr; |
22 | 22 | } |
23 | - foreach($sortFieldsSpec as $sortFieldSpec) { |
|
24 | - if(array_key_exists(0, $sortFieldSpec)) { |
|
25 | - if(array_key_exists($sortFieldSpec[0], $expressions)) { |
|
23 | + foreach ($sortFieldsSpec as $sortFieldSpec) { |
|
24 | + if (array_key_exists(0, $sortFieldSpec)) { |
|
25 | + if (array_key_exists($sortFieldSpec[0], $expressions)) { |
|
26 | 26 | $direction = 'ASC'; |
27 | - if(array_key_exists(1, $sortFieldSpec) && strtoupper($sortFieldSpec[1]) !== 'ASC') { |
|
27 | + if (array_key_exists(1, $sortFieldSpec) && strtoupper($sortFieldSpec[1]) !== 'ASC') { |
|
28 | 28 | $direction = 'DESC'; |
29 | 29 | } |
30 | 30 | $this->fields[] = [ |
@@ -33,9 +33,9 @@ discard block |
||
33 | 33 | ]; |
34 | 34 | } |
35 | 35 | } else { // @phpstan-ignore-line |
36 | - foreach($sortFieldSpec as $alias => $direction) { |
|
36 | + foreach ($sortFieldSpec as $alias => $direction) { |
|
37 | 37 | $direction = strtoupper($direction) === 'DESC' ? 'DESC' : 'ASC'; |
38 | - if(array_key_exists($alias, $expressions)) { |
|
38 | + if (array_key_exists($alias, $expressions)) { |
|
39 | 39 | $this->fields[] = [$expressions[$alias], $direction]; |
40 | 40 | } |
41 | 41 | } |
@@ -36,7 +36,7 @@ |
||
36 | 36 | * @return DBExprFilter |
37 | 37 | */ |
38 | 38 | public function __invoke(string $expression, $keyPath, $validator = null) { |
39 | - if(!RecursiveStructureAccess::recursiveHas($this->map, $keyPath)) { |
|
39 | + if (!RecursiveStructureAccess::recursiveHas($this->map, $keyPath)) { |
|
40 | 40 | throw new RequiredValueNotFoundException(sprintf("Required value %s not found", json_encode($keyPath, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE))); |
41 | 41 | } |
42 | 42 | return new DBExprFilter($expression, $this->map, $keyPath, $validator); |
@@ -41,13 +41,13 @@ |
||
41 | 41 | public function getFields(): array { |
42 | 42 | $fields = []; |
43 | 43 | $max = $this->options['max_sort_instructions'] ?? 16; |
44 | - foreach($this->sortingInstruction as $alias => $direction) { |
|
44 | + foreach ($this->sortingInstruction as $alias => $direction) { |
|
45 | 45 | $direction = strtolower($direction) === 'desc' ? 'DESC' : 'ASC'; |
46 | - if(!array_key_exists($alias, $this->sortSpecification)) { |
|
46 | + if (!array_key_exists($alias, $this->sortSpecification)) { |
|
47 | 47 | throw new DBSortAliasNotFoundException('Sorting: Alias for DB-Expression not found'); |
48 | 48 | } |
49 | 49 | $fields[] = [$this->sortSpecification[$alias], $direction]; |
50 | - if($max < 1) { |
|
50 | + if ($max < 1) { |
|
51 | 51 | throw new DBSortTooManyInstructionsException(); |
52 | 52 | } |
53 | 53 | $max--; |
@@ -19,7 +19,7 @@ |
||
19 | 19 | /** @link http://php.net/manual/en/class.exception.php#Hcom115813 (cHao's comment) */ |
20 | 20 | $code = is_array($errorInfo) && isset($errorInfo[1]) ? ((int) $errorInfo[1]) : ((int) $exception->getCode()); |
21 | 21 | $message = $exception->getMessage(); |
22 | - switch($code) { |
|
22 | + switch ($code) { |
|
23 | 23 | case 2006: return new DatabaseHasGoneAwayException($message, $code, $exception); |
24 | 24 | case 1213: return new SqlDeadLockException($message, $code, $exception); |
25 | 25 | case 1205: return new LockWaitTimeoutExceededException($message, $code, $exception); |
@@ -25,12 +25,12 @@ |
||
25 | 25 | $timer = microtime(true); |
26 | 26 | try { |
27 | 27 | return $fn(); |
28 | - } catch(Throwable $e) { |
|
28 | + } catch (Throwable $e) { |
|
29 | 29 | $exception = $e; |
30 | 30 | throw $e; |
31 | 31 | } finally { |
32 | - $finalTimer = microtime(true) - $timer; |
|
33 | - if($exception === null) { |
|
32 | + $finalTimer = microtime(true)-$timer; |
|
33 | + if ($exception === null) { |
|
34 | 34 | $this->log($query, $finalTimer); |
35 | 35 | } else { |
36 | 36 | $this->logError($query, $exception, $finalTimer); |
@@ -10,10 +10,10 @@ |
||
10 | 10 | */ |
11 | 11 | public static function getFieldTypes(QueryStatement $statement): array { |
12 | 12 | $fieldTypes = []; |
13 | - for($i = 0; $column = $statement->getColumnMeta($i); $i++) { |
|
13 | + for ($i = 0; $column = $statement->getColumnMeta($i); $i++) { |
|
14 | 14 | $name = $column['name'] ?? null; |
15 | 15 | $nativeType = $column['native_type'] ?? null; |
16 | - if(is_string($name) && is_string($nativeType)) { |
|
16 | + if (is_string($name) && is_string($nativeType)) { |
|
17 | 17 | $fieldTypes[$name] = self::getTypeFromNativeType($nativeType); |
18 | 18 | } |
19 | 19 | } |
@@ -8,10 +8,10 @@ |
||
8 | 8 | use Rector\Php80\Rector\FunctionLike\MixedTypeRector; |
9 | 9 | use Rector\Set\ValueObject\LevelSetList; |
10 | 10 | |
11 | -return static function (RectorConfig $rectorConfig): void { |
|
11 | +return static function(RectorConfig $rectorConfig): void { |
|
12 | 12 | $rectorConfig->paths([ |
13 | - __DIR__ . '/src', |
|
14 | - __DIR__ . '/tests', |
|
13 | + __DIR__.'/src', |
|
14 | + __DIR__.'/tests', |
|
15 | 15 | ]); |
16 | 16 | |
17 | 17 | // register a single rule |
@@ -14,16 +14,16 @@ discard block |
||
14 | 14 | * @return string |
15 | 15 | */ |
16 | 16 | public static function build(Database $db, string $query, array $conditions, string $token): string { |
17 | - if(!count($conditions)) { |
|
17 | + if (!count($conditions)) { |
|
18 | 18 | return $query; |
19 | 19 | } |
20 | 20 | $query .= "{$token}\n"; |
21 | 21 | $arr = []; |
22 | - foreach($conditions as [$expression, $arguments]) { |
|
23 | - if(is_array($expression)) { |
|
24 | - foreach($expression as $key => $value) { |
|
22 | + foreach ($conditions as [$expression, $arguments]) { |
|
23 | + if (is_array($expression)) { |
|
24 | + foreach ($expression as $key => $value) { |
|
25 | 25 | $key = self::formatKey($key); |
26 | - if($value === null) { |
|
26 | + if ($value === null) { |
|
27 | 27 | $arr = self::buildCondition($arr, "ISNULL({$key})", [$value], $db); |
28 | 28 | } else { |
29 | 29 | $arr = self::buildCondition($arr, "{$key}=?", [$value], $db); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @return string |
56 | 56 | */ |
57 | 57 | private static function formatKey(string $key): string { |
58 | - if(strpos($key, '`') !== false || strpos($key, '(') !== false) { |
|
58 | + if (strpos($key, '`') !== false || strpos($key, '(') !== false) { |
|
59 | 59 | return $key; |
60 | 60 | } |
61 | 61 | $keyParts = explode('.', $key); |
@@ -101,17 +101,17 @@ discard block |
||
101 | 101 | * @inheritDoc |
102 | 102 | */ |
103 | 103 | public function fetchObjects(string $className = 'stdClass', $callback = null): array { |
104 | - return $this->createTempStatement(function (QueryStatement $statement) use ($className, $callback) { |
|
104 | + return $this->createTempStatement(function(QueryStatement $statement) use ($className, $callback) { |
|
105 | 105 | $data = $statement->fetchAll(PDO::FETCH_CLASS, $className); |
106 | - if($this->preserveTypes) { |
|
106 | + if ($this->preserveTypes) { |
|
107 | 107 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
108 | 108 | $data = array_map(static fn($row) => FieldValueConverter::convertValues($row, $columnDefinitions), $data); |
109 | 109 | } |
110 | - if($callback !== null) { |
|
111 | - return call_user_func(static function ($resultData = []) use ($data, $callback) { |
|
112 | - foreach($data as $row) { |
|
110 | + if ($callback !== null) { |
|
111 | + return call_user_func(static function($resultData = []) use ($data, $callback) { |
|
112 | + foreach ($data as $row) { |
|
113 | 113 | $result = $callback($row); |
114 | - if($result !== null && !($result instanceof DBIgnoreRow)) { |
|
114 | + if ($result !== null && !($result instanceof DBIgnoreRow)) { |
|
115 | 115 | $resultData[] = $result; |
116 | 116 | } else { |
117 | 117 | $resultData[] = $row; |
@@ -147,11 +147,11 @@ discard block |
||
147 | 147 | * @inheritDoc |
148 | 148 | */ |
149 | 149 | public function fetchKeyValue($treatValueAsArray = false): array { |
150 | - return $this->createTempStatement(static function (QueryStatement $statement) use ($treatValueAsArray) { |
|
151 | - if($treatValueAsArray) { |
|
150 | + return $this->createTempStatement(static function(QueryStatement $statement) use ($treatValueAsArray) { |
|
151 | + if ($treatValueAsArray) { |
|
152 | 152 | $rows = $statement->fetchAll(PDO::FETCH_ASSOC); |
153 | 153 | $result = []; |
154 | - foreach($rows as $row) { |
|
154 | + foreach ($rows as $row) { |
|
155 | 155 | [$key] = array_values($row); |
156 | 156 | $result[$key] = $row; |
157 | 157 | } |
@@ -167,12 +167,12 @@ discard block |
||
167 | 167 | public function fetchGroups(array $fields): array { |
168 | 168 | $rows = $this->fetchRows(); |
169 | 169 | $result = []; |
170 | - foreach($rows as $row) { |
|
170 | + foreach ($rows as $row) { |
|
171 | 171 | /** @var array<string, mixed> $tmp */ |
172 | 172 | $tmp = &$result; |
173 | - foreach($fields as $field) { |
|
173 | + foreach ($fields as $field) { |
|
174 | 174 | $value = (string) $row[$field]; |
175 | - if(!array_key_exists($value, $tmp)) { |
|
175 | + if (!array_key_exists($value, $tmp)) { |
|
176 | 176 | $tmp[$value] = []; |
177 | 177 | } |
178 | 178 | $tmp = &$tmp[$value]; |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | * @inheritDoc |
187 | 187 | */ |
188 | 188 | public function fetchArray(?callable $fn = null): array { |
189 | - return $this->createTempStatement(static function (QueryStatement $stmt) use ($fn) { |
|
190 | - if($fn !== null) { |
|
189 | + return $this->createTempStatement(static function(QueryStatement $stmt) use ($fn) { |
|
190 | + if ($fn !== null) { |
|
191 | 191 | return $stmt->fetchAll(PDO::FETCH_FUNC, $fn); |
192 | 192 | } |
193 | 193 | return $stmt->fetchAll(PDO::FETCH_COLUMN); |
@@ -198,9 +198,9 @@ discard block |
||
198 | 198 | * @inheritDoc |
199 | 199 | */ |
200 | 200 | public function fetchValue($default = null, ?callable $fn = null) { |
201 | - return $this->createTempStatement(static function (QueryStatement $stmt) use ($default, $fn) { |
|
201 | + return $this->createTempStatement(static function(QueryStatement $stmt) use ($default, $fn) { |
|
202 | 202 | $result = $stmt->fetchAll(PDO::FETCH_COLUMN); |
203 | - if($result !== false && array_key_exists(0, $result)) { |
|
203 | + if ($result !== false && array_key_exists(0, $result)) { |
|
204 | 204 | return $fn !== null ? $fn($result[0]) : $result[0]; |
205 | 205 | } |
206 | 206 | return $default; |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | $query = $this->__toString(); |
236 | 236 | $statement = $db->prepare($query); |
237 | 237 | $statement->execute($this->values); |
238 | - if($this->getCalcFoundRows()) { |
|
238 | + if ($this->getCalcFoundRows()) { |
|
239 | 239 | $this->foundRows = (int) $db->query('SELECT FOUND_ROWS()')->fetchColumn(); |
240 | 240 | } |
241 | 241 | return $statement; |
@@ -256,21 +256,21 @@ discard block |
||
256 | 256 | * @return ($callback is null ? array<int, ($mode is PDO::FETCH_NUM ? array<int, null|scalar> : array<string, null|scalar>)> : array<int, TFnReturnType>) |
257 | 257 | */ |
258 | 258 | private function fetchAll($callback = null, int $mode = 0, $arg0 = null) { |
259 | - return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0) { |
|
259 | + return $this->createTempStatement(function(QueryStatement $statement) use ($callback, $mode, $arg0) { |
|
260 | 260 | $statement->setFetchMode($mode, $arg0); |
261 | 261 | $data = $statement->fetchAll(); |
262 | - if($this->preserveTypes) { |
|
262 | + if ($this->preserveTypes) { |
|
263 | 263 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
264 | 264 | $data = array_map(static fn($row) => FieldValueConverter::convertValues($row, $columnDefinitions), $data); |
265 | 265 | } |
266 | - if($callback !== null) { |
|
267 | - return call_user_func(static function ($resultData = []) use ($data, $callback) { |
|
268 | - foreach($data as $row) { |
|
266 | + if ($callback !== null) { |
|
267 | + return call_user_func(static function($resultData = []) use ($data, $callback) { |
|
268 | + foreach ($data as $row) { |
|
269 | 269 | $result = $callback($row); |
270 | - if($result instanceof DBIgnoreRow) { |
|
270 | + if ($result instanceof DBIgnoreRow) { |
|
271 | 271 | continue; |
272 | 272 | } |
273 | - if($result !== null) { |
|
273 | + if ($result !== null) { |
|
274 | 274 | $resultData[] = $result; |
275 | 275 | } else { |
276 | 276 | $resultData[] = $row; |
@@ -294,18 +294,18 @@ discard block |
||
294 | 294 | $statement = $this->createStatement(); |
295 | 295 | $statement->setFetchMode($mode, $arg0); |
296 | 296 | try { |
297 | - while($row = $statement->fetch()) { |
|
297 | + while ($row = $statement->fetch()) { |
|
298 | 298 | /** @var T $row */ |
299 | 299 | // if($this->preserveTypes) { |
300 | 300 | // $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
301 | 301 | // $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
302 | 302 | // } |
303 | 303 | $result = $callback($row); |
304 | - if($result instanceof DBIgnoreRow) { |
|
304 | + if ($result instanceof DBIgnoreRow) { |
|
305 | 305 | // Skip row in this case |
306 | 306 | continue; |
307 | 307 | } |
308 | - if($result !== null) { |
|
308 | + if ($result !== null) { |
|
309 | 309 | yield $result; |
310 | 310 | } else { |
311 | 311 | yield $row; |
@@ -326,20 +326,20 @@ discard block |
||
326 | 326 | * @return T|U|array<string, mixed> |
327 | 327 | */ |
328 | 328 | private function fetch($callback, int $mode = PDO::FETCH_ASSOC, $arg0 = null, ?Closure $resultValidator = null) { |
329 | - return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) { |
|
329 | + return $this->createTempStatement(function(QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) { |
|
330 | 330 | $statement->setFetchMode($mode, $arg0); |
331 | 331 | $row = $statement->fetch(); |
332 | 332 | $result = $resultValidator === null ? ['valid' => true] : $resultValidator($row); |
333 | - if(!$result['valid']) { |
|
333 | + if (!$result['valid']) { |
|
334 | 334 | return $result['default']; |
335 | 335 | } |
336 | - if($this->preserveTypes) { |
|
336 | + if ($this->preserveTypes) { |
|
337 | 337 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
338 | 338 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
339 | 339 | } |
340 | - if($callback !== null) { |
|
340 | + if ($callback !== null) { |
|
341 | 341 | $result = $callback($row); |
342 | - if($result !== null) { |
|
342 | + if ($result !== null) { |
|
343 | 343 | $row = $result; |
344 | 344 | } |
345 | 345 | } |