@@ -73,7 +73,7 @@ |
||
| 73 | 73 | { |
| 74 | 74 | return preg_replace_callback( |
| 75 | 75 | '/({{(%?[\w\-. ]+%?)}}|\\[\\[([\w\-. ]+)]])/', |
| 76 | - function ($matches) { |
|
| 76 | + function($matches) { |
|
| 77 | 77 | if (isset($matches[3])) { |
| 78 | 78 | return $this->quoteColumnName($matches[3]); |
| 79 | 79 | } |
@@ -203,8 +203,8 @@ |
||
| 203 | 203 | public function dropCommentFromTable(string $table): string |
| 204 | 204 | { |
| 205 | 205 | return 'COMMENT ON TABLE ' |
| 206 | - . $this->queryBuilder->quoter()->quoteTableName($table) |
|
| 207 | - . ' IS NULL'; |
|
| 206 | + . $this->queryBuilder->quoter()->quoteTableName($table) |
|
| 207 | + . ' IS NULL'; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | public function dropDefaultValue(string $name, string $table): string |
@@ -854,7 +854,7 @@ discard block |
||
| 854 | 854 | */ |
| 855 | 855 | protected function hasOffset(mixed $offset): bool |
| 856 | 856 | { |
| 857 | - return ($offset instanceof ExpressionInterface) || (ctype_digit((string)$offset) && (string)$offset !== '0'); |
|
| 857 | + return ($offset instanceof ExpressionInterface) || (ctype_digit((string) $offset) && (string) $offset !== '0'); |
|
| 858 | 858 | } |
| 859 | 859 | |
| 860 | 860 | /** |
@@ -1046,7 +1046,7 @@ discard block |
||
| 1046 | 1046 | /** Remove duplicates */ |
| 1047 | 1047 | $constraints = array_combine( |
| 1048 | 1048 | array_map( |
| 1049 | - static function ($constraint) { |
|
| 1049 | + static function($constraint) { |
|
| 1050 | 1050 | $columns = $constraint->getColumnNames(); |
| 1051 | 1051 | sort($columns, SORT_STRING); |
| 1052 | 1052 | |
@@ -1064,7 +1064,7 @@ discard block |
||
| 1064 | 1064 | $constraints = array_values( |
| 1065 | 1065 | array_filter( |
| 1066 | 1066 | $constraints, |
| 1067 | - static function ($constraint) use ($quoter, $columns, &$columnNames) { |
|
| 1067 | + static function($constraint) use ($quoter, $columns, &$columnNames) { |
|
| 1068 | 1068 | /** @psalm-suppress UndefinedClass, UndefinedMethod */ |
| 1069 | 1069 | $constraintColumnNames = array_map([$quoter, 'quoteColumnName'], $constraint->getColumnNames()); |
| 1070 | 1070 | $result = !array_diff($constraintColumnNames, $columns); |
@@ -42,7 +42,7 @@ |
||
| 42 | 42 | ): mixed { |
| 43 | 43 | return $this->cache->getOrSet( |
| 44 | 44 | $key, |
| 45 | - static fn () => $value, |
|
| 45 | + static fn() => $value, |
|
| 46 | 46 | $ttl, |
| 47 | 47 | $dependency, |
| 48 | 48 | ); |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | public function batchInsert(string $table, array $columns, iterable $rows): self |
| 218 | 218 | { |
| 219 | 219 | $table = $this->queryBuilder()->quoter()->quoteSql($table); |
| 220 | - $columns = array_map(fn ($column) => $this->queryBuilder()->quoter()->quoteSql($column), $columns); |
|
| 220 | + $columns = array_map(fn($column) => $this->queryBuilder()->quoter()->quoteSql($column), $columns); |
|
| 221 | 221 | $params = []; |
| 222 | 222 | $sql = $this->queryBuilder()->batchInsert($table, $columns, $rows, $params); |
| 223 | 223 | |
@@ -432,18 +432,18 @@ discard block |
||
| 432 | 432 | $this->prepare(false); |
| 433 | 433 | |
| 434 | 434 | try { |
| 435 | - $this->profiler?->begin((string)$rawSql, [__METHOD__]); |
|
| 435 | + $this->profiler ? ->begin((string) $rawSql, [__METHOD__]); |
|
| 436 | 436 | |
| 437 | 437 | $this->internalExecute($rawSql); |
| 438 | 438 | $n = $this->pdoStatement->rowCount(); |
| 439 | 439 | |
| 440 | - $this->profiler?->end((string)$rawSql, [__METHOD__]); |
|
| 440 | + $this->profiler ? ->end((string) $rawSql, [__METHOD__]); |
|
| 441 | 441 | |
| 442 | 442 | $this->refreshTableSchema(); |
| 443 | 443 | |
| 444 | 444 | return $n; |
| 445 | 445 | } catch (Exception $e) { |
| 446 | - $this->profiler?->end((string)$rawSql, [__METHOD__]); |
|
| 446 | + $this->profiler ? ->end((string) $rawSql, [__METHOD__]); |
|
| 447 | 447 | throw $e; |
| 448 | 448 | } |
| 449 | 449 | } |
@@ -708,11 +708,11 @@ discard block |
||
| 708 | 708 | $cacheKey = $this->getCacheKey($method, $fetchMode, $rawSql); |
| 709 | 709 | $result = $cache->getOrSet( |
| 710 | 710 | $cacheKey, |
| 711 | - static fn () => null, |
|
| 711 | + static fn() => null, |
|
| 712 | 712 | ); |
| 713 | 713 | |
| 714 | 714 | if (is_array($result) && isset($result[0])) { |
| 715 | - $this->logger?->log(LogLevel::DEBUG, 'Query result served from cache', [__CLASS__ . '::query']); |
|
| 715 | + $this->logger ? ->log(LogLevel::DEBUG, 'Query result served from cache', [__CLASS__ . '::query']); |
|
| 716 | 716 | |
| 717 | 717 | return $result[0]; |
| 718 | 718 | } |
@@ -722,7 +722,7 @@ discard block |
||
| 722 | 722 | $this->prepare(true); |
| 723 | 723 | |
| 724 | 724 | try { |
| 725 | - $this->profiler?->begin((string)$rawSql, [__CLASS__ . '::query']); |
|
| 725 | + $this->profiler ? ->begin((string) $rawSql, [__CLASS__ . '::query']); |
|
| 726 | 726 | |
| 727 | 727 | $this->internalExecute($rawSql); |
| 728 | 728 | |
@@ -738,21 +738,21 @@ discard block |
||
| 738 | 738 | $this->pdoStatement->closeCursor(); |
| 739 | 739 | } |
| 740 | 740 | |
| 741 | - $this->profiler?->end((string)$rawSql, [__CLASS__ . '::query']); |
|
| 741 | + $this->profiler ? ->end((string) $rawSql, [__CLASS__ . '::query']); |
|
| 742 | 742 | } catch (Exception $e) { |
| 743 | - $this->profiler?->end((string)$rawSql, [__CLASS__ . '::query']); |
|
| 743 | + $this->profiler ? ->end((string) $rawSql, [__CLASS__ . '::query']); |
|
| 744 | 744 | throw $e; |
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | if (isset($cache, $cacheKey, $info)) { |
| 748 | 748 | $cache->getOrSet( |
| 749 | 749 | $cacheKey, |
| 750 | - static fn (): array => [$result], |
|
| 750 | + static fn(): array => [$result], |
|
| 751 | 751 | $info[1], |
| 752 | 752 | $info[2] |
| 753 | 753 | ); |
| 754 | 754 | |
| 755 | - $this->logger?->log(LogLevel::DEBUG, 'Saved query result in cache', [__CLASS__ . '::query']); |
|
| 755 | + $this->logger ? ->log(LogLevel::DEBUG, 'Saved query result in cache', [__CLASS__ . '::query']); |
|
| 756 | 756 | } |
| 757 | 757 | |
| 758 | 758 | return $result; |
@@ -262,7 +262,7 @@ |
||
| 262 | 262 | |
| 263 | 263 | return $poolConnection; |
| 264 | 264 | } catch (Exception $e) { |
| 265 | - $this->logger?->log( |
|
| 265 | + $this->logger ? ->log( |
|
| 266 | 266 | LogLevel::WARNING, |
| 267 | 267 | "Connection ({$poolConnection->getDriver()->getDsn()}) failed: " . $e->getMessage() . ' ' . __METHOD__ |
| 268 | 268 | ); |
@@ -32,14 +32,14 @@ discard block |
||
| 32 | 32 | return [ |
| 33 | 33 | 'drop' => [ |
| 34 | 34 | "ALTER TABLE {{{$tableName}}} DROP CONSTRAINT [[$name]]", |
| 35 | - static function (QueryBuilderInterface $qb) use ($tableName, $name) { |
|
| 35 | + static function(QueryBuilderInterface $qb) use ($tableName, $name) { |
|
| 36 | 36 | return $qb->dropForeignKey($name, $tableName); |
| 37 | 37 | }, |
| 38 | 38 | ], |
| 39 | 39 | 'add' => [ |
| 40 | 40 | "ALTER TABLE {{{$tableName}}} ADD CONSTRAINT [[$name]] FOREIGN KEY ([[C_fk_id_1]])" |
| 41 | 41 | . " REFERENCES {{{$pkTableName}}} ([[C_id_1]]) ON DELETE CASCADE ON UPDATE CASCADE", |
| 42 | - static function (QueryBuilderInterface $qb) use ($tableName, $name, $pkTableName) { |
|
| 42 | + static function(QueryBuilderInterface $qb) use ($tableName, $name, $pkTableName) { |
|
| 43 | 43 | return $qb->addForeignKey( |
| 44 | 44 | $name, |
| 45 | 45 | $tableName, |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | 'add (2 columns)' => [ |
| 55 | 55 | "ALTER TABLE {{{$tableName}}} ADD CONSTRAINT [[$name]] FOREIGN KEY ([[C_fk_id_1]], [[C_fk_id_2]])" |
| 56 | 56 | . " REFERENCES {{{$pkTableName}}} ([[C_id_1]], [[C_id_2]]) ON DELETE CASCADE ON UPDATE CASCADE", |
| 57 | - static function (QueryBuilderInterface $qb) use ($tableName, $name, $pkTableName) { |
|
| 57 | + static function(QueryBuilderInterface $qb) use ($tableName, $name, $pkTableName) { |
|
| 58 | 58 | return $qb->addForeignKey( |
| 59 | 59 | $name, |
| 60 | 60 | $tableName, |
@@ -77,19 +77,19 @@ discard block |
||
| 77 | 77 | return [ |
| 78 | 78 | 'drop' => [ |
| 79 | 79 | "ALTER TABLE {{{$tableName}}} DROP CONSTRAINT [[$name]]", |
| 80 | - static function (QueryBuilderInterface $qb) use ($tableName, $name) { |
|
| 80 | + static function(QueryBuilderInterface $qb) use ($tableName, $name) { |
|
| 81 | 81 | return $qb->dropPrimaryKey($name, $tableName); |
| 82 | 82 | }, |
| 83 | 83 | ], |
| 84 | 84 | 'add' => [ |
| 85 | 85 | "ALTER TABLE {{{$tableName}}} ADD CONSTRAINT [[$name]] PRIMARY KEY ([[C_id_1]])", |
| 86 | - static function (QueryBuilderInterface $qb) use ($tableName, $name) { |
|
| 86 | + static function(QueryBuilderInterface $qb) use ($tableName, $name) { |
|
| 87 | 87 | return $qb->addPrimaryKey($name, $tableName, 'C_id_1'); |
| 88 | 88 | }, |
| 89 | 89 | ], |
| 90 | 90 | 'add (2 columns)' => [ |
| 91 | 91 | "ALTER TABLE {{{$tableName}}} ADD CONSTRAINT [[$name]] PRIMARY KEY ([[C_id_1]], [[C_id_2]])", |
| 92 | - static function (QueryBuilderInterface $qb) use ($tableName, $name) { |
|
| 92 | + static function(QueryBuilderInterface $qb) use ($tableName, $name) { |
|
| 93 | 93 | return $qb->addPrimaryKey($name, $tableName, 'C_id_1, C_id_2'); |
| 94 | 94 | }, |
| 95 | 95 | ], |
@@ -106,19 +106,19 @@ discard block |
||
| 106 | 106 | return [ |
| 107 | 107 | 'drop' => [ |
| 108 | 108 | "ALTER TABLE {{{$tableName1}}} DROP CONSTRAINT [[$name1]]", |
| 109 | - static function (QueryBuilderInterface $qb) use ($tableName1, $name1) { |
|
| 109 | + static function(QueryBuilderInterface $qb) use ($tableName1, $name1) { |
|
| 110 | 110 | return $qb->dropUnique($name1, $tableName1); |
| 111 | 111 | }, |
| 112 | 112 | ], |
| 113 | 113 | 'add' => [ |
| 114 | 114 | "ALTER TABLE {{{$tableName1}}} ADD CONSTRAINT [[$name1]] UNIQUE ([[C_unique]])", |
| 115 | - static function (QueryBuilderInterface $qb) use ($tableName1, $name1) { |
|
| 115 | + static function(QueryBuilderInterface $qb) use ($tableName1, $name1) { |
|
| 116 | 116 | return $qb->addUnique($name1, $tableName1, 'C_unique'); |
| 117 | 117 | }, |
| 118 | 118 | ], |
| 119 | 119 | 'add (2 columns)' => [ |
| 120 | 120 | "ALTER TABLE {{{$tableName2}}} ADD CONSTRAINT [[$name2]] UNIQUE ([[C_index_2_1]], [[C_index_2_2]])", |
| 121 | - static function (QueryBuilderInterface $qb) use ($tableName2, $name2) { |
|
| 121 | + static function(QueryBuilderInterface $qb) use ($tableName2, $name2) { |
|
| 122 | 122 | return $qb->addUnique($name2, $tableName2, 'C_index_2_1, C_index_2_2'); |
| 123 | 123 | }, |
| 124 | 124 | ], |
@@ -494,7 +494,7 @@ discard block |
||
| 494 | 494 | [new Expression('NOT (any_expression(:a))', [':a' => 1]), 'NOT (any_expression(:a))', [':a' => 1]], |
| 495 | 495 | ]; |
| 496 | 496 | |
| 497 | - $conditions = match ($this->db->getDriverName()) { |
|
| 497 | + $conditions = match($this->db->getDriverName()) { |
|
| 498 | 498 | 'sqlsrv', 'sqlite' => array_merge($conditions, [ |
| 499 | 499 | [ |
| 500 | 500 | ['in', ['id', 'name'], [['id' => 1, 'name' => 'foo'], ['id' => 2, 'name' => 'bar']]], |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | [':qp0' => 1, |
| 503 | 503 | ':qp1' => 'foo', |
| 504 | 504 | ':qp2' => 2, |
| 505 | - ':qp3' => 'bar',], |
|
| 505 | + ':qp3' => 'bar', ], |
|
| 506 | 506 | ], |
| 507 | 507 | [ |
| 508 | 508 | ['not in', ['id', 'name'], [['id' => 1, 'name' => 'foo'], ['id' => 2, 'name' => 'bar']]], |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | [':qp0' => 1, |
| 511 | 511 | ':qp1' => 'foo', |
| 512 | 512 | ':qp2' => 2, |
| 513 | - ':qp3' => 'bar',], |
|
| 513 | + ':qp3' => 'bar', ], |
|
| 514 | 514 | ], |
| 515 | 515 | //[['in', ['id', 'name'], (new Query())->select(['id', 'name'])->from('users')->where(['active' => 1])], 'EXISTS (SELECT 1 FROM (SELECT [[id]], [[name]] FROM [[users]] WHERE [[active]]=:qp0) AS a WHERE a.[[id]] = [[id AND a.]]name[[ = ]]name`)', [':qp0' => 1] ], |
| 516 | 516 | //[ ['not in', ['id', 'name'], (new Query())->select(['id', 'name'])->from('users')->where(['active' => 1])], 'NOT EXISTS (SELECT 1 FROM (SELECT [[id]], [[name]] FROM [[users]] WHERE [[active]]=:qp0) AS a WHERE a.[[id]] = [[id]] AND a.[[name = ]]name`)', [':qp0' => 1] ], |
@@ -797,31 +797,31 @@ discard block |
||
| 797 | 797 | return [ |
| 798 | 798 | 'drop' => [ |
| 799 | 799 | "DROP INDEX [[$name1]] ON {{{$tableName}}}", |
| 800 | - static function (QueryBuilderInterface $qb) use ($tableName, $name1) { |
|
| 800 | + static function(QueryBuilderInterface $qb) use ($tableName, $name1) { |
|
| 801 | 801 | return $qb->dropIndex($name1, $tableName); |
| 802 | 802 | }, |
| 803 | 803 | ], |
| 804 | 804 | 'create' => [ |
| 805 | 805 | "CREATE INDEX [[$name1]] ON {{{$tableName}}} ([[C_index_1]])", |
| 806 | - static function (QueryBuilderInterface $qb) use ($tableName, $name1) { |
|
| 806 | + static function(QueryBuilderInterface $qb) use ($tableName, $name1) { |
|
| 807 | 807 | return $qb->createIndex($name1, $tableName, 'C_index_1'); |
| 808 | 808 | }, |
| 809 | 809 | ], |
| 810 | 810 | 'create (2 columns)' => [ |
| 811 | 811 | "CREATE INDEX [[$name2]] ON {{{$tableName}}} ([[C_index_2_1]], [[C_index_2_2]])", |
| 812 | - static function (QueryBuilderInterface $qb) use ($tableName, $name2) { |
|
| 812 | + static function(QueryBuilderInterface $qb) use ($tableName, $name2) { |
|
| 813 | 813 | return $qb->createIndex($name2, $tableName, 'C_index_2_1, C_index_2_2'); |
| 814 | 814 | }, |
| 815 | 815 | ], |
| 816 | 816 | 'create unique' => [ |
| 817 | 817 | "CREATE UNIQUE INDEX [[$name1]] ON {{{$tableName}}} ([[C_index_1]])", |
| 818 | - static function (QueryBuilderInterface $qb) use ($tableName, $name1) { |
|
| 818 | + static function(QueryBuilderInterface $qb) use ($tableName, $name1) { |
|
| 819 | 819 | return $qb->createIndex($name1, $tableName, 'C_index_1', true); |
| 820 | 820 | }, |
| 821 | 821 | ], |
| 822 | 822 | 'create unique (2 columns)' => [ |
| 823 | 823 | "CREATE UNIQUE INDEX [[$name2]] ON {{{$tableName}}} ([[C_index_2_1]], [[C_index_2_2]])", |
| 824 | - static function (QueryBuilderInterface $qb) use ($tableName, $name2) { |
|
| 824 | + static function(QueryBuilderInterface $qb) use ($tableName, $name2) { |
|
| 825 | 825 | return $qb->createIndex($name2, $tableName, 'C_index_2_1, C_index_2_2', true); |
| 826 | 826 | }, |
| 827 | 827 | ], |
@@ -1136,20 +1136,20 @@ |
||
| 1136 | 1136 | $secondQuery = new Query($db); |
| 1137 | 1137 | |
| 1138 | 1138 | $secondQuery->select('id') |
| 1139 | - ->from('TotalTotalExample t2') |
|
| 1140 | - ->where('w > 5'); |
|
| 1139 | + ->from('TotalTotalExample t2') |
|
| 1140 | + ->where('w > 5'); |
|
| 1141 | 1141 | |
| 1142 | 1142 | $thirdQuery = new Query($db); |
| 1143 | 1143 | |
| 1144 | 1144 | $thirdQuery->select('id') |
| 1145 | - ->from('TotalTotalExample t3') |
|
| 1146 | - ->where('w = 3'); |
|
| 1145 | + ->from('TotalTotalExample t3') |
|
| 1146 | + ->where('w = 3'); |
|
| 1147 | 1147 | |
| 1148 | 1148 | $query->select('id') |
| 1149 | - ->from('TotalExample t1') |
|
| 1150 | - ->where(['and', 'w > 0', 'x < 2']) |
|
| 1151 | - ->union($secondQuery) |
|
| 1152 | - ->union($thirdQuery, true); |
|
| 1149 | + ->from('TotalExample t1') |
|
| 1150 | + ->where(['and', 'w > 0', 'x < 2']) |
|
| 1151 | + ->union($secondQuery) |
|
| 1152 | + ->union($thirdQuery, true); |
|
| 1153 | 1153 | |
| 1154 | 1154 | [$actualQuerySql, $queryParams] = $db->getQueryBuilder()->build($query); |
| 1155 | 1155 | |
@@ -185,7 +185,7 @@ |
||
| 185 | 185 | */ |
| 186 | 186 | protected function replaceQuotes($sql): string|array|null |
| 187 | 187 | { |
| 188 | - return match ($this->drivername) { |
|
| 188 | + return match($this->drivername) { |
|
| 189 | 189 | 'mysql', 'sqlite' => str_replace(['[[', ']]'], '`', $sql), |
| 190 | 190 | 'oci' => str_replace(['[[', ']]'], '"', $sql), |
| 191 | 191 | 'pgsql' => str_replace(['\\[', '\\]'], ['[', ']'], preg_replace('/(\[\[)|((?<!(\[))]])/', '"', $sql)), |