diff --git a/src/Schema.php b/src/Schema.php index eb1286f9..2e663e88 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -33,26 +33,7 @@ /** * Implements the SQLite Server specific schema, supporting SQLite 3.3.0 or higher. * - * @psalm-type Column = array - * @psalm-type NormalizePragmaForeignKeyList = array< - * string, - * array< - * array-key, - * array{ - * id:string, - * cid:string, - * seq:string, - * table:string, - * from:string, - * to:string, - * on_update:string, - * on_delete:string - * } - * > - * > - * @psalm-type PragmaForeignKeyList = array< - * string, - * array{ + * @psalm-type ForeignKeyInfo = array{ * id:string, * cid:string, * seq:string, @@ -61,17 +42,31 @@ * to:string, * on_update:string, * on_delete:string - * } - * > - * @psalm-type PragmaIndexInfo = array - * @psalm-type PragmaIndexList = array< - * array-key, - * array{seq:string, name:string, unique:string, origin:string, partial:string} - * > - * @psalm-type PragmaTableInfo = array< - * array-key, - * array{cid:string, name:string, type:string, notnull:string, dflt_value:string|null, pk:string} + * } + * @psalm-type GroupedForeignKeyInfo = array< + * string, + * ForeignKeyInfo[] * > + * @psalm-type IndexInfo = array{ + * seqno:string, + * cid:string, + * name:string + * } + * @psalm-type IndexListInfo = array{ + * seq:string, + * name:string, + * unique:string, + * origin:string, + * partial:string + * } + * @psalm-type ColumnInfo = array{ + * cid:string, + * name:string, + * type:string, + * notnull:string, + * dflt_value:string|null, + * pk:string + * } */ final class Schema extends AbstractPdoSchema { @@ -201,15 +196,14 @@ protected function loadTablePrimaryKey(string $tableName): Constraint|null protected function loadTableForeignKeys(string $tableName): array { $result = []; - /** @psalm-var PragmaForeignKeyList $foreignKeysList */ + $foreignKeysList = $this->getPragmaForeignKeyList($tableName); - /** @psalm-var NormalizePragmaForeignKeyList $foreignKeysList */ + /** @psalm-var ForeignKeyInfo[] $foreignKeysList */ $foreignKeysList = $this->normalizeRowKeyCase($foreignKeysList, true); - /** @psalm-var NormalizePragmaForeignKeyList $foreignKeysList */ $foreignKeysList = DbArrayHelper::index($foreignKeysList, null, ['table']); DbArrayHelper::multisort($foreignKeysList, 'seq'); - /** @psalm-var NormalizePragmaForeignKeyList $foreignKeysList */ + /** @psalm-var GroupedForeignKeyInfo $foreignKeysList */ foreach ($foreignKeysList as $table => $foreignKey) { $fk = (new ForeignKeyConstraint()) ->columnNames(DbArrayHelper::getColumn($foreignKey, 'from')) @@ -347,7 +341,7 @@ protected function loadTableDefaultValues(string $tableName): array */ protected function findColumns(TableSchemaInterface $table): bool { - /** @psalm-var PragmaTableInfo $columns */ + /** @psalm-var ColumnInfo[] $columns */ $columns = $this->getPragmaTableInfo($table->getName()); foreach ($columns as $info) { @@ -380,7 +374,7 @@ protected function findColumns(TableSchemaInterface $table): bool */ protected function findConstraints(TableSchemaInterface $table): void { - /** @psalm-var PragmaForeignKeyList $foreignKeysList */ + /** @psalm-var ForeignKeyInfo[] $foreignKeysList */ $foreignKeysList = $this->getPragmaForeignKeyList($table->getName()); foreach ($foreignKeysList as $foreignKey) { @@ -418,13 +412,13 @@ protected function findConstraints(TableSchemaInterface $table): void */ public function findUniqueIndexes(TableSchemaInterface $table): array { - /** @psalm-var PragmaIndexList $indexList */ + /** @psalm-var IndexListInfo[] $indexList */ $indexList = $this->getPragmaIndexList($table->getName()); $uniqueIndexes = []; foreach ($indexList as $index) { $indexName = $index['name']; - /** @psalm-var PragmaIndexInfo $indexInfo */ + /** @psalm-var IndexInfo[] $indexInfo */ $indexInfo = $this->getPragmaIndexInfo($index['name']); if ($index['unique']) { @@ -535,7 +529,7 @@ private function normalizeDefaultValue(string|null $defaultValue, ColumnSchemaIn private function loadTableColumnsInfo(string $tableName): array { $tableColumns = $this->getPragmaTableInfo($tableName); - /** @psalm-var PragmaTableInfo $tableColumns */ + /** @psalm-var ColumnInfo[] $tableColumns */ $tableColumns = $this->normalizeRowKeyCase($tableColumns, true); return DbArrayHelper::index($tableColumns, 'cid'); @@ -556,7 +550,7 @@ private function loadTableColumnsInfo(string $tableName): array private function loadTableConstraints(string $tableName, string $returnType): Constraint|array|null { $indexList = $this->getPragmaIndexList($tableName); - /** @psalm-var PragmaIndexList $indexes */ + /** @psalm-var IndexListInfo[] $indexes */ $indexes = $this->normalizeRowKeyCase($indexList, true); $result = [ self::PRIMARY_KEY => null, @@ -565,7 +559,7 @@ private function loadTableConstraints(string $tableName, string $returnType): Co ]; foreach ($indexes as $index) { - /** @psalm-var Column $columns */ + /** @psalm-var IndexInfo[] $columns */ $columns = $this->getPragmaIndexInfo($index['name']); if ($index['origin'] === 'pk') { @@ -592,7 +586,7 @@ private function loadTableConstraints(string $tableName, string $returnType): Co * * @link https://www.sqlite.org/lang_createtable.html#primkeyconst * - * @psalm-var PragmaTableInfo $tableColumns + * @psalm-var ColumnInfo[] $tableColumns */ $tableColumns = $this->loadTableColumnsInfo($tableName); @@ -645,7 +639,7 @@ private function getPragmaIndexInfo(string $name): array $column = $this->db ->createCommand('PRAGMA INDEX_INFO(' . (string) $this->db->getQuoter()->quoteValue($name) . ')') ->queryAll(); - /** @psalm-var Column $column */ + /** @psalm-var IndexInfo[] $column */ $column = $this->normalizeRowKeyCase($column, true); DbArrayHelper::multisort($column, 'seqno');