Skip to content

Commit

Permalink
refactor: fix Forge::processIndexes() for empty $this->fields (#9330
Browse files Browse the repository at this point in the history
)
paulbalandan authored Dec 19, 2024
1 parent cc2dcee commit f48aa6f
Showing 3 changed files with 10 additions and 18 deletions.
14 changes: 8 additions & 6 deletions system/Database/Forge.php
Original file line number Diff line number Diff line change
@@ -32,9 +32,9 @@ class Forge
protected $db;

/**
* List of fields.
* List of fields in the form `[name => attributes]`
*
* @var array<string, array|string> [name => attributes]
* @var array<string, array<string, bool|string>|string>
*/
protected $fields = [];

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

if ($this->fields === []) {
$this->fields = array_flip(array_map(
static fn ($columnName) => $columnName->name,
$this->db->getFieldData($this->db->DBPrefix . $table)
));
$fieldData = $this->db->getFieldData($this->db->DBPrefix . $table);

$this->fields = array_combine(
array_map(static fn ($columnName) => $columnName->name, $fieldData),
array_fill(0, count($fieldData), [])
);
}

$fields = $this->fields;
7 changes: 1 addition & 6 deletions utils/phpstan-baseline/assign.propertyType.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 21 errors
# total 20 errors

parameters:
ignoreErrors:
@@ -7,11 +7,6 @@ parameters:
count: 1
path: ../../system/Controller.php

-
message: '#^Property CodeIgniter\\Database\\Forge\:\:\$fields \(array\<string, array\|string\>\) does not accept array\<int\|string, int\<0, max\>\>\.$#'
count: 1
path: ../../system/Database/Forge.php

-
message: '#^Property class@anonymous/tests/system/API/ResponseTraitTest\.php\:639\:\:\$format \(''html''\|''json''\|''xml''\|null\) does not accept ''txt''\.$#'
count: 1
7 changes: 1 addition & 6 deletions utils/phpstan-baseline/missingType.iterableValue.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 1687 errors
# total 1686 errors

parameters:
ignoreErrors:
@@ -1707,11 +1707,6 @@ parameters:
count: 1
path: ../../system/Database/Forge.php

-
message: '#^Property CodeIgniter\\Database\\Forge\:\:\$fields type has no value type specified in iterable type array\.$#'
count: 1
path: ../../system/Database/Forge.php

-
message: '#^Property CodeIgniter\\Database\\Forge\:\:\$fkAllowActions type has no value type specified in iterable type array\.$#'
count: 1

0 comments on commit f48aa6f

Please sign in to comment.