Skip to content

Commit 36aa01a

Browse files
Tigrovvjik
andauthored
Resolve deprecated methods (#287)
* Resolve deprecated methods * Add line to CHANGELOG.md * Fix test * Fix psalm issues --------- Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
1 parent f0acbe5 commit 36aa01a

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Enh #282: Change property `Schema::$typeMap` to constant `Schema::TYPE_MAP` (@Tigrov)
77
- Enh #283: Remove unnecessary check for array type in `Schema::loadTableIndexes()` (@Tigrov)
88
- Enh #288: Minor refactoring of `DDLQueryBuilder` and `Schema` (@Tigrov)
9+
- Enh #287: Resolve deprecated methods (@Tigrov)
910

1011
## 1.1.0 November 12, 2023
1112

src/Schema.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Yiisoft\Db\Schema\TableSchemaInterface;
2222

2323
use function array_column;
24+
use function array_map;
2425
use function array_merge;
2526
use function count;
2627
use function explode;
@@ -201,7 +202,7 @@ protected function loadTableForeignKeys(string $tableName): array
201202

202203
$foreignKeysList = $this->getPragmaForeignKeyList($tableName);
203204
/** @psalm-var ForeignKeyInfo[] $foreignKeysList */
204-
$foreignKeysList = $this->normalizeRowKeyCase($foreignKeysList, true);
205+
$foreignKeysList = array_map('array_change_key_case', $foreignKeysList);
205206
$foreignKeysList = DbArrayHelper::index($foreignKeysList, null, ['table']);
206207
DbArrayHelper::multisort($foreignKeysList, 'seq');
207208

@@ -553,7 +554,7 @@ private function loadTableColumnsInfo(string $tableName): array
553554
{
554555
$tableColumns = $this->getPragmaTableInfo($tableName);
555556
/** @psalm-var ColumnInfo[] $tableColumns */
556-
$tableColumns = $this->normalizeRowKeyCase($tableColumns, true);
557+
$tableColumns = array_map('array_change_key_case', $tableColumns);
557558

558559
/** @psalm-var ColumnInfo[] */
559560
return DbArrayHelper::index($tableColumns, 'cid');
@@ -575,7 +576,7 @@ private function loadTableConstraints(string $tableName, string $returnType): Co
575576
{
576577
$indexList = $this->getPragmaIndexList($tableName);
577578
/** @psalm-var IndexListInfo[] $indexes */
578-
$indexes = $this->normalizeRowKeyCase($indexList, true);
579+
$indexes = array_map('array_change_key_case', $indexList);
579580
$result = [
580581
self::PRIMARY_KEY => null,
581582
self::INDEXES => [],
@@ -642,9 +643,12 @@ private function createColumnSchema(string $name): ColumnSchemaInterface
642643
* @throws Exception
643644
* @throws InvalidConfigException
644645
* @throws Throwable
646+
*
647+
* @psalm-return ForeignKeyInfo[]
645648
*/
646649
private function getPragmaForeignKeyList(string $tableName): array
647650
{
651+
/** @psalm-var ForeignKeyInfo[] */
648652
return $this->db->createCommand(
649653
'PRAGMA FOREIGN_KEY_LIST(' . $this->db->getQuoter()->quoteSimpleTableName($tableName) . ')'
650654
)->queryAll();
@@ -662,7 +666,7 @@ private function getPragmaIndexInfo(string $name): array
662666
$column = $this->db
663667
->createCommand('PRAGMA INDEX_INFO(' . (string) $this->db->getQuoter()->quoteValue($name) . ')')
664668
->queryAll();
665-
$column = $this->normalizeRowKeyCase($column, true);
669+
$column = array_map('array_change_key_case', $column);
666670
DbArrayHelper::multisort($column, 'seqno');
667671

668672
/** @psalm-var IndexInfo[] $column */
@@ -673,9 +677,12 @@ private function getPragmaIndexInfo(string $name): array
673677
* @throws Exception
674678
* @throws InvalidConfigException
675679
* @throws Throwable
680+
*
681+
* @psalm-return IndexListInfo[]
676682
*/
677683
private function getPragmaIndexList(string $tableName): array
678684
{
685+
/** @psalm-var IndexListInfo[] */
679686
return $this->db
680687
->createCommand('PRAGMA INDEX_LIST(' . (string) $this->db->getQuoter()->quoteValue($tableName) . ')')
681688
->queryAll();
@@ -723,6 +730,8 @@ protected function findViewNames(string $schema = ''): array
723730
* @param string $name the table name.
724731
*
725732
* @return array The cache key.
733+
*
734+
* @psalm-suppress DeprecatedMethod
726735
*/
727736
protected function getCacheKey(string $name): array
728737
{

tests/SchemaTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,11 @@ public function testWorkWithPrimaryKeyConstraint(): void
352352
public function testNotConnectionPDO(): void
353353
{
354354
$db = $this->createMock(ConnectionInterface::class);
355-
$schema = new Schema($db, DbHelper::getSchemaCache(), 'system');
355+
$schema = new Schema($db, DbHelper::getSchemaCache());
356356

357357
$this->expectException(NotSupportedException::class);
358358
$this->expectExceptionMessage('Only PDO connections are supported.');
359359

360-
$schema->refreshTableSchema('customer');
360+
$schema->refresh();
361361
}
362362
}

0 commit comments

Comments
 (0)