@@ -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 | } |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | $result = (new Query($db))->from('customer') |
| 551 | 551 | ->select(['name', 'id']) |
| 552 | 552 | ->orderBy(['id' => SORT_DESC]) |
| 553 | - ->indexBy(function ($row) { |
|
| 553 | + ->indexBy(function($row) { |
|
| 554 | 554 | return $row['id'] * 2; |
| 555 | 555 | }) |
| 556 | 556 | ->column(); |
@@ -814,7 +814,7 @@ discard block |
||
| 814 | 814 | ); |
| 815 | 815 | |
| 816 | 816 | /* Connection cache */ |
| 817 | - $db->cache(function (ConnectionInterface $db) use ($query, $update) { |
|
| 817 | + $db->cache(function(ConnectionInterface $db) use ($query, $update) { |
|
| 818 | 818 | $this->assertEquals( |
| 819 | 819 | 'user2', |
| 820 | 820 | $query->where(['id' => 2])->scalar(), |
@@ -829,7 +829,7 @@ discard block |
||
| 829 | 829 | 'Query does NOT reflect DB changes when wrapped in connection caching' |
| 830 | 830 | ); |
| 831 | 831 | |
| 832 | - $db->noCache(function () use ($query) { |
|
| 832 | + $db->noCache(function() use ($query) { |
|
| 833 | 833 | $this->assertEquals( |
| 834 | 834 | 'user22', |
| 835 | 835 | $query->where(['id' => 2])->scalar(), |
@@ -846,7 +846,7 @@ discard block |
||
| 846 | 846 | |
| 847 | 847 | $this->queryCache->setEnable(false); |
| 848 | 848 | |
| 849 | - $db->cache(function () use ($query, $update) { |
|
| 849 | + $db->cache(function() use ($query, $update) { |
|
| 850 | 850 | $this->assertEquals( |
| 851 | 851 | 'user22', |
| 852 | 852 | $query->where(['id' => 2])->scalar(), |
@@ -877,7 +877,7 @@ discard block |
||
| 877 | 877 | 'When Query has disabled cache, we get actual data' |
| 878 | 878 | ); |
| 879 | 879 | |
| 880 | - $db->cache(function () use ($query) { |
|
| 880 | + $db->cache(function() use ($query) { |
|
| 881 | 881 | $this->assertEquals('user1', $query->noCache()->where(['id' => 1])->scalar()); |
| 882 | 882 | $this->assertEquals('user11', $query->cache()->where(['id' => 1])->scalar()); |
| 883 | 883 | }, 10); |
@@ -310,8 +310,8 @@ |
||
| 310 | 310 | $string = ' DEFAULT '; |
| 311 | 311 | |
| 312 | 312 | $string .= match (gettype($this->default)) { |
| 313 | - 'object', 'integer' => (string)$this->default, |
|
| 314 | - 'double' => NumericHelper::normalize((string)$this->default), |
|
| 313 | + 'object', 'integer' => (string) $this->default, |
|
| 314 | + 'double' => NumericHelper::normalize((string) $this->default), |
|
| 315 | 315 | 'boolean' => $this->default ? 'TRUE' : 'FALSE', |
| 316 | 316 | default => "'{$this->default}'", |
| 317 | 317 | }; |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | /** Remove duplicates */ |
| 350 | 350 | $constraints = array_combine( |
| 351 | 351 | array_map( |
| 352 | - static function (Constraint $constraint) { |
|
| 352 | + static function(Constraint $constraint) { |
|
| 353 | 353 | $columns = $constraint->getColumnNames() ?? []; |
| 354 | 354 | $columns = is_array($columns) ? $columns : [$columns]; |
| 355 | 355 | sort($columns, SORT_STRING); |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | $constraints = array_values( |
| 368 | 368 | array_filter( |
| 369 | 369 | $constraints, |
| 370 | - static function (Constraint $constraint) use ($quoter, $columns, &$columnNames) { |
|
| 370 | + static function(Constraint $constraint) use ($quoter, $columns, &$columnNames) { |
|
| 371 | 371 | /** @psalm-var string[]|string */ |
| 372 | 372 | $getColumnNames = $constraint->getColumnNames() ?? []; |
| 373 | 373 | $constraintColumnNames = []; |
@@ -585,7 +585,7 @@ |
||
| 585 | 585 | */ |
| 586 | 586 | protected function hasOffset(mixed $offset): bool |
| 587 | 587 | { |
| 588 | - return ($offset instanceof ExpressionInterface) || (ctype_digit((string)$offset) && (string)$offset !== '0'); |
|
| 588 | + return ($offset instanceof ExpressionInterface) || (ctype_digit((string) $offset) && (string) $offset !== '0'); |
|
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | /** |
@@ -142,7 +142,7 @@ |
||
| 142 | 142 | |
| 143 | 143 | protected function getCacheKey(int $queryMode, string $rawSql): array |
| 144 | 144 | { |
| 145 | - return array_merge([static::class , $queryMode], $this->db->getCacheKey(), [$rawSql]); |
|
| 145 | + return array_merge([static::class, $queryMode], $this->db->getCacheKey(), [$rawSql]); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | |
| 203 | 203 | $this->expectException(Exception::class); |
| 204 | 204 | |
| 205 | - $db->transaction(function () use ($db) { |
|
| 205 | + $db->transaction(function() use ($db) { |
|
| 206 | 206 | $db->createCommand()->insert('profile', ['description' => 'test transaction shortcut'])->execute(); |
| 207 | 207 | throw new Exception('Exception in transaction shortcut'); |
| 208 | 208 | }); |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | { |
| 217 | 217 | $db = $this->getConnection(true); |
| 218 | 218 | |
| 219 | - $result = $db->transaction(static function () use ($db) { |
|
| 219 | + $result = $db->transaction(static function() use ($db) { |
|
| 220 | 220 | $db->createCommand()->insert('profile', ['description' => 'test transaction shortcut'])->execute(); |
| 221 | 221 | return true; |
| 222 | 222 | }); |
@@ -239,10 +239,10 @@ discard block |
||
| 239 | 239 | { |
| 240 | 240 | $db = $this->getConnection(); |
| 241 | 241 | |
| 242 | - $db->transaction(function (ConnectionInterface $db) { |
|
| 242 | + $db->transaction(function(ConnectionInterface $db) { |
|
| 243 | 243 | $this->assertNotNull($db->getTransaction()); |
| 244 | 244 | |
| 245 | - $db->transaction(function (ConnectionInterface $db) { |
|
| 245 | + $db->transaction(function(ConnectionInterface $db) { |
|
| 246 | 246 | $transaction = $db->getTransaction(); |
| 247 | 247 | $this->assertNotNull($transaction); |
| 248 | 248 | $transaction->rollBack(); |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | |
| 259 | 259 | $db->setEnableSavepoint(false); |
| 260 | 260 | |
| 261 | - $db->transaction(function (ConnectionInterface $db) { |
|
| 261 | + $db->transaction(function(ConnectionInterface $db) { |
|
| 262 | 262 | $this->assertNotNull($db->getTransaction()); |
| 263 | 263 | $this->expectException(NotSupportedException::class); |
| 264 | 264 | $db->beginTransaction(); |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | $row = $rows[2]; |
| 218 | 218 | $this->assertEquals(3, $row['id']); |
| 219 | 219 | $this->assertEquals('user3', $row['name']); |
| 220 | - $this->assertTrue(is_array($rows) && count($rows)>1 && count($rows[0]) === 2); |
|
| 220 | + $this->assertTrue(is_array($rows) && count($rows) > 1 && count($rows[0]) === 2); |
|
| 221 | 221 | |
| 222 | 222 | $rows = $db->createCommand('SELECT * FROM {{customer}} WHERE [[id]] = 10')->queryAll(); |
| 223 | 223 | $this->assertEquals([], $rows); |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | */ |
| 259 | 259 | public function testBatchInsertWithYield(): void |
| 260 | 260 | { |
| 261 | - $rows = (static function () { |
|
| 261 | + $rows = (static function() { |
|
| 262 | 262 | foreach ([['[email protected]', 'test name', 'test address']] as $row) { |
| 263 | 263 | yield $row; |
| 264 | 264 | } |
@@ -882,14 +882,14 @@ discard block |
||
| 882 | 882 | $update->bindValues([':id' => 1, ':name' => 'user11'])->execute(); |
| 883 | 883 | $this->assertEquals('user11', $command->bindValue(':id', 1)->queryScalar()); |
| 884 | 884 | |
| 885 | - $db->cache(function (ConnectionInterface $db) use ($command, $update) { |
|
| 885 | + $db->cache(function(ConnectionInterface $db) use ($command, $update) { |
|
| 886 | 886 | $this->assertEquals('user2', $command->bindValue(':id', 2)->queryScalar()); |
| 887 | 887 | |
| 888 | 888 | $update->bindValues([':id' => 2, ':name' => 'user22'])->execute(); |
| 889 | 889 | |
| 890 | 890 | $this->assertEquals('user2', $command->bindValue(':id', 2)->queryScalar()); |
| 891 | 891 | |
| 892 | - $db->noCache(function () use ($command) { |
|
| 892 | + $db->noCache(function() use ($command) { |
|
| 893 | 893 | $this->assertEquals('user22', $command->bindValue(':id', 2)->queryScalar()); |
| 894 | 894 | }); |
| 895 | 895 | |
@@ -899,7 +899,7 @@ discard block |
||
| 899 | 899 | /** @psalm-suppress PossiblyNullReference */ |
| 900 | 900 | $this->queryCache->setEnable(false); |
| 901 | 901 | |
| 902 | - $db->cache(function () use ($command, $update) { |
|
| 902 | + $db->cache(function() use ($command, $update) { |
|
| 903 | 903 | $this->assertEquals('user22', $command->bindValue(':id', 2)->queryScalar()); |
| 904 | 904 | $update->bindValues([':id' => 2, ':name' => 'user2'])->execute(); |
| 905 | 905 | $this->assertEquals('user2', $command->bindValue(':id', 2)->queryScalar()); |
@@ -916,7 +916,7 @@ discard block |
||
| 916 | 916 | |
| 917 | 917 | $command = $db->createCommand('SELECT [[name]] FROM {{customer}} WHERE [[id]] = :id'); |
| 918 | 918 | |
| 919 | - $db->cache(function () use ($command) { |
|
| 919 | + $db->cache(function() use ($command) { |
|
| 920 | 920 | $this->assertEquals('user11', $command->bindValue(':id', 1)->queryScalar()); |
| 921 | 921 | $this->assertEquals('user1', $command->noCache()->bindValue(':id', 1)->queryScalar()); |
| 922 | 922 | }, 10); |
@@ -990,7 +990,7 @@ discard block |
||
| 990 | 990 | $this->invokeMethod( |
| 991 | 991 | $command, |
| 992 | 992 | 'setRetryHandler', |
| 993 | - [static function ($exception, $attempt) use (&$attempts, &$hitHandler) { |
|
| 993 | + [static function($exception, $attempt) use (&$attempts, &$hitHandler) { |
|
| 994 | 994 | $attempts = $attempt; |
| 995 | 995 | $hitHandler = true; |
| 996 | 996 | |
@@ -33,14 +33,14 @@ discard block |
||
| 33 | 33 | return [ |
| 34 | 34 | 'drop' => [ |
| 35 | 35 | "ALTER TABLE {{{$tableName}}} DROP CONSTRAINT [[$name]]", |
| 36 | - static function (QueryBuilderInterface $qb) use ($tableName, $name) { |
|
| 36 | + static function(QueryBuilderInterface $qb) use ($tableName, $name) { |
|
| 37 | 37 | return $qb->dropForeignKey($name, $tableName); |
| 38 | 38 | }, |
| 39 | 39 | ], |
| 40 | 40 | 'add' => [ |
| 41 | 41 | "ALTER TABLE {{{$tableName}}} ADD CONSTRAINT [[$name]] FOREIGN KEY ([[C_fk_id_1]])" |
| 42 | 42 | . " REFERENCES {{{$pkTableName}}} ([[C_id_1]]) ON DELETE CASCADE ON UPDATE CASCADE", |
| 43 | - static function (QueryBuilderInterface $qb) use ($tableName, $name, $pkTableName) { |
|
| 43 | + static function(QueryBuilderInterface $qb) use ($tableName, $name, $pkTableName) { |
|
| 44 | 44 | return $qb->addForeignKey( |
| 45 | 45 | $name, |
| 46 | 46 | $tableName, |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | 'add (2 columns)' => [ |
| 56 | 56 | "ALTER TABLE {{{$tableName}}} ADD CONSTRAINT [[$name]] FOREIGN KEY ([[C_fk_id_1]], [[C_fk_id_2]])" |
| 57 | 57 | . " REFERENCES {{{$pkTableName}}} ([[C_id_1]], [[C_id_2]]) ON DELETE CASCADE ON UPDATE CASCADE", |
| 58 | - static function (QueryBuilderInterface $qb) use ($tableName, $name, $pkTableName) { |
|
| 58 | + static function(QueryBuilderInterface $qb) use ($tableName, $name, $pkTableName) { |
|
| 59 | 59 | return $qb->addForeignKey( |
| 60 | 60 | $name, |
| 61 | 61 | $tableName, |
@@ -78,19 +78,19 @@ discard block |
||
| 78 | 78 | return [ |
| 79 | 79 | 'drop' => [ |
| 80 | 80 | "ALTER TABLE {{{$tableName}}} DROP CONSTRAINT [[$name]]", |
| 81 | - static function (QueryBuilderInterface $qb) use ($tableName, $name) { |
|
| 81 | + static function(QueryBuilderInterface $qb) use ($tableName, $name) { |
|
| 82 | 82 | return $qb->dropPrimaryKey($name, $tableName); |
| 83 | 83 | }, |
| 84 | 84 | ], |
| 85 | 85 | 'add' => [ |
| 86 | 86 | "ALTER TABLE {{{$tableName}}} ADD CONSTRAINT [[$name]] PRIMARY KEY ([[C_id_1]])", |
| 87 | - static function (QueryBuilderInterface $qb) use ($tableName, $name) { |
|
| 87 | + static function(QueryBuilderInterface $qb) use ($tableName, $name) { |
|
| 88 | 88 | return $qb->addPrimaryKey($name, $tableName, 'C_id_1'); |
| 89 | 89 | }, |
| 90 | 90 | ], |
| 91 | 91 | 'add (2 columns)' => [ |
| 92 | 92 | "ALTER TABLE {{{$tableName}}} ADD CONSTRAINT [[$name]] PRIMARY KEY ([[C_id_1]], [[C_id_2]])", |
| 93 | - static function (QueryBuilderInterface $qb) use ($tableName, $name) { |
|
| 93 | + static function(QueryBuilderInterface $qb) use ($tableName, $name) { |
|
| 94 | 94 | return $qb->addPrimaryKey($name, $tableName, 'C_id_1, C_id_2'); |
| 95 | 95 | }, |
| 96 | 96 | ], |
@@ -107,19 +107,19 @@ discard block |
||
| 107 | 107 | return [ |
| 108 | 108 | 'drop' => [ |
| 109 | 109 | "ALTER TABLE {{{$tableName1}}} DROP CONSTRAINT [[$name1]]", |
| 110 | - static function (QueryBuilderInterface $qb) use ($tableName1, $name1) { |
|
| 110 | + static function(QueryBuilderInterface $qb) use ($tableName1, $name1) { |
|
| 111 | 111 | return $qb->dropUnique($name1, $tableName1); |
| 112 | 112 | }, |
| 113 | 113 | ], |
| 114 | 114 | 'add' => [ |
| 115 | 115 | "ALTER TABLE {{{$tableName1}}} ADD CONSTRAINT [[$name1]] UNIQUE ([[C_unique]])", |
| 116 | - static function (QueryBuilderInterface $qb) use ($tableName1, $name1) { |
|
| 116 | + static function(QueryBuilderInterface $qb) use ($tableName1, $name1) { |
|
| 117 | 117 | return $qb->addUnique($name1, $tableName1, 'C_unique'); |
| 118 | 118 | }, |
| 119 | 119 | ], |
| 120 | 120 | 'add (2 columns)' => [ |
| 121 | 121 | "ALTER TABLE {{{$tableName2}}} ADD CONSTRAINT [[$name2]] UNIQUE ([[C_index_2_1]], [[C_index_2_2]])", |
| 122 | - static function (QueryBuilderInterface $qb) use ($tableName2, $name2) { |
|
| 122 | + static function(QueryBuilderInterface $qb) use ($tableName2, $name2) { |
|
| 123 | 123 | return $qb->addUnique($name2, $tableName2, 'C_index_2_1, C_index_2_2'); |
| 124 | 124 | }, |
| 125 | 125 | ], |
@@ -503,7 +503,7 @@ discard block |
||
| 503 | 503 | [':qp0' => 1, |
| 504 | 504 | ':qp1' => 'foo', |
| 505 | 505 | ':qp2' => 2, |
| 506 | - ':qp3' => 'bar',], |
|
| 506 | + ':qp3' => 'bar', ], |
|
| 507 | 507 | ], |
| 508 | 508 | [ |
| 509 | 509 | ['not in', ['id', 'name'], [['id' => 1, 'name' => 'foo'], ['id' => 2, 'name' => 'bar']]], |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | [':qp0' => 1, |
| 512 | 512 | ':qp1' => 'foo', |
| 513 | 513 | ':qp2' => 2, |
| 514 | - ':qp3' => 'bar',], |
|
| 514 | + ':qp3' => 'bar', ], |
|
| 515 | 515 | ], |
| 516 | 516 | //[['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] ], |
| 517 | 517 | //[ ['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] ], |
@@ -798,31 +798,31 @@ discard block |
||
| 798 | 798 | return [ |
| 799 | 799 | 'drop' => [ |
| 800 | 800 | "DROP INDEX [[$name1]] ON {{{$tableName}}}", |
| 801 | - static function (QueryBuilderInterface $qb) use ($tableName, $name1) { |
|
| 801 | + static function(QueryBuilderInterface $qb) use ($tableName, $name1) { |
|
| 802 | 802 | return $qb->dropIndex($name1, $tableName); |
| 803 | 803 | }, |
| 804 | 804 | ], |
| 805 | 805 | 'create' => [ |
| 806 | 806 | "CREATE INDEX [[$name1]] ON {{{$tableName}}} ([[C_index_1]])", |
| 807 | - static function (QueryBuilderInterface $qb) use ($tableName, $name1) { |
|
| 807 | + static function(QueryBuilderInterface $qb) use ($tableName, $name1) { |
|
| 808 | 808 | return $qb->createIndex($name1, $tableName, 'C_index_1'); |
| 809 | 809 | }, |
| 810 | 810 | ], |
| 811 | 811 | 'create (2 columns)' => [ |
| 812 | 812 | "CREATE INDEX [[$name2]] ON {{{$tableName}}} ([[C_index_2_1]], [[C_index_2_2]])", |
| 813 | - static function (QueryBuilderInterface $qb) use ($tableName, $name2) { |
|
| 813 | + static function(QueryBuilderInterface $qb) use ($tableName, $name2) { |
|
| 814 | 814 | return $qb->createIndex($name2, $tableName, 'C_index_2_1, C_index_2_2'); |
| 815 | 815 | }, |
| 816 | 816 | ], |
| 817 | 817 | 'create unique' => [ |
| 818 | 818 | "CREATE UNIQUE INDEX [[$name1]] ON {{{$tableName}}} ([[C_index_1]])", |
| 819 | - static function (QueryBuilderInterface $qb) use ($tableName, $name1) { |
|
| 819 | + static function(QueryBuilderInterface $qb) use ($tableName, $name1) { |
|
| 820 | 820 | return $qb->createIndex($name1, $tableName, 'C_index_1', QueryBuilder::INDEX_UNIQUE); |
| 821 | 821 | }, |
| 822 | 822 | ], |
| 823 | 823 | 'create unique (2 columns)' => [ |
| 824 | 824 | "CREATE UNIQUE INDEX [[$name2]] ON {{{$tableName}}} ([[C_index_2_1]], [[C_index_2_2]])", |
| 825 | - static function (QueryBuilderInterface $qb) use ($tableName, $name2) { |
|
| 825 | + static function(QueryBuilderInterface $qb) use ($tableName, $name2) { |
|
| 826 | 826 | return $qb->createIndex($name2, $tableName, 'C_index_2_1, C_index_2_2', QueryBuilder::INDEX_UNIQUE); |
| 827 | 827 | }, |
| 828 | 828 | ], |