Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: fix Forge::processIndexes() for empty $this->fields #9330

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions system/Database/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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;
Expand Down
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:
Expand All @@ -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
Expand Down
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:
Expand Down Expand Up @@ -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
Expand Down
Loading