From 359a1140555e045ef4da5ed13d770d07c2342955 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 29 Jan 2024 11:46:05 +0700 Subject: [PATCH 1/4] Resolve deprecated methods --- src/Schema.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Schema.php b/src/Schema.php index 23d46723..466c8989 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -21,6 +21,7 @@ use Yiisoft\Db\Schema\TableSchemaInterface; use function array_column; +use function array_map; use function array_merge; use function count; use function explode; @@ -201,7 +202,7 @@ protected function loadTableForeignKeys(string $tableName): array $foreignKeysList = $this->getPragmaForeignKeyList($tableName); /** @psalm-var ForeignKeyInfo[] $foreignKeysList */ - $foreignKeysList = $this->normalizeRowKeyCase($foreignKeysList, true); + $foreignKeysList = array_map('array_change_key_case', $foreignKeysList); $foreignKeysList = DbArrayHelper::index($foreignKeysList, null, ['table']); DbArrayHelper::multisort($foreignKeysList, 'seq'); @@ -553,7 +554,7 @@ private function loadTableColumnsInfo(string $tableName): array { $tableColumns = $this->getPragmaTableInfo($tableName); /** @psalm-var ColumnInfo[] $tableColumns */ - $tableColumns = $this->normalizeRowKeyCase($tableColumns, true); + $tableColumns = array_map('array_change_key_case', $tableColumns); /** @psalm-var ColumnInfo[] */ return DbArrayHelper::index($tableColumns, 'cid'); @@ -575,7 +576,7 @@ private function loadTableConstraints(string $tableName, string $returnType): Co { $indexList = $this->getPragmaIndexList($tableName); /** @psalm-var IndexListInfo[] $indexes */ - $indexes = $this->normalizeRowKeyCase($indexList, true); + $indexes = array_map('array_change_key_case', $indexList); $result = [ self::PRIMARY_KEY => null, self::INDEXES => [], @@ -662,7 +663,7 @@ private function getPragmaIndexInfo(string $name): array $column = $this->db ->createCommand('PRAGMA INDEX_INFO(' . (string) $this->db->getQuoter()->quoteValue($name) . ')') ->queryAll(); - $column = $this->normalizeRowKeyCase($column, true); + $column = array_map('array_change_key_case', $column); DbArrayHelper::multisort($column, 'seqno'); /** @psalm-var IndexInfo[] $column */ @@ -726,7 +727,7 @@ protected function findViewNames(string $schema = ''): array */ protected function getCacheKey(string $name): array { - return array_merge([self::class], $this->generateCacheKey(), [$this->getRawTableName($name)]); + return array_merge([self::class], $this->generateCacheKey(), [$this->db->getQuoter()->getRawTableName($name)]); } /** From c0d1fbd05240c75be5bd7fce7cf8c2f617c3c249 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Tue, 30 Jan 2024 15:39:28 +0700 Subject: [PATCH 2/4] Add line to CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b78d56f3..17f24bac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Enh #281: Remove unused code in `Command` class (@vjik) - Enh #282: Change property `Schema::$typeMap` to constant `Schema::TYPE_MAP` (@Tigrov) - Enh #283: Remove unnecessary check for array type in `Schema::loadTableIndexes()` (@Tigrov) +- Enh #287: Resolve deprecated methods (@Tigrov) ## 1.1.0 November 12, 2023 From 58545a6cbd0092288565e02f258f8087cc5c6e56 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Thu, 1 Feb 2024 18:09:08 +0700 Subject: [PATCH 3/4] Fix test --- tests/SchemaTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index e15c3f1b..2a171127 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -352,11 +352,11 @@ public function testWorkWithPrimaryKeyConstraint(): void public function testNotConnectionPDO(): void { $db = $this->createMock(ConnectionInterface::class); - $schema = new Schema($db, DbHelper::getSchemaCache(), 'system'); + $schema = new Schema($db, DbHelper::getSchemaCache()); $this->expectException(NotSupportedException::class); $this->expectExceptionMessage('Only PDO connections are supported.'); - $schema->refreshTableSchema('customer'); + $schema->refresh(); } } From 5c49385aff5270260d4ccf4521a3b1084970f316 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Mon, 5 Feb 2024 01:01:50 +0700 Subject: [PATCH 4/4] Fix psalm issues --- src/Schema.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Schema.php b/src/Schema.php index 651defa2..beecabc4 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -643,9 +643,12 @@ private function createColumnSchema(string $name): ColumnSchemaInterface * @throws Exception * @throws InvalidConfigException * @throws Throwable + * + * @psalm-return ForeignKeyInfo[] */ private function getPragmaForeignKeyList(string $tableName): array { + /** @psalm-var ForeignKeyInfo[] */ return $this->db->createCommand( 'PRAGMA FOREIGN_KEY_LIST(' . $this->db->getQuoter()->quoteSimpleTableName($tableName) . ')' )->queryAll(); @@ -674,9 +677,12 @@ private function getPragmaIndexInfo(string $name): array * @throws Exception * @throws InvalidConfigException * @throws Throwable + * + * @psalm-return IndexListInfo[] */ private function getPragmaIndexList(string $tableName): array { + /** @psalm-var IndexListInfo[] */ return $this->db ->createCommand('PRAGMA INDEX_LIST(' . (string) $this->db->getQuoter()->quoteValue($tableName) . ')') ->queryAll(); @@ -724,10 +730,12 @@ protected function findViewNames(string $schema = ''): array * @param string $name the table name. * * @return array The cache key. + * + * @psalm-suppress DeprecatedMethod */ protected function getCacheKey(string $name): array { - return array_merge([self::class], $this->generateCacheKey(), [$this->db->getQuoter()->getRawTableName($name)]); + return array_merge([self::class], $this->generateCacheKey(), [$this->getRawTableName($name)]); } /**