@@ -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 |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @param array<string, mixed> $options |
| 52 | 52 | */ |
| 53 | 53 | public function __construct(PDO $pdo, array $options = []) { |
| 54 | - if($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) { |
|
| 54 | + if ($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) { |
|
| 55 | 55 | $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 56 | 56 | } |
| 57 | 57 | $this->pdo = $pdo; |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | ]; |
| 67 | 67 | $this->options = array_merge($defaultOptions, $options); |
| 68 | 68 | $this->options['timezone'] = $this->options['timezone'] ?? date_default_timezone_get(); |
| 69 | - if(!($this->options['timezone'] instanceof DateTimeZone)) { |
|
| 69 | + if (!($this->options['timezone'] instanceof DateTimeZone)) { |
|
| 70 | 70 | $this->options['timezone'] = new DateTimeZone((string) $this->options['timezone']); |
| 71 | 71 | } |
| 72 | 72 | $this->quoter = new MySQLQuoter($pdo, $this->options['timezone']); |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @return VirtualTables |
| 91 | 91 | */ |
| 92 | 92 | public function getVirtualTables(): VirtualTables { |
| 93 | - if($this->virtualTables === null) { |
|
| 93 | + if ($this->virtualTables === null) { |
|
| 94 | 94 | $this->virtualTables = new VirtualTables(); |
| 95 | 95 | } |
| 96 | 96 | return $this->virtualTables; |
@@ -135,11 +135,11 @@ discard block |
||
| 135 | 135 | array $params = [] |
| 136 | 136 | ): int { |
| 137 | 137 | return $this->getQueryLoggers()->logRegion($query, fn() => |
| 138 | - $this->exceptionHandler(function () use ($query, $params) { |
|
| 138 | + $this->exceptionHandler(function() use ($query, $params) { |
|
| 139 | 139 | $stmt = $this->pdo->prepare($query); |
| 140 | 140 | $timer = microtime(true); |
| 141 | 141 | $stmt->execute($params); |
| 142 | - $this->queryLoggers->log($query, microtime(true) - $timer); |
|
| 142 | + $this->queryLoggers->log($query, microtime(true)-$timer); |
|
| 143 | 143 | $result = $stmt->rowCount(); |
| 144 | 144 | $stmt->closeCursor(); |
| 145 | 145 | return $result; |
@@ -161,15 +161,15 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | public function getTableFields(string $table): array { |
| 163 | 163 | $fqTable = $this->select()->aliasReplacer()->replace($table); |
| 164 | - if(array_key_exists($fqTable, $this->tableFields)) { |
|
| 164 | + if (array_key_exists($fqTable, $this->tableFields)) { |
|
| 165 | 165 | return $this->tableFields[$fqTable]; |
| 166 | 166 | } |
| 167 | 167 | $query = "DESCRIBE {$fqTable}"; |
| 168 | 168 | return $this->getQueryLoggers()->logRegion($query, fn() => |
| 169 | - $this->exceptionHandler(function () use ($query, $fqTable) { |
|
| 169 | + $this->exceptionHandler(function() use ($query, $fqTable) { |
|
| 170 | 170 | $stmt = $this->pdo->query($query); |
| 171 | 171 | try { |
| 172 | - if($stmt === false) { |
|
| 172 | + if ($stmt === false) { |
|
| 173 | 173 | throw new RuntimeException('Invalid return type'); |
| 174 | 174 | } |
| 175 | 175 | $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | $select = array_key_exists('select-factory', $this->options) |
| 218 | 218 | ? call_user_func($this->options['select-factory'], $this, $this->options['select-options']) |
| 219 | 219 | : new MySQL\MySQLRunnableSelect($this, $this->options['select-options']); |
| 220 | - if($fields !== null) { |
|
| 220 | + if ($fields !== null) { |
|
| 221 | 221 | $select->fields($fields); |
| 222 | 222 | } |
| 223 | 223 | return $select; |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | $insert = array_key_exists('insert-factory', $this->options) |
| 232 | 232 | ? call_user_func($this->options['insert-factory'], $this, $this->options['insert-options']) |
| 233 | 233 | : new Builder\RunnableInsert($this, $this->options['insert-options']); |
| 234 | - if($fields !== null) { |
|
| 234 | + if ($fields !== null) { |
|
| 235 | 235 | $insert->addAll($fields); |
| 236 | 236 | } |
| 237 | 237 | return $insert; |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | $update = array_key_exists('update-factory', $this->options) |
| 246 | 246 | ? call_user_func($this->options['update-factory'], $this, $this->options['update-options']) |
| 247 | 247 | : new Builder\RunnableUpdate($this, $this->options['update-options']); |
| 248 | - if($fields !== null) { |
|
| 248 | + if ($fields !== null) { |
|
| 249 | 249 | $update->setAll($fields); |
| 250 | 250 | } |
| 251 | 251 | return $update; |
@@ -264,8 +264,8 @@ discard block |
||
| 264 | 264 | * @return $this |
| 265 | 265 | */ |
| 266 | 266 | public function transactionStart() { |
| 267 | - if($this->transactionLevel === 0) { |
|
| 268 | - if($this->pdo->inTransaction()) { |
|
| 267 | + if ($this->transactionLevel === 0) { |
|
| 268 | + if ($this->pdo->inTransaction()) { |
|
| 269 | 269 | $this->outerTransaction = true; |
| 270 | 270 | } else { |
| 271 | 271 | $this->pdo->beginTransaction(); |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | * @return $this |
| 280 | 280 | */ |
| 281 | 281 | public function transactionCommit() { |
| 282 | - return $this->transactionEnd(function () { |
|
| 282 | + return $this->transactionEnd(function() { |
|
| 283 | 283 | $this->pdo->commit(); |
| 284 | 284 | }); |
| 285 | 285 | } |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | * @return $this |
| 289 | 289 | */ |
| 290 | 290 | public function transactionRollback() { |
| 291 | - return $this->transactionEnd(function () { |
|
| 291 | + return $this->transactionEnd(function() { |
|
| 292 | 292 | $this->pdo->rollBack(); |
| 293 | 293 | }); |
| 294 | 294 | } |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @return T |
| 300 | 300 | */ |
| 301 | 301 | public function dryRun(callable $callback) { |
| 302 | - if(!$this->pdo->inTransaction()) { |
|
| 302 | + if (!$this->pdo->inTransaction()) { |
|
| 303 | 303 | $this->transactionStart(); |
| 304 | 304 | try { |
| 305 | 305 | return $callback($this); |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | * @throws Throwable |
| 325 | 325 | */ |
| 326 | 326 | public function transaction(callable $callback) { |
| 327 | - if(!$this->pdo->inTransaction()) { |
|
| 327 | + if (!$this->pdo->inTransaction()) { |
|
| 328 | 328 | $this->transactionStart(); |
| 329 | 329 | try { |
| 330 | 330 | $result = $callback($this); |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | return $result; |
| 333 | 333 | } catch (Throwable $e) { |
| 334 | 334 | // @phpstan-ignore-next-line; If condition is always false as it is not. |
| 335 | - if($this->pdo->inTransaction()) { |
|
| 335 | + if ($this->pdo->inTransaction()) { |
|
| 336 | 336 | $this->transactionRollback(); |
| 337 | 337 | } |
| 338 | 338 | throw $e; |
@@ -356,11 +356,11 @@ discard block |
||
| 356 | 356 | */ |
| 357 | 357 | private function transactionEnd($fn): self { |
| 358 | 358 | $this->transactionLevel--; |
| 359 | - if($this->transactionLevel < 0) { |
|
| 359 | + if ($this->transactionLevel < 0) { |
|
| 360 | 360 | throw new RuntimeException("Transaction-Nesting-Problem: Trying to invoke commit on a already closed transaction"); |
| 361 | 361 | } |
| 362 | - if($this->transactionLevel < 1) { |
|
| 363 | - if($this->outerTransaction) { |
|
| 362 | + if ($this->transactionLevel < 1) { |
|
| 363 | + if ($this->outerTransaction) { |
|
| 364 | 364 | $this->outerTransaction = false; |
| 365 | 365 | } else { |
| 366 | 366 | $fn(); |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | */ |
| 378 | 378 | private function buildQueryStatement(string $query, callable $fn): QueryStatement { |
| 379 | 379 | $stmt = $fn($query); |
| 380 | - if(!$stmt) { |
|
| 380 | + if (!$stmt) { |
|
| 381 | 381 | throw new RuntimeException("Could not execute statement:\n{$query}"); |
| 382 | 382 | } |
| 383 | 383 | return new QueryStatement($stmt, $query, $this->exceptionInterpreter, $this->queryLoggers); |
@@ -104,17 +104,17 @@ discard block |
||
| 104 | 104 | * @inheritDoc |
| 105 | 105 | */ |
| 106 | 106 | public function fetchObjects(string $className = 'stdClass', $callback = null): array { |
| 107 | - return $this->createTempStatement(function (QueryStatement $statement) use ($className, $callback) { |
|
| 107 | + return $this->createTempStatement(function(QueryStatement $statement) use ($className, $callback) { |
|
| 108 | 108 | $data = $statement->fetchAll(PDO::FETCH_CLASS, $className); |
| 109 | - if($this->preserveTypes) { |
|
| 109 | + if ($this->preserveTypes) { |
|
| 110 | 110 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
| 111 | 111 | $data = array_map(static fn($row) => FieldValueConverter::convertValues($row, $columnDefinitions), $data); |
| 112 | 112 | } |
| 113 | - if($callback !== null) { |
|
| 114 | - return call_user_func(static function ($resultData = []) use ($data, $callback) { |
|
| 115 | - foreach($data as $row) { |
|
| 113 | + if ($callback !== null) { |
|
| 114 | + return call_user_func(static function($resultData = []) use ($data, $callback) { |
|
| 115 | + foreach ($data as $row) { |
|
| 116 | 116 | $result = $callback($row); |
| 117 | - if($result !== null && !($result instanceof DBIgnoreRow)) { |
|
| 117 | + if ($result !== null && !($result instanceof DBIgnoreRow)) { |
|
| 118 | 118 | $resultData[] = $result; |
| 119 | 119 | } else { |
| 120 | 120 | $resultData[] = $row; |
@@ -150,11 +150,11 @@ discard block |
||
| 150 | 150 | * @inheritDoc |
| 151 | 151 | */ |
| 152 | 152 | public function fetchKeyValue($treatValueAsArray = false): array { |
| 153 | - return $this->createTempStatement(static function (QueryStatement $statement) use ($treatValueAsArray) { |
|
| 154 | - if($treatValueAsArray) { |
|
| 153 | + return $this->createTempStatement(static function(QueryStatement $statement) use ($treatValueAsArray) { |
|
| 154 | + if ($treatValueAsArray) { |
|
| 155 | 155 | $rows = $statement->fetchAll(PDO::FETCH_ASSOC); |
| 156 | 156 | $result = []; |
| 157 | - foreach($rows as $row) { |
|
| 157 | + foreach ($rows as $row) { |
|
| 158 | 158 | [$key] = array_values($row); |
| 159 | 159 | $result[$key] = $row; |
| 160 | 160 | } |
@@ -170,12 +170,12 @@ discard block |
||
| 170 | 170 | public function fetchGroups(array $fields): array { |
| 171 | 171 | $rows = $this->fetchRows(); |
| 172 | 172 | $result = []; |
| 173 | - foreach($rows as $row) { |
|
| 173 | + foreach ($rows as $row) { |
|
| 174 | 174 | /** @var array<string, mixed> $tmp */ |
| 175 | 175 | $tmp = &$result; |
| 176 | - foreach($fields as $field) { |
|
| 176 | + foreach ($fields as $field) { |
|
| 177 | 177 | $value = (string) $row[$field]; |
| 178 | - if(!array_key_exists($value, $tmp)) { |
|
| 178 | + if (!array_key_exists($value, $tmp)) { |
|
| 179 | 179 | $tmp[$value] = []; |
| 180 | 180 | } |
| 181 | 181 | $tmp = &$tmp[$value]; |
@@ -189,8 +189,8 @@ discard block |
||
| 189 | 189 | * @inheritDoc |
| 190 | 190 | */ |
| 191 | 191 | public function fetchArray(?callable $fn = null): array { |
| 192 | - return $this->createTempStatement(static function (QueryStatement $stmt) use ($fn) { |
|
| 193 | - if($fn !== null) { |
|
| 192 | + return $this->createTempStatement(static function(QueryStatement $stmt) use ($fn) { |
|
| 193 | + if ($fn !== null) { |
|
| 194 | 194 | return $stmt->fetchAll(PDO::FETCH_FUNC, $fn); |
| 195 | 195 | } |
| 196 | 196 | return $stmt->fetchAll(PDO::FETCH_COLUMN); |
@@ -201,9 +201,9 @@ discard block |
||
| 201 | 201 | * @inheritDoc |
| 202 | 202 | */ |
| 203 | 203 | public function fetchValue($default = null, ?callable $fn = null) { |
| 204 | - return $this->createTempStatement(static function (QueryStatement $stmt) use ($default, $fn) { |
|
| 204 | + return $this->createTempStatement(static function(QueryStatement $stmt) use ($default, $fn) { |
|
| 205 | 205 | $result = $stmt->fetchAll(PDO::FETCH_COLUMN); |
| 206 | - if($result !== false && array_key_exists(0, $result)) { |
|
| 206 | + if ($result !== false && array_key_exists(0, $result)) { |
|
| 207 | 207 | return $fn !== null ? $fn($result[0]) : $result[0]; |
| 208 | 208 | } |
| 209 | 209 | return $default; |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | $query = $this->__toString(); |
| 239 | 239 | $statement = $db->prepare($query); |
| 240 | 240 | $statement->execute($this->values); |
| 241 | - if($this->getCalcFoundRows()) { |
|
| 241 | + if ($this->getCalcFoundRows()) { |
|
| 242 | 242 | $this->foundRows = (int) $db->query('SELECT FOUND_ROWS()')->fetchColumn(); |
| 243 | 243 | } |
| 244 | 244 | return $statement; |
@@ -260,21 +260,21 @@ discard block |
||
| 260 | 260 | * @return ($callback is null ? array<int, ($mode is PDO::FETCH_NUM ? array<int, null|scalar> : array<string, null|scalar>)> : array<int, TFnReturnType|TFnParamType>) |
| 261 | 261 | */ |
| 262 | 262 | private function fetchAll($callback = null, int $mode = 0, $arg0 = null) { |
| 263 | - return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0) { |
|
| 263 | + return $this->createTempStatement(function(QueryStatement $statement) use ($callback, $mode, $arg0) { |
|
| 264 | 264 | $statement->setFetchMode($mode, $arg0); |
| 265 | 265 | $data = $statement->fetchAll(); |
| 266 | - if($this->preserveTypes) { |
|
| 266 | + if ($this->preserveTypes) { |
|
| 267 | 267 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
| 268 | 268 | $data = array_map(static fn($row) => FieldValueConverter::convertValues($row, $columnDefinitions), $data); |
| 269 | 269 | } |
| 270 | - if($callback !== null) { |
|
| 271 | - return call_user_func(static function ($resultData = []) use ($data, $callback) { |
|
| 272 | - foreach($data as $row) { |
|
| 270 | + if ($callback !== null) { |
|
| 271 | + return call_user_func(static function($resultData = []) use ($data, $callback) { |
|
| 272 | + foreach ($data as $row) { |
|
| 273 | 273 | $result = $callback($row); |
| 274 | - if($result instanceof DBIgnoreRow) { |
|
| 274 | + if ($result instanceof DBIgnoreRow) { |
|
| 275 | 275 | continue; |
| 276 | 276 | } |
| 277 | - if($result !== null) { |
|
| 277 | + if ($result !== null) { |
|
| 278 | 278 | $resultData[] = $result; |
| 279 | 279 | } else { |
| 280 | 280 | $resultData[] = $row; |
@@ -299,18 +299,18 @@ discard block |
||
| 299 | 299 | $statement = $this->createStatement(); |
| 300 | 300 | $statement->setFetchMode($mode, $arg0); |
| 301 | 301 | try { |
| 302 | - while($row = $statement->fetch()) { |
|
| 302 | + while ($row = $statement->fetch()) { |
|
| 303 | 303 | /** @var T $row */ |
| 304 | 304 | // if($this->preserveTypes) { |
| 305 | 305 | // $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
| 306 | 306 | // $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
| 307 | 307 | // } |
| 308 | 308 | $result = $callback($row); |
| 309 | - if($result instanceof DBIgnoreRow) { |
|
| 309 | + if ($result instanceof DBIgnoreRow) { |
|
| 310 | 310 | // Skip row in this case |
| 311 | 311 | continue; |
| 312 | 312 | } |
| 313 | - if($result !== null) { |
|
| 313 | + if ($result !== null) { |
|
| 314 | 314 | yield $result; |
| 315 | 315 | } else { |
| 316 | 316 | yield $row; |
@@ -331,20 +331,20 @@ discard block |
||
| 331 | 331 | * @return T|U|array<string, mixed> |
| 332 | 332 | */ |
| 333 | 333 | private function fetch($callback, int $mode = PDO::FETCH_ASSOC, $arg0 = null, ?Closure $resultValidator = null) { |
| 334 | - return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) { |
|
| 334 | + return $this->createTempStatement(function(QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) { |
|
| 335 | 335 | $statement->setFetchMode($mode, $arg0); |
| 336 | 336 | $row = $statement->fetch(); |
| 337 | 337 | $result = $resultValidator === null ? ['valid' => true] : $resultValidator($row); |
| 338 | - if(!$result['valid']) { |
|
| 338 | + if (!$result['valid']) { |
|
| 339 | 339 | return $result['default']; |
| 340 | 340 | } |
| 341 | - if($this->preserveTypes) { |
|
| 341 | + if ($this->preserveTypes) { |
|
| 342 | 342 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
| 343 | 343 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
| 344 | 344 | } |
| 345 | - if($callback !== null) { |
|
| 345 | + if ($callback !== null) { |
|
| 346 | 346 | $result = $callback($row); |
| 347 | - if($result !== null) { |
|
| 347 | + if ($result !== null) { |
|
| 348 | 348 | $row = $result; |
| 349 | 349 | } |
| 350 | 350 | } |
@@ -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; |