Skip to content

Commit f48aa6f

Browse files
authored
refactor: fix Forge::processIndexes() for empty $this->fields (#9330)
1 parent cc2dcee commit f48aa6f

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

system/Database/Forge.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class Forge
3232
protected $db;
3333

3434
/**
35-
* List of fields.
35+
* List of fields in the form `[name => attributes]`
3636
*
37-
* @var array<string, array|string> [name => attributes]
37+
* @var array<string, array<string, bool|string>|string>
3838
*/
3939
protected $fields = [];
4040

@@ -1108,10 +1108,12 @@ public function processIndexes(string $table): bool
11081108
$fk = $this->foreignKeys;
11091109

11101110
if ($this->fields === []) {
1111-
$this->fields = array_flip(array_map(
1112-
static fn ($columnName) => $columnName->name,
1113-
$this->db->getFieldData($this->db->DBPrefix . $table)
1114-
));
1111+
$fieldData = $this->db->getFieldData($this->db->DBPrefix . $table);
1112+
1113+
$this->fields = array_combine(
1114+
array_map(static fn ($columnName) => $columnName->name, $fieldData),
1115+
array_fill(0, count($fieldData), [])
1116+
);
11151117
}
11161118

11171119
$fields = $this->fields;

utils/phpstan-baseline/assign.propertyType.neon

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 21 errors
1+
# total 20 errors
22

33
parameters:
44
ignoreErrors:
@@ -7,11 +7,6 @@ parameters:
77
count: 1
88
path: ../../system/Controller.php
99

10-
-
11-
message: '#^Property CodeIgniter\\Database\\Forge\:\:\$fields \(array\<string, array\|string\>\) does not accept array\<int\|string, int\<0, max\>\>\.$#'
12-
count: 1
13-
path: ../../system/Database/Forge.php
14-
1510
-
1611
message: '#^Property class@anonymous/tests/system/API/ResponseTraitTest\.php\:639\:\:\$format \(''html''\|''json''\|''xml''\|null\) does not accept ''txt''\.$#'
1712
count: 1

utils/phpstan-baseline/missingType.iterableValue.neon

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 1687 errors
1+
# total 1686 errors
22

33
parameters:
44
ignoreErrors:
@@ -1707,11 +1707,6 @@ parameters:
17071707
count: 1
17081708
path: ../../system/Database/Forge.php
17091709

1710-
-
1711-
message: '#^Property CodeIgniter\\Database\\Forge\:\:\$fields type has no value type specified in iterable type array\.$#'
1712-
count: 1
1713-
path: ../../system/Database/Forge.php
1714-
17151710
-
17161711
message: '#^Property CodeIgniter\\Database\\Forge\:\:\$fkAllowActions type has no value type specified in iterable type array\.$#'
17171712
count: 1

0 commit comments

Comments
 (0)