Skip to content

Commit 6df2fe3

Browse files
authored
refactor: fix phpstan errors in Forge (#10470)
1 parent fda6e25 commit 6df2fe3

10 files changed

Lines changed: 50 additions & 494 deletions

File tree

system/Database/Forge.php

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Forge
5050
/**
5151
* List of unique keys.
5252
*
53-
* @var array
53+
* @var list<int>
5454
*/
5555
protected $uniqueKeys = [];
5656

@@ -64,7 +64,7 @@ class Forge
6464
/**
6565
* List of foreign keys.
6666
*
67-
* @var array
67+
* @var list<array{field: list<string>, referenceTable: string, referenceField: list<string>, onDelete: string, onUpdate: string, fkName: string}>
6868
*/
6969
protected $foreignKeys = [];
7070

@@ -146,7 +146,7 @@ class Forge
146146
/**
147147
* UNSIGNED support
148148
*
149-
* @var array|bool
149+
* @var array<array-key, string>|bool
150150
*/
151151
protected $unsigned = true;
152152

@@ -183,7 +183,7 @@ class Forge
183183
/**
184184
* Foreign Key Allowed Actions
185185
*
186-
* @var array
186+
* @var list<string>
187187
*/
188188
protected $fkAllowActions = ['CASCADE', 'SET NULL', 'NO ACTION', 'RESTRICT', 'SET DEFAULT'];
189189

@@ -324,7 +324,7 @@ public function dropDatabase(string $dbName): bool
324324
/**
325325
* Add Key
326326
*
327-
* @param array|string $key
327+
* @param list<string>|string $key
328328
*
329329
* @return Forge
330330
*/
@@ -346,7 +346,7 @@ public function addKey($key, bool $primary = false, bool $unique = false, string
346346
/**
347347
* Add Primary Key
348348
*
349-
* @param array|string $key
349+
* @param list<string>|string $key
350350
*
351351
* @return Forge
352352
*/
@@ -358,7 +358,7 @@ public function addPrimaryKey($key, string $keyName = '')
358358
/**
359359
* Add Unique Key
360360
*
361-
* @param array|string $key
361+
* @param list<string>|string $key
362362
*
363363
* @return Forge
364364
*/
@@ -370,7 +370,7 @@ public function addUniqueKey($key, string $keyName = '')
370370
/**
371371
* Add Field
372372
*
373-
* @param array<string, array|string>|string $fields Field array or Field string
373+
* @param array<array-key, array<string, mixed>|string>|string $fields Field array or Field string
374374
*
375375
* @return Forge
376376
*/
@@ -544,7 +544,7 @@ public function dropForeignKey(string $table, string $foreignName)
544544
}
545545

546546
/**
547-
* @param array $attributes Table attributes
547+
* @param array<string, mixed> $attributes Table attributes
548548
*
549549
* @return bool
550550
*
@@ -590,7 +590,7 @@ public function createTable(string $table, bool $ifNotExists = false, array $att
590590
}
591591

592592
/**
593-
* @param array $attributes Table attributes
593+
* @param array<string, mixed> $attributes Table attributes
594594
*
595595
* @return string SQL string
596596
*
@@ -626,6 +626,9 @@ protected function _createTable(string $table, bool $ifNotExists, array $attribu
626626
);
627627
}
628628

629+
/**
630+
* @param array<string, mixed> $attributes
631+
*/
629632
protected function _createTableAttributes(array $attributes): string
630633
{
631634
$sql = '';
@@ -746,7 +749,7 @@ public function renameTable(string $tableName, string $newTableName)
746749
}
747750

748751
/**
749-
* @param array<string, array|string>|string $fields Field array or Field string
752+
* @param array<array-key, array<string, mixed>|string>|string $fields Field array or Field string
750753
*
751754
* @throws DatabaseException
752755
*/
@@ -804,7 +807,7 @@ public function dropColumn(string $table, $columnNames)
804807
}
805808

806809
/**
807-
* @param array<string, array|string>|string $fields Field array or Field string
810+
* @param array<array-key, array<string, mixed>|string>|string $fields Field array or Field string
808811
*
809812
* @throws DatabaseException
810813
*/
@@ -846,9 +849,9 @@ public function modifyColumn(string $table, $fields): bool
846849
}
847850

848851
/**
849-
* @param 'ADD'|'CHANGE'|'DROP' $alterType
850-
* @param array|string $processedFields Processed column definitions
851-
* or column names to DROP
852+
* @param 'ADD'|'CHANGE'|'DROP' $alterType
853+
* @param list<array<string, mixed>>|list<string>|string $processedFields Processed column definitions
854+
* or column names to DROP
852855
*
853856
* @return ($alterType is 'DROP' ? string : false|list<string>|null)
854857
*/
@@ -884,6 +887,8 @@ protected function _alterTable(string $alterType, string $table, $processedField
884887

885888
/**
886889
* Returns $processedFields array from $this->fields data.
890+
*
891+
* @return list<array<string, mixed>>
887892
*/
888893
protected function _processFields(bool $createTable = false): array
889894
{
@@ -973,6 +978,8 @@ protected function _processFields(bool $createTable = false): array
973978

974979
/**
975980
* Converts $processedField array to field definition string.
981+
*
982+
* @param array<string, mixed> $processedField
976983
*/
977984
protected function _processColumn(array $processedField): string
978985
{
@@ -988,6 +995,8 @@ protected function _processColumn(array $processedField): string
988995
/**
989996
* Performs a data type mapping between different databases.
990997
*
998+
* @param array<string, mixed> $attributes
999+
*
9911000
* @return void
9921001
*/
9931002
protected function _attributeType(array &$attributes)
@@ -1005,6 +1014,9 @@ protected function _attributeType(array &$attributes)
10051014
* - array(TYPE => UTYPE) will change $field['type'],
10061015
* from TYPE to UTYPE in case of a match
10071016
*
1017+
* @param array<string, mixed> $attributes
1018+
* @param array<string, mixed> $field
1019+
*
10081020
* @return void
10091021
*/
10101022
protected function _attributeUnsigned(array &$attributes, array &$field)
@@ -1038,6 +1050,9 @@ protected function _attributeUnsigned(array &$attributes, array &$field)
10381050
}
10391051

10401052
/**
1053+
* @param array<string, mixed> $attributes
1054+
* @param array<string, mixed> $field
1055+
*
10411056
* @return void
10421057
*/
10431058
protected function _attributeDefault(array &$attributes, array &$field)
@@ -1062,6 +1077,9 @@ protected function _attributeDefault(array &$attributes, array &$field)
10621077
}
10631078

10641079
/**
1080+
* @param array<string, mixed> $attributes
1081+
* @param array<string, mixed> $field
1082+
*
10651083
* @return void
10661084
*/
10671085
protected function _attributeUnique(array &$attributes, array &$field)
@@ -1072,6 +1090,9 @@ protected function _attributeUnique(array &$attributes, array &$field)
10721090
}
10731091

10741092
/**
1093+
* @param array<string, mixed> $attributes
1094+
* @param array<string, mixed> $field
1095+
*
10751096
* @return void
10761097
*/
10771098
protected function _attributeAutoIncrement(array &$attributes, array &$field)
@@ -1164,6 +1185,8 @@ public function processIndexes(string $table): bool
11641185
* Generates SQL to add indexes
11651186
*
11661187
* @param bool $asQuery When true returns stand alone SQL, else partial SQL used with CREATE TABLE
1188+
*
1189+
* @return list<string>
11671190
*/
11681191
protected function _processIndexes(string $table, bool $asQuery = false): array
11691192
{
@@ -1210,6 +1233,8 @@ protected function _processIndexes(string $table, bool $asQuery = false): array
12101233
* Generates SQL to add foreign keys
12111234
*
12121235
* @param bool $asQuery When true returns stand alone SQL, else partial SQL used with CREATE TABLE
1236+
*
1237+
* @return list<string>
12131238
*/
12141239
protected function _processForeignKeys(string $table, bool $asQuery = false): array
12151240
{

system/Database/MySQLi/Forge.php

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ class Forge extends BaseForge
2424
{
2525
/**
2626
* CREATE DATABASE statement
27-
*
28-
* @var string
2927
*/
3028
protected $createDatabaseStr = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s';
3129

@@ -38,8 +36,6 @@ class Forge extends BaseForge
3836

3937
/**
4038
* DROP CONSTRAINT statement
41-
*
42-
* @var string
4339
*/
4440
protected $dropConstraintStr = 'ALTER TABLE %s DROP FOREIGN KEY %s';
4541

@@ -56,7 +52,7 @@ class Forge extends BaseForge
5652
/**
5753
* UNSIGNED support
5854
*
59-
* @var array
55+
* @var list<string>
6056
*/
6157
protected $_unsigned = [
6258
'TINYINT',
@@ -76,7 +72,7 @@ class Forge extends BaseForge
7672
/**
7773
* Table Options list which required to be quoted
7874
*
79-
* @var array
75+
* @var list<string>
8076
*/
8177
protected $_quoted_table_options = [
8278
'COMMENT',
@@ -100,7 +96,7 @@ class Forge extends BaseForge
10096
/**
10197
* CREATE TABLE attributes
10298
*
103-
* @param array $attributes Associative array of table attributes
99+
* @param array<string, mixed> $attributes Associative array of table attributes
104100
*/
105101
protected function _createTableAttributes(array $attributes): string
106102
{
@@ -129,16 +125,6 @@ protected function _createTableAttributes(array $attributes): string
129125
return $sql;
130126
}
131127

132-
/**
133-
* ALTER TABLE
134-
*
135-
* @param string $alterType ALTER type
136-
* @param string $table Table name
137-
* @param array|string $processedFields Processed column definitions
138-
* or column names to DROP
139-
*
140-
* @return ($alterType is 'DROP' ? string : list<string>)
141-
*/
142128
protected function _alterTable(string $alterType, string $table, $processedFields)
143129
{
144130
if ($alterType === 'DROP') {
@@ -187,11 +173,6 @@ protected function _processColumn(array $processedField): string
187173
. $extraClause;
188174
}
189175

190-
/**
191-
* Generates SQL to add indexes
192-
*
193-
* @param bool $asQuery When true returns stand alone SQL, else partial SQL used with CREATE TABLE
194-
*/
195176
protected function _processIndexes(string $table, bool $asQuery = false): array
196177
{
197178
$sqls = [''];

system/Database/OCI8/Forge.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,38 +31,28 @@ class Forge extends BaseForge
3131

3232
/**
3333
* CREATE DATABASE statement
34-
*
35-
* @var false
3634
*/
3735
protected $createDatabaseStr = false;
3836

3937
/**
4038
* CREATE TABLE IF statement
4139
*
42-
* @var false
43-
*
4440
* @deprecated This is no longer used.
4541
*/
4642
protected $createTableIfStr = false;
4743

4844
/**
4945
* DROP TABLE IF EXISTS statement
50-
*
51-
* @var false
5246
*/
5347
protected $dropTableIfStr = false;
5448

5549
/**
5650
* DROP DATABASE statement
57-
*
58-
* @var false
5951
*/
6052
protected $dropDatabaseStr = false;
6153

6254
/**
6355
* UNSIGNED support
64-
*
65-
* @var array|bool
6656
*/
6757
protected $unsigned = false;
6858

@@ -75,35 +65,19 @@ class Forge extends BaseForge
7565

7666
/**
7767
* RENAME TABLE statement
78-
*
79-
* @var string
8068
*/
8169
protected $renameTableStr = 'ALTER TABLE %s RENAME TO %s';
8270

8371
/**
8472
* DROP CONSTRAINT statement
85-
*
86-
* @var string
8773
*/
8874
protected $dropConstraintStr = 'ALTER TABLE %s DROP CONSTRAINT %s';
8975

9076
/**
9177
* Foreign Key Allowed Actions
92-
*
93-
* @var array
9478
*/
9579
protected $fkAllowActions = ['CASCADE', 'SET NULL', 'NO ACTION'];
9680

97-
/**
98-
* ALTER TABLE
99-
*
100-
* @param string $alterType ALTER type
101-
* @param string $table Table name
102-
* @param array|string $processedFields Processed column definitions
103-
* or column names to DROP
104-
*
105-
* @return ($alterType is 'DROP' ? string : list<string>)
106-
*/
10781
protected function _alterTable(string $alterType, string $table, $processedFields)
10882
{
10983
$sql = 'ALTER TABLE ' . $this->db->escapeIdentifiers($table);

0 commit comments

Comments
 (0)