@@ -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 | } |
@@ -47,10 +47,10 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function setFetchMode(int $mode = PDO::FETCH_ASSOC, $arg0 = null, ?array $arg1 = null) { |
49 | 49 | $args = [$mode]; |
50 | - if($arg0 !== null) { |
|
50 | + if ($arg0 !== null) { |
|
51 | 51 | $args[] = $arg0; |
52 | 52 | } |
53 | - if($arg1 !== null) { |
|
53 | + if ($arg1 !== null) { |
|
54 | 54 | $args[] = $arg1; |
55 | 55 | } |
56 | 56 | $this->statement->setFetchMode(...$args); |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | $this->exceptionHandler(function() use ($params) { |
67 | 67 | $this->queryLoggers->logRegion($this->query, function() use ($params) { |
68 | 68 | $response = $this->statement->execute($params); |
69 | - if(!$response) { |
|
69 | + if (!$response) { |
|
70 | 70 | throw new SqlException('Execution returned with "false".'); |
71 | 71 | } |
72 | 72 | }); |
@@ -82,13 +82,13 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function fetchAll($fetchStyle = PDO::FETCH_ASSOC, $fetchArgument = null, array $ctorArgs = []): array { |
84 | 84 | $result = $x = $this->exceptionHandler(function() use ($fetchStyle, $fetchArgument, $ctorArgs) { |
85 | - if($fetchArgument !== null) { |
|
85 | + if ($fetchArgument !== null) { |
|
86 | 86 | return $this->statement->fetchAll($fetchStyle, $fetchArgument, ...$ctorArgs); |
87 | 87 | } |
88 | 88 | return $this->statement->fetchAll($fetchStyle); |
89 | 89 | }); |
90 | 90 | /** @var array<mixed, mixed>|false $x */ |
91 | - if($x === false) { |
|
91 | + if ($x === false) { |
|
92 | 92 | return []; |
93 | 93 | } |
94 | 94 | return $result; |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | public function getColumnMeta(int $columnNo): ?array { |
142 | 142 | return $this->exceptionHandler(function() use ($columnNo) { |
143 | 143 | $columnMeta = $this->statement->getColumnMeta($columnNo); |
144 | - if($columnMeta === false) { |
|
144 | + if ($columnMeta === false) { |
|
145 | 145 | return null; |
146 | 146 | } |
147 | 147 | return $columnMeta; |
@@ -9,13 +9,13 @@ |
||
9 | 9 | use Rector\Set\ValueObject\LevelSetList; |
10 | 10 | |
11 | 11 | return static function (RectorConfig $rectorConfig): void { |
12 | - $rectorConfig->paths([ |
|
13 | - __DIR__ . '/src', |
|
14 | - __DIR__ . '/tests', |
|
15 | - ]); |
|
12 | + $rectorConfig->paths([ |
|
13 | + __DIR__ . '/src', |
|
14 | + __DIR__ . '/tests', |
|
15 | + ]); |
|
16 | 16 | |
17 | - // register a single rule |
|
18 | - $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); |
|
17 | + // register a single rule |
|
18 | + $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); |
|
19 | 19 | |
20 | 20 | $rectorConfig->skip([RemoveUselessParamTagRector::class]); |
21 | 21 | $rectorConfig->skip([MixedTypeRector::class]); |
@@ -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); |
@@ -14,34 +14,34 @@ |
||
14 | 14 | * @return string |
15 | 15 | */ |
16 | 16 | protected function buildTableName(?string $alias, $name): string { |
17 | - if(is_object($name) && !($name instanceof VirtualTable) && method_exists($name, '__toString')) { |
|
17 | + if (is_object($name) && !($name instanceof VirtualTable) && method_exists($name, '__toString')) { |
|
18 | 18 | $name = (string) $name; |
19 | 19 | $lines = explode("\n", $name); |
20 | 20 | $lines = array_map(static fn(string $line) => "\t{$line}", $lines); |
21 | 21 | $name = implode("\n", $lines); |
22 | - $name = '(' . trim(rtrim(trim($name), ';')) . ')'; |
|
22 | + $name = '('.trim(rtrim(trim($name), ';')).')'; |
|
23 | 23 | } |
24 | - if(is_array($name)) { |
|
24 | + if (is_array($name)) { |
|
25 | 25 | $parts = []; |
26 | - foreach($name as $index => $bucket) { |
|
27 | - if(is_scalar($bucket) && ctype_digit((string) $index)) { |
|
26 | + foreach ($name as $index => $bucket) { |
|
27 | + if (is_scalar($bucket) && ctype_digit((string) $index)) { |
|
28 | 28 | $parts[] = "SELECT {$this->db()->quote($bucket)} AS {$this->db()->quoteField('value')}"; |
29 | 29 | } else { |
30 | 30 | $values = []; |
31 | - foreach($bucket as $field => $value) { |
|
31 | + foreach ($bucket as $field => $value) { |
|
32 | 32 | $values[] = sprintf('%s AS %s', $this->db()->quote($value), $this->db()->quoteField($field)); |
33 | 33 | } |
34 | 34 | $parts[] = sprintf("SELECT %s", implode(', ', $values)); |
35 | 35 | } |
36 | 36 | } |
37 | - $name = '(' . implode("\n\tUNION ALL\n\t", $parts) . ')'; |
|
37 | + $name = '('.implode("\n\tUNION ALL\n\t", $parts).')'; |
|
38 | 38 | } |
39 | - if((is_string($name) || $name instanceof VirtualTable) && $this->db()->getVirtualTables()->has($name)) { |
|
39 | + if ((is_string($name) || $name instanceof VirtualTable) && $this->db()->getVirtualTables()->has($name)) { |
|
40 | 40 | $select = (string) $this->db()->getVirtualTables()->get($name); |
41 | 41 | $name = sprintf('(%s)', implode("\n\t", explode("\n", trim($select)))); |
42 | 42 | } |
43 | 43 | $name = $this->aliasReplacer()->replace((string) $name); |
44 | - if($alias !== null) { |
|
44 | + if ($alias !== null) { |
|
45 | 45 | return sprintf("%s %s", $name, $alias); |
46 | 46 | } |
47 | 47 | return $name; |
@@ -28,11 +28,11 @@ discard block |
||
28 | 28 | * @param null|string|Select $table |
29 | 29 | * @return $this |
30 | 30 | */ |
31 | - public function from(string $alias, null|string|Select $table = null) { |
|
32 | - if($table !== null) { |
|
31 | + public function from(string $alias, null | string | Select $table = null) { |
|
32 | + if ($table !== null) { |
|
33 | 33 | $this->aliases[] = $alias; |
34 | 34 | } |
35 | - if($table === null) { |
|
35 | + if ($table === null) { |
|
36 | 36 | [$alias, $table] = [$table, $alias]; |
37 | 37 | } |
38 | 38 | $this->addTable($alias, $table); |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | public function __toString(): string { |
52 | 52 | $query = 'DELETE '; |
53 | 53 | $query .= implode(', ', $this->aliases); |
54 | - $query = trim($query) . " FROM\n"; |
|
54 | + $query = trim($query)." FROM\n"; |
|
55 | 55 | $query = $this->buildTables($query); |
56 | 56 | $query = $this->buildJoins($query); |
57 | 57 | $query = $this->buildWhereConditions($query); |
@@ -30,12 +30,12 @@ discard block |
||
30 | 30 | $this->keyPath = $this->buildKey($keyPath); |
31 | 31 | $this->value = RecursiveStructureAccess::recursiveGet($data, $this->keyPath, null); |
32 | 32 | $this->hasValue = is_scalar($this->value) ? trim((string) $this->value) !== '' : !empty($this->value); |
33 | - if($validator === null) { |
|
33 | + if ($validator === null) { |
|
34 | 34 | $validator = static fn() => true; |
35 | 35 | } |
36 | 36 | $this->validator = $validator; |
37 | - if($validationResultHandler === null) { |
|
38 | - $validationResultHandler = static function () {}; |
|
37 | + if ($validationResultHandler === null) { |
|
38 | + $validationResultHandler = static function() {}; |
|
39 | 39 | } |
40 | 40 | $this->validationResultHandler = $validationResultHandler; |
41 | 41 | } |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | * @return bool |
52 | 52 | */ |
53 | 53 | public function isValid(): bool { |
54 | - if(!$this->hasValue) { |
|
54 | + if (!$this->hasValue) { |
|
55 | 55 | return false; |
56 | 56 | } |
57 | - if($this->validator !== null) { |
|
57 | + if ($this->validator !== null) { |
|
58 | 58 | $result = call_user_func($this->validator, $this->value); |
59 | 59 | call_user_func($this->validationResultHandler, $result, [ |
60 | 60 | 'value' => $this->value, |
@@ -77,10 +77,10 @@ discard block |
||
77 | 77 | * @return string[] |
78 | 78 | */ |
79 | 79 | private function buildKey($keyPath): array { |
80 | - if(is_string($keyPath)) { |
|
80 | + if (is_string($keyPath)) { |
|
81 | 81 | $keyPath = explode('.', $keyPath); |
82 | 82 | } |
83 | - if(!is_array($keyPath)) { |
|
83 | + if (!is_array($keyPath)) { |
|
84 | 84 | throw new RuntimeException('Invalid key'); |
85 | 85 | } |
86 | 86 | return $keyPath; |