From 6b7b6398d32626dafaa5518e9f9a05722a4596f0 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Fri, 24 Nov 2023 16:20:19 +0300 Subject: [PATCH 1/2] Specify result type of `ConstraintSchemaInterface::getTableIndexes()` method to `IndexConstraint[]` --- CHANGELOG.md | 1 + src/Constraint/ConstraintSchemaInterface.php | 2 +- src/QueryBuilder/AbstractDMLQueryBuilder.php | 2 -- src/Schema/AbstractSchema.php | 5 +++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af82ceefc..792406c06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ `DbArrayHelper::populate()` methods to `array[]` (@vjik) - Enh #779: Specify populate closure type in `BatchQueryResultInterface` (@vjik) - Enh #778: Deprecate unnecessary argument `$rawSql` of `AbstractCommand::internalExecute()` (@Tigrov) +- Enh #784: Specify result type of `ConstraintSchemaInterface::getTableIndexes()` method to `IndexConstraint[]` (@vjik) ## 1.2.0 November 12, 2023 diff --git a/src/Constraint/ConstraintSchemaInterface.php b/src/Constraint/ConstraintSchemaInterface.php index 309bc6c5a..957ea6b3f 100644 --- a/src/Constraint/ConstraintSchemaInterface.php +++ b/src/Constraint/ConstraintSchemaInterface.php @@ -131,7 +131,7 @@ public function getTableForeignKeys(string $name, bool $refresh = false): array; * @param string $name Table name. The table name may contain a schema name if any. Don't quote the table name. * @param bool $refresh Whether to reload the information, even if it's found in the cache. * - * @return array The information metadata for the indexes of the named table. + * @return IndexConstraint[] The information metadata for the indexes of the named table. */ public function getTableIndexes(string $name, bool $refresh = false): array; diff --git a/src/QueryBuilder/AbstractDMLQueryBuilder.php b/src/QueryBuilder/AbstractDMLQueryBuilder.php index 5d57d6412..b3c0a4132 100644 --- a/src/QueryBuilder/AbstractDMLQueryBuilder.php +++ b/src/QueryBuilder/AbstractDMLQueryBuilder.php @@ -6,7 +6,6 @@ use JsonException; use Yiisoft\Db\Constraint\Constraint; -use Yiisoft\Db\Constraint\IndexConstraint; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidArgumentException; use Yiisoft\Db\Exception\InvalidConfigException; @@ -335,7 +334,6 @@ private function getTableUniqueColumnNames(string $name, array $columns, array & $constraints[] = $primaryKey; } - /** @psalm-var IndexConstraint[] $tableIndexes */ $tableIndexes = $this->schema->getTableIndexes($name); foreach ($tableIndexes as $constraint) { diff --git a/src/Schema/AbstractSchema.php b/src/Schema/AbstractSchema.php index cd1c89cb0..4ab2a048a 100644 --- a/src/Schema/AbstractSchema.php +++ b/src/Schema/AbstractSchema.php @@ -10,6 +10,7 @@ use Yiisoft\Db\Command\DataType; use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Constraint\Constraint; +use Yiisoft\Db\Constraint\IndexConstraint; use Yiisoft\Db\Exception\NotSupportedException; use function array_change_key_case; @@ -95,7 +96,7 @@ abstract protected function loadTableForeignKeys(string $tableName): array; * * @param string $tableName The table name. * - * @return array The indexes for the given table. + * @return IndexConstraint[] The indexes for the given table. */ abstract protected function loadTableIndexes(string $tableName): array; @@ -261,7 +262,7 @@ public function getTableForeignKeys(string $name, bool $refresh = false): array */ public function getTableIndexes(string $name, bool $refresh = false): array { - /** @psalm-var mixed $tableIndexes */ + /** @var IndexConstraint[]|null $tableIndexes */ $tableIndexes = $this->getTableMetadata($name, SchemaInterface::INDEXES, $refresh); return is_array($tableIndexes) ? $tableIndexes : []; } From b3be66b52e8e80eae716240cbe685b8e2a9c3554 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sun, 26 Nov 2023 11:06:24 +0300 Subject: [PATCH 2/2] improve --- CHANGELOG.md | 1 + src/Schema/AbstractSchema.php | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 792406c06..f3c06c3a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Enh #779: Specify populate closure type in `BatchQueryResultInterface` (@vjik) - Enh #778: Deprecate unnecessary argument `$rawSql` of `AbstractCommand::internalExecute()` (@Tigrov) - Enh #784: Specify result type of `ConstraintSchemaInterface::getTableIndexes()` method to `IndexConstraint[]` (@vjik) +- Enh #784: Remove unused code in `AbstractSchema::getTableIndexes()` (@vjik) ## 1.2.0 November 12, 2023 diff --git a/src/Schema/AbstractSchema.php b/src/Schema/AbstractSchema.php index 4ab2a048a..7e88d45f6 100644 --- a/src/Schema/AbstractSchema.php +++ b/src/Schema/AbstractSchema.php @@ -262,9 +262,8 @@ public function getTableForeignKeys(string $name, bool $refresh = false): array */ public function getTableIndexes(string $name, bool $refresh = false): array { - /** @var IndexConstraint[]|null $tableIndexes */ - $tableIndexes = $this->getTableMetadata($name, SchemaInterface::INDEXES, $refresh); - return is_array($tableIndexes) ? $tableIndexes : []; + /** @var IndexConstraint[] */ + return $this->getTableMetadata($name, SchemaInterface::INDEXES, $refresh); } /**