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

Database Forge correction #1899

Merged
merged 7 commits into from
Apr 1, 2019
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
2 changes: 1 addition & 1 deletion system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ public function query(string $sql, $binds = null, bool $setEscapeFlags = true, $

if (! $this->pretend)
{
// Let others do somethign with this query
// Let others do something with this query
Events::trigger('DBQuery', $query);
}

Expand Down
66 changes: 33 additions & 33 deletions system/Database/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function getConnection()
* @return boolean
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function createDatabase($db_name)
public function createDatabase(string $db_name): bool
{
if ($this->createDatabaseStr === false)
{
Expand Down Expand Up @@ -244,7 +244,7 @@ public function createDatabase($db_name)
* @return boolean
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function dropDatabase($db_name)
public function dropDatabase(string $db_name): bool
{
if ($this->dropDatabaseStr === false)
{
Expand Down Expand Up @@ -394,7 +394,7 @@ public function addField($field)
* @return \CodeIgniter\Database\Forge
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function addForeignKey($fieldName = '', $tableName = '', $tableField = '', $onUpdate = false, $onDelete = false)
public function addForeignKey(string $fieldName = '', string $tableName = '', string $tableField = '', bool $onUpdate = false, bool $onDelete = false)
{
if (! isset($this->fields[$fieldName]))
{
Expand Down Expand Up @@ -422,7 +422,7 @@ public function addForeignKey($fieldName = '', $tableName = '', $tableField = ''
* @return boolean|\CodeIgniter\Database\BaseResult|\CodeIgniter\Database\Query|false|mixed
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function dropForeignKey($table, $foreign_name)
public function dropForeignKey(string $table, string $foreign_name)
{
$sql = sprintf($this->dropConstraintStr, $this->db->escapeIdentifiers($this->db->DBPrefix . $table),
$this->db->escapeIdentifiers($this->db->DBPrefix . $foreign_name));
Expand All @@ -449,10 +449,10 @@ public function dropForeignKey($table, $foreign_name)
* @param boolean $if_not_exists Whether to add IF NOT EXISTS condition
* @param array $attributes Associative array of table attributes
*
* @return boolean
* @return mixed
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function createTable($table, $if_not_exists = false, array $attributes = [])
public function createTable(string $table, bool $if_not_exists = false, array $attributes = [])
{
if ($table === '')
{
Expand Down Expand Up @@ -484,7 +484,7 @@ public function createTable($table, $if_not_exists = false, array $attributes =

if (($result = $this->db->query($sql)) !== false)
{
empty($this->db->dataCache['table_names']) || $this->db->dataCache['table_names'][] = $table;
empty($this->db->dataCache['table_names']) || ($this->db->dataCache['table_names'][] = $table);

// Most databases don't support creating indexes from within the CREATE TABLE statement
if (! empty($this->keys))
Expand Down Expand Up @@ -512,7 +512,7 @@ public function createTable($table, $if_not_exists = false, array $attributes =
*
* @return mixed
*/
protected function _createTable($table, $if_not_exists, $attributes)
protected function _createTable(string $table, bool $if_not_exists, array $attributes)
{
// For any platforms that don't support Create If Not Exists...
if ($if_not_exists === true && $this->createTableIfStr === false)
Expand Down Expand Up @@ -562,7 +562,7 @@ protected function _createTable($table, $if_not_exists, $attributes)
*
* @return string
*/
protected function _createTableAttributes($attributes)
protected function _createTableAttributes(array $attributes): string
{
$sql = '';

Expand All @@ -589,7 +589,7 @@ protected function _createTableAttributes($attributes)
* @return mixed
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function dropTable($table_name, $if_exists = false, $cascade = false)
public function dropTable(string $table_name, bool $if_exists = false, bool $cascade = false)
{
if ($table_name === '')
{
Expand Down Expand Up @@ -641,7 +641,7 @@ public function dropTable($table_name, $if_exists = false, $cascade = false)
*
* @return string
*/
protected function _dropTable($table, $if_exists, $cascade)
protected function _dropTable(string $table, bool $if_exists, bool $cascade): string
{
$sql = 'DROP TABLE';

Expand Down Expand Up @@ -676,7 +676,7 @@ protected function _dropTable($table, $if_exists, $cascade)
* @return mixed
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function renameTable($table_name, $new_table_name)
public function renameTable(string $table_name, string $new_table_name)
{
if ($table_name === '' || $new_table_name === '')
{
Expand Down Expand Up @@ -715,13 +715,13 @@ public function renameTable($table_name, $new_table_name)
/**
* Column Add
*
* @param string $table Table name
* @param array $field Column definition
* @param string $table Table name
* @param string|array $field Column definition
*
* @return boolean
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function addColumn($table, $field)
public function addColumn(string $table, $field): bool
{
// Work-around for literal column definitions
is_array($field) || $field = [$field];
Expand Down Expand Up @@ -762,10 +762,10 @@ public function addColumn($table, $field)
* @param string $table Table name
* @param string $column_name Column name
*
* @return boolean
* @return mixed
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function dropColumn($table, $column_name)
public function dropColumn(string $table, string $column_name)
{
$sql = $this->_alterTable('DROP', $this->db->DBPrefix . $table, $column_name);
if ($sql === false)
Expand All @@ -786,13 +786,13 @@ public function dropColumn($table, $column_name)
/**
* Column Modify
*
* @param string $table Table name
* @param string $field Column definition
* @param string $table Table name
* @param string|array $field Column definition
*
* @return boolean
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function modifyColumn($table, $field)
public function modifyColumn(string $table, $field): bool
{
// Work-around for literal column definitions
is_array($field) || $field = [$field];
Expand Down Expand Up @@ -844,7 +844,7 @@ public function modifyColumn($table, $field)
*
* @return string|string[]
*/
protected function _alterTable($alter_type, $table, $field)
protected function _alterTable(string $alter_type, string $table, $field)
{
$sql = 'ALTER TABLE ' . $this->db->escapeIdentifiers($table) . ' ';

Expand Down Expand Up @@ -875,7 +875,7 @@ protected function _alterTable($alter_type, $table, $field)
*
* @return array
*/
protected function _processFields($create_table = false)
protected function _processFields(bool $create_table = false): array
{
$fields = [];

Expand Down Expand Up @@ -975,7 +975,7 @@ protected function _processFields($create_table = false)
*
* @return string
*/
protected function _processColumn($field)
protected function _processColumn(array $field): string
{
return $this->db->escapeIdentifiers($field['name'])
. ' ' . $field['type'] . $field['length']
Expand All @@ -997,7 +997,7 @@ protected function _processColumn($field)
*
* @return void
*/
protected function _attributeType(&$attributes)
protected function _attributeType(array &$attributes)
{
// Usually overridden by drivers
}
Expand All @@ -1019,9 +1019,9 @@ protected function _attributeType(&$attributes)
* @param array &$attributes
* @param array &$field
*
* @return void
* @return null|void
*/
protected function _attributeUnsigned(&$attributes, &$field)
protected function _attributeUnsigned(array &$attributes, array &$field)
{
if (empty($attributes['UNSIGNED']) || $attributes['UNSIGNED'] !== true)
{
Expand Down Expand Up @@ -1063,9 +1063,9 @@ protected function _attributeUnsigned(&$attributes, &$field)
* @param array &$attributes
* @param array &$field
*
* @return void
* @return null|void
*/
protected function _attributeDefault(&$attributes, &$field)
protected function _attributeDefault(array &$attributes, array &$field)
{
if ($this->default === false)
{
Expand Down Expand Up @@ -1099,7 +1099,7 @@ protected function _attributeDefault(&$attributes, &$field)
*
* @return void
*/
protected function _attributeUnique(&$attributes, &$field)
protected function _attributeUnique(array &$attributes, array &$field)
{
if (! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === true)
{
Expand All @@ -1117,7 +1117,7 @@ protected function _attributeUnique(&$attributes, &$field)
*
* @return void
*/
protected function _attributeAutoIncrement(&$attributes, &$field)
protected function _attributeAutoIncrement(array &$attributes, array &$field)
{
if (! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === true
&& stripos($field['type'], 'int') !== false
Expand All @@ -1136,7 +1136,7 @@ protected function _attributeAutoIncrement(&$attributes, &$field)
*
* @return string
*/
protected function _processPrimaryKeys($table)
protected function _processPrimaryKeys(string $table): string
{
$sql = '';

Expand Down Expand Up @@ -1166,7 +1166,7 @@ protected function _processPrimaryKeys($table)
*
* @return array
*/
protected function _processIndexes($table)
protected function _processIndexes(string $table)
{
$sqls = [];

Expand Down Expand Up @@ -1211,7 +1211,7 @@ protected function _processIndexes($table)
*
* @return string
*/
protected function _processForeignKeys($table)
protected function _processForeignKeys(string $table): string
{
$sql = '';

Expand Down
10 changes: 5 additions & 5 deletions system/Database/MySQLi/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Forge extends \CodeIgniter\Database\Forge
* @param array $attributes Associative array of table attributes
* @return string
*/
protected function _createTableAttributes($attributes)
protected function _createTableAttributes(array $attributes): string
{
$sql = '';

Expand Down Expand Up @@ -162,7 +162,7 @@ protected function _createTableAttributes($attributes)
* @param mixed $field Column definition
* @return string|string[]
*/
protected function _alterTable($alter_type, $table, $field)
protected function _alterTable(string $alter_type, string $table, $field)
{
if ($alter_type === 'DROP')
{
Expand Down Expand Up @@ -202,7 +202,7 @@ protected function _alterTable($alter_type, $table, $field)
* @param array $field
* @return string
*/
protected function _processColumn($field)
protected function _processColumn(array $field): string
{
$extra_clause = isset($field['after']) ? ' AFTER ' . $this->db->escapeIdentifiers($field['after']) : '';

Expand Down Expand Up @@ -231,7 +231,7 @@ protected function _processColumn($field)
* @param string $table (ignored)
* @return string
*/
protected function _processIndexes($table)
protected function _processIndexes(string $table): string
{
$sql = '';

Expand Down Expand Up @@ -259,7 +259,7 @@ protected function _processIndexes($table)
$unique = in_array($i, $this->uniqueKeys) ? 'UNIQUE ' : '';

$sql .= ",\n\t{$unique}KEY " . $this->db->escapeIdentifiers(implode('_', $this->keys[$i]))
. ' (' . implode(', ', $this->db->escapeIdentifiers($this->keys[$i])) . ')';
. ' (' . implode(', ', $this->db->escapeIdentifiers($this->keys[$i])) . ')';
}

$this->keys = [];
Expand Down
19 changes: 10 additions & 9 deletions system/Database/Postgre/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Forge extends \CodeIgniter\Database\Forge
* @param array $attributes Associative array of table attributes
* @return string
*/
protected function _createTableAttributes($attributes)
protected function _createTableAttributes(array $attributes): string
{
return '';
}
Expand All @@ -99,7 +99,7 @@ protected function _createTableAttributes($attributes)
*
* @return string|array
*/
protected function _alterTable($alter_type, $table, $field)
protected function _alterTable(string $alter_type, string $table, $field)
{
if (in_array($alter_type, ['DROP', 'ADD'], true))
{
Expand Down Expand Up @@ -158,7 +158,7 @@ protected function _alterTable($alter_type, $table, $field)
* @param array $field
* @return string
*/
protected function _processColumn($field)
protected function _processColumn(array $field): string
{
return $this->db->escapeIdentifiers($field['name'])
. ' ' . $field['type'] . $field['length']
Expand All @@ -179,7 +179,7 @@ protected function _processColumn($field)
*
* @return void
*/
protected function _attributeType(&$attributes)
protected function _attributeType(array &$attributes)
{
// Reset field lengths for data types that don't support it
if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== false)
Expand All @@ -192,15 +192,16 @@ protected function _attributeType(&$attributes)
case 'TINYINT':
$attributes['TYPE'] = 'SMALLINT';
$attributes['UNSIGNED'] = false;
return;
break;
case 'MEDIUMINT':
$attributes['TYPE'] = 'INTEGER';
$attributes['UNSIGNED'] = false;
return;
break;
case 'DATETIME':
$attributes['TYPE'] = 'TIMESTAMP';
break;
default:
return;
break;
}
}

Expand All @@ -214,7 +215,7 @@ protected function _attributeType(&$attributes)
*
* @return void
*/
protected function _attributeAutoIncrement(&$attributes, &$field)
protected function _attributeAutoIncrement(array &$attributes, array &$field)
{
if (! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === true)
{
Expand All @@ -235,7 +236,7 @@ protected function _attributeAutoIncrement(&$attributes, &$field)
*
* @return string
*/
protected function _dropTable($table, $if_exists, $cascade)
protected function _dropTable(string $table, bool $if_exists, bool $cascade): string
{
$sql = parent::_dropTable($table, $if_exists, $cascade);

Expand Down
Loading