diff --git a/phpstan-baseline.php b/phpstan-baseline.php index c49b156548eb..a5ad5aa95b7d 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -2677,12 +2677,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Database/Forge.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.iterableValue - 'message' => '#^Method CodeIgniter\\\\Database\\\\Forge\\:\\:dropColumn\\(\\) has parameter \\$columnNames with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/Forge.php', -]; $ignoreErrors[] = [ // identifier: missingType.iterableValue 'message' => '#^Method CodeIgniter\\\\Database\\\\Forge\\:\\:modifyColumn\\(\\) has parameter \\$fields with no value type specified in iterable type array\\.$#', diff --git a/system/Database/Forge.php b/system/Database/Forge.php index 595cd6156b5f..b7f6743634f8 100644 --- a/system/Database/Forge.php +++ b/system/Database/Forge.php @@ -778,7 +778,7 @@ public function addColumn(string $table, $fields): bool } /** - * @param array|string $columnNames column names to DROP + * @param list|string $columnNames column names to DROP * * @return bool * diff --git a/system/Database/SQLite3/Forge.php b/system/Database/SQLite3/Forge.php index 48e9abcc425c..f0a38a817453 100644 --- a/system/Database/SQLite3/Forge.php +++ b/system/Database/SQLite3/Forge.php @@ -121,17 +121,6 @@ public function dropDatabase(string $dbName): bool protected function _alterTable(string $alterType, string $table, $processedFields) { switch ($alterType) { - case 'DROP': - $columnNamesToDrop = $processedFields; - - $sqlTable = new Table($this->db, $this); - - $sqlTable->fromTable($table) - ->dropColumn($columnNamesToDrop) - ->run(); - - return ''; // Why empty string? - case 'CHANGE': $fieldsToModify = []; @@ -164,6 +153,33 @@ protected function _alterTable(string $alterType, string $table, $processedField } } + /** + * @param list|string $columnNames column names to DROP + * + * @return bool + * + * @throws DatabaseException + */ + public function dropColumn(string $table, $columnNames) + { + $sqlTable = new Table($this->db, $this); + + $sqlExecuteResult = $sqlTable->fromTable($this->db->DBPrefix . $table) + ->dropColumn($columnNames) + ->run(); + + if ($sqlExecuteResult === false) { + $columns = is_array($columnNames) ? implode(',', $columnNames) : $columnNames; + + throw new DatabaseException( + 'Failed to drop column. Table: "' . $table + . '", Column: "' . $columns . '"' + ); + } + + return $sqlExecuteResult; + } + /** * Process column */ diff --git a/tests/system/Database/Live/ForgeTest.php b/tests/system/Database/Live/ForgeTest.php index 7fccd6b1d298..5772aae95405 100644 --- a/tests/system/Database/Live/ForgeTest.php +++ b/tests/system/Database/Live/ForgeTest.php @@ -1317,7 +1317,8 @@ public function testDropColumn(): void $this->assertTrue($this->db->fieldExists('name', 'forge_test_two')); - $this->forge->dropColumn('forge_test_two', 'name'); + $result = $this->forge->dropColumn('forge_test_two', 'name'); + $this->assertTrue($result); $this->db->resetDataCache();