Skip to content

Commit b35e9e4

Browse files
authored
Merge 7084360 into ff859e8
2 parents ff859e8 + 7084360 commit b35e9e4

File tree

1 file changed

+38
-44
lines changed

1 file changed

+38
-44
lines changed

src/Schema.php

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -33,45 +33,40 @@
3333
/**
3434
* Implements the SQLite Server specific schema, supporting SQLite 3.3.0 or higher.
3535
*
36-
* @psalm-type Column = array<array-key, array{seqno:string, cid:string, name:string}>
37-
* @psalm-type NormalizePragmaForeignKeyList = array<
38-
* string,
39-
* array<
40-
* array-key,
41-
* array{
42-
* id:string,
43-
* cid:string,
44-
* seq:string,
45-
* table:string,
46-
* from:string,
47-
* to:string,
48-
* on_update:string,
49-
* on_delete:string
50-
* }
51-
* >
52-
* >
53-
* @psalm-type PragmaForeignKeyList = array<
54-
* string,
55-
* array{
36+
* @psalm-type PragmaForeignKeyList = array{
5637
* id:string,
5738
* cid:string,
5839
* seq:string,
5940
* table:string,
6041
* from:string,
61-
* to:string,
42+
* to:string|null,
6243
* on_update:string,
6344
* on_delete:string
64-
* }
65-
* >
66-
* @psalm-type PragmaIndexInfo = array<array-key, array{seqno:string, cid:string, name:string}>
67-
* @psalm-type PragmaIndexList = array<
68-
* array-key,
69-
* array{seq:string, name:string, unique:string, origin:string, partial:string}
70-
* >
71-
* @psalm-type PragmaTableInfo = array<
72-
* array-key,
73-
* array{cid:string, name:string, type:string, notnull:string, dflt_value:string|null, pk:string}
45+
* }
46+
* @psalm-type IndexedPragmaForeignKeyList = array<
47+
* string,
48+
* PragmaForeignKeyList[]
7449
* >
50+
* @psalm-type PragmaIndexInfo = array{
51+
* seqno:string,
52+
* cid:string,
53+
* name:string
54+
* }
55+
* @psalm-type PragmaIndexList = array{
56+
* seq:string,
57+
* name:string,
58+
* unique:string,
59+
* origin:string,
60+
* partial:string
61+
* }
62+
* @psalm-type PragmaTableInfo = array{
63+
* cid:string,
64+
* name:string,
65+
* type:string,
66+
* notnull:string,
67+
* dflt_value:string|null,
68+
* pk:string
69+
* }
7570
*/
7671
final class Schema extends AbstractPdoSchema
7772
{
@@ -201,15 +196,14 @@ protected function loadTablePrimaryKey(string $tableName): Constraint|null
201196
protected function loadTableForeignKeys(string $tableName): array
202197
{
203198
$result = [];
204-
/** @psalm-var PragmaForeignKeyList $foreignKeysList */
199+
205200
$foreignKeysList = $this->getPragmaForeignKeyList($tableName);
206-
/** @psalm-var NormalizePragmaForeignKeyList $foreignKeysList */
201+
/** @psalm-var PragmaForeignKeyList[] $foreignKeysList */
207202
$foreignKeysList = $this->normalizeRowKeyCase($foreignKeysList, true);
208-
/** @psalm-var NormalizePragmaForeignKeyList $foreignKeysList */
209203
$foreignKeysList = DbArrayHelper::index($foreignKeysList, null, ['table']);
210204
DbArrayHelper::multisort($foreignKeysList, 'seq');
211205

212-
/** @psalm-var NormalizePragmaForeignKeyList $foreignKeysList */
206+
/** @psalm-var IndexedPragmaForeignKeyList $foreignKeysList */
213207
foreach ($foreignKeysList as $table => $foreignKey) {
214208
$fk = (new ForeignKeyConstraint())
215209
->columnNames(DbArrayHelper::getColumn($foreignKey, 'from'))
@@ -347,7 +341,7 @@ protected function loadTableDefaultValues(string $tableName): array
347341
*/
348342
protected function findColumns(TableSchemaInterface $table): bool
349343
{
350-
/** @psalm-var PragmaTableInfo $columns */
344+
/** @psalm-var PragmaTableInfo[] $columns */
351345
$columns = $this->getPragmaTableInfo($table->getName());
352346

353347
foreach ($columns as $info) {
@@ -380,7 +374,7 @@ protected function findColumns(TableSchemaInterface $table): bool
380374
*/
381375
protected function findConstraints(TableSchemaInterface $table): void
382376
{
383-
/** @psalm-var PragmaForeignKeyList $foreignKeysList */
377+
/** @psalm-var PragmaForeignKeyList[] $foreignKeysList */
384378
$foreignKeysList = $this->getPragmaForeignKeyList($table->getName());
385379

386380
foreach ($foreignKeysList as $foreignKey) {
@@ -418,13 +412,13 @@ protected function findConstraints(TableSchemaInterface $table): void
418412
*/
419413
public function findUniqueIndexes(TableSchemaInterface $table): array
420414
{
421-
/** @psalm-var PragmaIndexList $indexList */
415+
/** @psalm-var PragmaIndexList[] $indexList */
422416
$indexList = $this->getPragmaIndexList($table->getName());
423417
$uniqueIndexes = [];
424418

425419
foreach ($indexList as $index) {
426420
$indexName = $index['name'];
427-
/** @psalm-var PragmaIndexInfo $indexInfo */
421+
/** @psalm-var PragmaIndexInfo[] $indexInfo */
428422
$indexInfo = $this->getPragmaIndexInfo($index['name']);
429423

430424
if ($index['unique']) {
@@ -535,7 +529,7 @@ private function normalizeDefaultValue(string|null $defaultValue, ColumnSchemaIn
535529
private function loadTableColumnsInfo(string $tableName): array
536530
{
537531
$tableColumns = $this->getPragmaTableInfo($tableName);
538-
/** @psalm-var PragmaTableInfo $tableColumns */
532+
/** @psalm-var PragmaTableInfo[] $tableColumns */
539533
$tableColumns = $this->normalizeRowKeyCase($tableColumns, true);
540534

541535
return DbArrayHelper::index($tableColumns, 'cid');
@@ -556,7 +550,7 @@ private function loadTableColumnsInfo(string $tableName): array
556550
private function loadTableConstraints(string $tableName, string $returnType): Constraint|array|null
557551
{
558552
$indexList = $this->getPragmaIndexList($tableName);
559-
/** @psalm-var PragmaIndexList $indexes */
553+
/** @psalm-var PragmaIndexList[] $indexes */
560554
$indexes = $this->normalizeRowKeyCase($indexList, true);
561555
$result = [
562556
self::PRIMARY_KEY => null,
@@ -565,7 +559,7 @@ private function loadTableConstraints(string $tableName, string $returnType): Co
565559
];
566560

567561
foreach ($indexes as $index) {
568-
/** @psalm-var Column $columns */
562+
/** @psalm-var PragmaIndexInfo[] $columns */
569563
$columns = $this->getPragmaIndexInfo($index['name']);
570564

571565
if ($index['origin'] === 'pk') {
@@ -592,7 +586,7 @@ private function loadTableConstraints(string $tableName, string $returnType): Co
592586
*
593587
* @link https://www.sqlite.org/lang_createtable.html#primkeyconst
594588
*
595-
* @psalm-var PragmaTableInfo $tableColumns
589+
* @psalm-var PragmaTableInfo[] $tableColumns
596590
*/
597591
$tableColumns = $this->loadTableColumnsInfo($tableName);
598592

@@ -645,7 +639,7 @@ private function getPragmaIndexInfo(string $name): array
645639
$column = $this->db
646640
->createCommand('PRAGMA INDEX_INFO(' . (string) $this->db->getQuoter()->quoteValue($name) . ')')
647641
->queryAll();
648-
/** @psalm-var Column $column */
642+
/** @psalm-var PragmaIndexInfo[] $column */
649643
$column = $this->normalizeRowKeyCase($column, true);
650644
DbArrayHelper::multisort($column, 'seqno');
651645

0 commit comments

Comments
 (0)