From f48aa6f61ed800c3117eeeee8ea5b1d7daf6e752 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Thu, 19 Dec 2024 16:07:05 +0800 Subject: [PATCH] refactor: fix `Forge::processIndexes()` for empty `$this->fields` (#9330) --- system/Database/Forge.php | 14 ++++++++------ utils/phpstan-baseline/assign.propertyType.neon | 7 +------ .../missingType.iterableValue.neon | 7 +------ 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/system/Database/Forge.php b/system/Database/Forge.php index 06044f72b58e..d2cfde6bf104 100644 --- a/system/Database/Forge.php +++ b/system/Database/Forge.php @@ -32,9 +32,9 @@ class Forge protected $db; /** - * List of fields. + * List of fields in the form `[name => attributes]` * - * @var array [name => attributes] + * @var array|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; diff --git a/utils/phpstan-baseline/assign.propertyType.neon b/utils/phpstan-baseline/assign.propertyType.neon index 4219ce877751..2b5ea6f2ce06 100644 --- a/utils/phpstan-baseline/assign.propertyType.neon +++ b/utils/phpstan-baseline/assign.propertyType.neon @@ -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\\) does not accept array\\>\.$#' - 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 diff --git a/utils/phpstan-baseline/missingType.iterableValue.neon b/utils/phpstan-baseline/missingType.iterableValue.neon index a4aef69e7466..812228800d8f 100644 --- a/utils/phpstan-baseline/missingType.iterableValue.neon +++ b/utils/phpstan-baseline/missingType.iterableValue.neon @@ -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