diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php index 2384ac515d8d..d62bca882fd6 100644 --- a/system/Database/BaseBuilder.php +++ b/system/Database/BaseBuilder.php @@ -1251,7 +1251,7 @@ public function orderBy(string $orderBy, string $direction = '', bool $escape = if ($escape === false) { - $qb_orderby[] = [ + $qb_orderBy[] = [ 'field' => $orderBy, 'direction' => $direction, 'escape' => false, @@ -1259,10 +1259,10 @@ public function orderBy(string $orderBy, string $direction = '', bool $escape = } else { - $qb_orderby = []; + $qb_orderBy = []; foreach (explode(',', $orderBy) as $field) { - $qb_orderby[] = ($direction === '' && preg_match('/\s+(ASC|DESC)$/i', rtrim($field), $match, PREG_OFFSET_CAPTURE)) + $qb_orderBy[] = ($direction === '' && preg_match('/\s+(ASC|DESC)$/i', rtrim($field), $match, PREG_OFFSET_CAPTURE)) ? [ 'field' => ltrim(substr($field, 0, $match[0][1])), @@ -1278,7 +1278,7 @@ public function orderBy(string $orderBy, string $direction = '', bool $escape = } } - $this->QBOrderBy = array_merge($this->QBOrderBy, $qb_orderby); + $this->QBOrderBy = array_merge($this->QBOrderBy, $qb_orderBy); return $this; } diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index 7e163304a252..c278568f1e33 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -422,12 +422,14 @@ public function initialize() * @param boolean $persistent * @return mixed */ - abstract public function connect($persistent = false); + abstract public function connect(bool $persistent = false); //-------------------------------------------------------------------- /** * Close the database connection. + * + * @return void */ public function close() { @@ -526,9 +528,9 @@ public function getError() /** * The name of the platform in use (MySQLi, mssql, etc) * - * @return mixed + * @return string */ - public function getPlatform() + public function getPlatform(): string { return $this->DBDriver; } @@ -538,9 +540,9 @@ public function getPlatform() /** * Returns a string containing the version of the database being used. * - * @return mixed + * @return string */ - abstract public function getVersion(); + abstract public function getVersion(): string; //-------------------------------------------------------------------- @@ -586,7 +588,7 @@ public function addTableAlias(string $table) * * @return mixed */ - abstract protected function execute($sql); + abstract protected function execute(string $sql); //-------------------------------------------------------------------- @@ -599,13 +601,13 @@ abstract protected function execute($sql); * queries if needed. * * @param string $sql - * @param array ...$binds + * @param mixed ...$binds * @param boolean $setEscapeFlags * @param string $queryClass * * @return BaseResult|Query|false */ - public function query(string $sql, $binds = null, bool $setEscapeFlags = true, $queryClass = 'CodeIgniter\\Database\\Query') + public function query(string $sql, $binds = null, bool $setEscapeFlags = true, string $queryClass = 'CodeIgniter\\Database\\Query') { if (empty($this->connID)) { @@ -713,6 +715,8 @@ public function simpleQuery(string $sql) * Disable Transactions * * This permits transactions to be disabled at run-time. + * + * @return void */ public function transOff() { @@ -750,7 +754,7 @@ public function transStrict(bool $mode = true) * @param boolean $test_mode = FALSE * @return boolean */ - public function transStart($test_mode = false) + public function transStart(bool $test_mode = false): bool { if (! $this->transEnabled) { @@ -767,7 +771,7 @@ public function transStart($test_mode = false) * * @return boolean */ - public function transComplete() + public function transComplete(): bool { if (! $this->transEnabled) { @@ -924,7 +928,7 @@ abstract protected function _transRollback(): bool; /** * Returns an instance of the query builder for this connection. * - * @param string $tableName + * @param string|array $tableName * * @return BaseBuilder * @throws DatabaseException @@ -1008,7 +1012,7 @@ public function getLastQuery() * * @return string */ - public function showLastQuery() + public function showLastQuery(): string { return (string) $this->lastQuery; } @@ -1023,7 +1027,7 @@ public function showLastQuery() * * @return float */ - public function getConnectStart() + public function getConnectStart(): float { return $this->connectTime; } @@ -1038,9 +1042,9 @@ public function getConnectStart() * * @param integer $decimals * - * @return mixed + * @return string */ - public function getConnectDuration($decimals = 6) + public function getConnectDuration(int $decimals = 6): string { return number_format($this->connectDuration, $decimals); } @@ -1067,14 +1071,14 @@ public function getConnectDuration($decimals = 6) * insert the table prefix (if it exists) in the proper position, and escape only * the correct identifiers. * - * @param string|array - * @param boolean - * @param mixed - * @param boolean + * @param string|array $item + * @param boolean $prefixSingle + * @param boolean $protectIdentifiers + * @param boolean $fieldExists * * @return string|array */ - public function protectIdentifiers($item, $prefixSingle = false, $protectIdentifiers = null, $fieldExists = true) + public function protectIdentifiers($item, bool $prefixSingle = false, bool $protectIdentifiers = null, bool $fieldExists = true) { if (! is_bool($protectIdentifiers)) { @@ -1313,7 +1317,7 @@ public function escapeIdentifiers($item) * @return string * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ - public function prefixTable($table = '') + public function prefixTable(string $table = ''): string { if ($table === '') { @@ -1334,7 +1338,7 @@ public function prefixTable($table = '') * * @return string */ - public function setPrefix($prefix = '') + public function setPrefix(string $prefix = ''): string { return $this->DBPrefix = $prefix; } @@ -1356,7 +1360,7 @@ abstract public function affectedRows(): int; * Escapes data based on type. * Sets boolean and null types * - * @param $str + * @param mixed $str * * @return mixed */ @@ -1395,9 +1399,9 @@ public function escape($str) * * @param string|string[] $str Input string * @param boolean $like Whether or not the string will be used in a LIKE condition - * @return string + * @return string|string[] */ - public function escapeString($str, $like = false) + public function escapeString($str, bool $like = false) { if (is_array($str)) { @@ -1473,7 +1477,7 @@ protected function _escapeString(string $str): string * @return boolean * @throws DatabaseException */ - public function callFunction(string $functionName, ...$params) + public function callFunction(string $functionName, ...$params): bool { $driver = ($this->DBDriver === 'postgre' ? 'pg' : strtolower($this->DBDriver)) . '_'; @@ -1507,7 +1511,7 @@ public function callFunction(string $functionName, ...$params) * @return boolean|array * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ - public function listTables($constrain_by_prefix = false) + public function listTables(bool $constrain_by_prefix = false) { // Is there a cached result? if (isset($this->dataCache['table_names']) && $this->dataCache['table_names']) @@ -1566,7 +1570,7 @@ public function listTables($constrain_by_prefix = false) * @param string $table_name * @return boolean */ - public function tableExists($table_name) + public function tableExists(string $table_name): bool { return in_array($this->protectIdentifiers($table_name, true, false, false), $this->listTables()); } @@ -1581,7 +1585,7 @@ public function tableExists($table_name) * @return array|false * @throws DatabaseException */ - public function getFieldNames($table) + public function getFieldNames(string $table) { // Is there a cached result? if (isset($this->dataCache['field_names'][$table])) @@ -1637,11 +1641,11 @@ public function getFieldNames($table) /** * Determine if a particular field exists * - * @param string - * @param string + * @param string $fieldName + * @param string $tableName * @return boolean */ - public function fieldExists($fieldName, $tableName) + public function fieldExists(string $fieldName, string $tableName): bool { return in_array($fieldName, $this->getFieldNames($tableName)); } @@ -1735,7 +1739,7 @@ public function resetDataCache() * * @return array */ - abstract public function error(); + abstract public function error(): array; //-------------------------------------------------------------------- @@ -1744,7 +1748,7 @@ abstract public function error(); * * @return integer */ - abstract public function insertID(); + abstract public function insertID(): int; //-------------------------------------------------------------------- @@ -1755,7 +1759,7 @@ abstract public function insertID(); * * @return string */ - abstract protected function _listTables($constrainByPrefix = false): string; + abstract protected function _listTables(bool $constrainByPrefix = false): string; //-------------------------------------------------------------------- @@ -1803,12 +1807,19 @@ abstract protected function _foreignKeyData(string $table): array; //-------------------------------------------------------------------- - public function __get($key) + /** + * @param string $key + * + * @return mixed + */ + public function __get(string $key) { if (property_exists($this, $key)) { return $this->$key; } + + return null; } //-------------------------------------------------------------------- diff --git a/system/Database/BasePreparedQuery.php b/system/Database/BasePreparedQuery.php index 887f906e5b46..a4287c2d25b9 100644 --- a/system/Database/BasePreparedQuery.php +++ b/system/Database/BasePreparedQuery.php @@ -37,6 +37,7 @@ namespace CodeIgniter\Database; +use CodeIgniter\Database\MySQLi\Connection; use CodeIgniter\Events\Events; /** @@ -85,7 +86,7 @@ abstract class BasePreparedQuery implements PreparedQueryInterface public function __construct(ConnectionInterface $db) { - $this->db = & $db; + $this->db = &$db; } //-------------------------------------------------------------------- @@ -103,7 +104,7 @@ public function __construct(ConnectionInterface $db) * * @return mixed */ - public function prepare(string $sql, array $options = [], $queryClass = 'CodeIgniter\\Database\\Query') + public function prepare(string $sql, array $options = [], string $queryClass = 'CodeIgniter\\Database\\Query') { // We only supports positional placeholders (?) // in order to work with the execute method below, so we @@ -180,9 +181,9 @@ public function execute(...$data) * * @param array $data * - * @return ResultInterface + * @return boolean */ - abstract public function _execute($data); + abstract public function _execute(array $data): bool; //-------------------------------------------------------------------- @@ -196,7 +197,9 @@ abstract public function _getResult(); //-------------------------------------------------------------------- /** - * Explicity closes the statement. + * Explicitly closes the statement. + * + * @return null|void */ public function close() { @@ -232,7 +235,7 @@ public function getQueryString(): string * * @return boolean */ - public function hasError() + public function hasError(): bool { return ! empty($this->errorString); } diff --git a/system/Database/BaseResult.php b/system/Database/BaseResult.php index ca7f11bb788f..5b2267d14b05 100644 --- a/system/Database/BaseResult.php +++ b/system/Database/BaseResult.php @@ -123,9 +123,9 @@ public function __construct(&$connID, &$resultID) * * @param string $type The row type. Either 'array', 'object', or a class name to use * - * @return mixed + * @return array */ - public function getResult($type = 'object'): array + public function getResult(string $type = 'object'): array { if ($type === 'array') { @@ -291,12 +291,12 @@ public function getResultObject(): array * * If row doesn't exist, returns null. * - * @param integer $n The index of the results to return + * @param mixed $n The index of the results to return * @param string $type The type of result object. 'array', 'object' or class name. * * @return mixed */ - public function getRow($n = 0, $type = 'object') + public function getRow($n = 0, string $type = 'object') { if (! is_numeric($n)) { @@ -336,7 +336,7 @@ public function getRow($n = 0, $type = 'object') * * @return mixed */ - public function getCustomRowObject($n, string $className) + public function getCustomRowObject(int $n, string $className) { isset($this->customResultObject[$className]) || $this->getCustomResultObject($className); @@ -364,7 +364,7 @@ public function getCustomRowObject($n, string $className) * * @return mixed */ - public function getRowArray($n = 0) + public function getRowArray(int $n = 0) { $result = $this->getResultArray(); if (empty($result)) @@ -391,7 +391,7 @@ public function getRowArray($n = 0) * * @return mixed */ - public function getRowObject($n = 0) + public function getRowObject(int $n = 0) { $result = $this->getResultObject(); if (empty($result)) @@ -412,8 +412,8 @@ public function getRowObject($n = 0) /** * Assigns an item into a particular column slot. * - * @param $key - * @param null $value + * @param mixed $key + * @param mixed $value * * @return mixed */ @@ -450,7 +450,7 @@ public function setRow($key, $value = null) * * @return mixed */ - public function getFirstRow($type = 'object') + public function getFirstRow(string $type = 'object') { $result = $this->getResult($type); @@ -466,7 +466,7 @@ public function getFirstRow($type = 'object') * * @return mixed */ - public function getLastRow($type = 'object') + public function getLastRow(string $type = 'object') { $result = $this->getResult($type); @@ -482,7 +482,7 @@ public function getLastRow($type = 'object') * * @return mixed */ - public function getNextRow($type = 'object') + public function getNextRow(string $type = 'object') { $result = $this->getResult($type); if (empty($result)) @@ -502,7 +502,7 @@ public function getNextRow($type = 'object') * * @return mixed */ - public function getPreviousRow($type = 'object') + public function getPreviousRow(string $type = 'object') { $result = $this->getResult($type); if (empty($result)) @@ -527,7 +527,7 @@ public function getPreviousRow($type = 'object') * * @return mixed */ - public function getUnbufferedRow($type = 'object') + public function getUnbufferedRow(string $type = 'object') { if ($type === 'array') { @@ -573,7 +573,7 @@ abstract public function getFieldData(): array; /** * Frees the current result. * - * @return mixed + * @return void */ abstract public function freeResult(); @@ -588,7 +588,7 @@ abstract public function freeResult(); * * @return mixed */ - abstract public function dataSeek($n = 0); + abstract public function dataSeek(int $n = 0); //-------------------------------------------------------------------- @@ -597,7 +597,7 @@ abstract public function dataSeek($n = 0); * * Overridden by driver classes. * - * @return array + * @return mixed */ abstract protected function fetchAssoc(); @@ -612,7 +612,7 @@ abstract protected function fetchAssoc(); * * @return object */ - abstract protected function fetchObject($className = 'stdClass'); + abstract protected function fetchObject(string $className = 'stdClass'); //-------------------------------------------------------------------- } diff --git a/system/Database/BaseUtils.php b/system/Database/BaseUtils.php index 096d1a1a5034..ce6f3bc1bedf 100644 --- a/system/Database/BaseUtils.php +++ b/system/Database/BaseUtils.php @@ -136,7 +136,7 @@ public function listDatabases() * @param string $database_name * @return boolean */ - public function databaseExists($database_name) + public function databaseExists(string $database_name): bool { return in_array($database_name, $this->listDatabases()); } @@ -147,10 +147,10 @@ public function databaseExists($database_name) * Optimize Table * * @param string $table_name - * @return boolean|mixed + * @return mixed * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ - public function optimizeTable($table_name) + public function optimizeTable(string $table_name) { if ($this->optimizeTable === false) { @@ -231,7 +231,7 @@ public function optimizeDatabase() * @return mixed * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ - public function repairTable($table_name) + public function repairTable(string $table_name) { if ($this->repairTable === false) { @@ -264,7 +264,7 @@ public function repairTable($table_name) * * @return string */ - public function getCSVFromResult(ResultInterface $query, $delim = ',', $newline = "\n", $enclosure = '"') + public function getCSVFromResult(ResultInterface $query, string $delim = ',', string $newline = "\n", string $enclosure = '"') { $out = ''; // First generate the headings from the table column names @@ -299,7 +299,7 @@ public function getCSVFromResult(ResultInterface $query, $delim = ',', $newline * * @return string */ - public function getXMLFromResult(ResultInterface $query, $params = []) + public function getXMLFromResult(ResultInterface $query, array $params = []): string { // Set our default values foreach (['root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t"] as $key => $val) @@ -336,7 +336,7 @@ public function getXMLFromResult(ResultInterface $query, $params = []) /** * Database Backup * - * @param array $params + * @param array|string $params * @return mixed * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ @@ -390,7 +390,7 @@ public function backup($params = []) // Is the encoder supported? If not, we'll either issue an // error or use plain text depending on the debug settings if (($prefs['format'] === 'gzip' && ! function_exists('gzencode')) - || ( $prefs['format'] === 'zip' && ! function_exists('gzcompress'))) + || ( $prefs['format'] === 'zip' && ! function_exists('gzcompress'))) { if ($this->db->DBDebug) { @@ -407,7 +407,7 @@ public function backup($params = []) if ($prefs['filename'] === '') { $prefs['filename'] = (count($prefs['tables']) === 1 ? $prefs['tables'] : $this->db->database) - . date('Y-m-d_H-i', time()) . '.sql'; + . date('Y-m-d_H-i', time()) . '.sql'; } else { diff --git a/system/Database/Config.php b/system/Database/Config.php index f94c663ed7af..acd7f9ffb047 100644 --- a/system/Database/Config.php +++ b/system/Database/Config.php @@ -125,7 +125,7 @@ public static function connect($group = null, bool $getShared = true) * * @return array */ - public static function getConnections() + public static function getConnections(): array { return static::$instances; } @@ -186,12 +186,12 @@ public static function seeder(string $group = null) */ protected static function ensureFactory() { - if (static::$factory instanceof \CodeIgniter\Database\Database) + if (static::$factory instanceof Database) { return; } - static::$factory = new \CodeIgniter\Database\Database(); + static::$factory = new Database(); } //-------------------------------------------------------------------- diff --git a/system/Database/ConnectionInterface.php b/system/Database/ConnectionInterface.php index 76f8a64c3ac4..a4a9a2745046 100644 --- a/system/Database/ConnectionInterface.php +++ b/system/Database/ConnectionInterface.php @@ -61,7 +61,7 @@ public function initialize(); * @param boolean $persistent * @return mixed */ - public function connect($persistent = false); + public function connect(bool $persistent = false); //-------------------------------------------------------------------- @@ -130,18 +130,18 @@ public function getError(); /** * The name of the platform in use (MySQLi, mssql, etc) * - * @return mixed + * @return string */ - public function getPlatform(); + public function getPlatform(): string; //-------------------------------------------------------------------- /** * Returns a string containing the version of the database being used. * - * @return mixed + * @return string */ - public function getVersion(); + public function getVersion(): string; //-------------------------------------------------------------------- @@ -154,7 +154,7 @@ public function getVersion(); * queries if needed. * * @param string $sql - * @param array ...$binds + * @param mixed ...$binds * * @return mixed */ @@ -201,7 +201,7 @@ public function getLastQuery(); * Escapes data based on type. * Sets boolean and null types. * - * @param string $str + * @param mixed $str * * @return mixed */ diff --git a/system/Database/Exceptions/DataException.php b/system/Database/Exceptions/DataException.php index 966c6ef43f6f..2af1793454cc 100644 --- a/system/Database/Exceptions/DataException.php +++ b/system/Database/Exceptions/DataException.php @@ -1,4 +1,6 @@ -DBGroup; } diff --git a/system/Database/MigrationRunner.php b/system/Database/MigrationRunner.php index 810e9a90791c..3a3604f86e5e 100644 --- a/system/Database/MigrationRunner.php +++ b/system/Database/MigrationRunner.php @@ -342,7 +342,7 @@ public function latest(string $namespace = null, string $group = null) * * @return boolean */ - public function latestAll(string $group = null) + public function latestAll(string $group = null): bool { $this->ensureTable(); @@ -387,7 +387,7 @@ public function latestAll(string $group = null) * * @param string|null $group * - * @return mixed TRUE if no migrations are found, current version string on success, FALSE on failure + * @return mixed Current version string on success, FALSE on failure or no migrations are found */ public function current(string $group = null) { @@ -409,7 +409,7 @@ public function current(string $group = null) * * @return array list of migrations as $version for one namespace */ - public function findMigrations() + public function findMigrations(): array { $migrations = []; @@ -471,11 +471,11 @@ public function findMigrations() * * @param array $migrations * @param string $method - * @param string $targetversion + * @param string $targetVersion * * @return boolean */ - protected function checkMigrations(array $migrations, string $method, string $targetversion) + protected function checkMigrations(array $migrations, string $method, string $targetVersion): bool { // Check if no migrations found if (empty($migrations)) @@ -487,14 +487,14 @@ protected function checkMigrations(array $migrations, string $method, string $ta throw new \RuntimeException(lang('Migrations.empty')); } - // Check if $targetversion file is found - if ((int)$targetversion !== 0 && ! array_key_exists($targetversion, $migrations)) + // Check if $targetVersion file is found + if ((int)$targetVersion !== 0 && ! array_key_exists($targetVersion, $migrations)) { if ($this->silent) { return false; } - throw new \RuntimeException(lang('Migrations.notFound') . $targetversion); + throw new \RuntimeException(lang('Migrations.notFound') . $targetVersion); } ksort($migrations); @@ -601,7 +601,7 @@ public function setName(string $name) * * @return array */ - public function getHistory(string $group = 'default') + public function getHistory(string $group = 'default'): array { $this->ensureTable(); @@ -645,7 +645,7 @@ public function setSilent(bool $silent) * * @return string Numeric portion of a migration filename */ - protected function getMigrationNumber(string $migration) + protected function getMigrationNumber(string $migration): string { return sscanf($migration, '%[0-9]+', $number) ? $number : '0'; } @@ -659,7 +659,7 @@ protected function getMigrationNumber(string $migration) * * @return string text portion of a migration filename */ - protected function getMigrationName(string $migration) + protected function getMigrationName(string $migration): string { $parts = explode('_', $migration); array_shift($parts); @@ -674,7 +674,7 @@ protected function getMigrationName(string $migration) * * @return string Current migration version */ - protected function getVersion() + protected function getVersion(): string { $this->ensureTable(); @@ -695,7 +695,7 @@ protected function getVersion() * * @return array Current migration version */ - public function getCliMessages() + public function getCliMessages(): array { return $this->cliMessages; } @@ -708,6 +708,8 @@ public function getCliMessages() * @param string $version * * @internal param string $migration Migration reached + * + * @return void */ protected function addHistory(string $version) { @@ -731,6 +733,7 @@ protected function addHistory(string $version) * Removes a single history * * @param string $version + * @return void */ protected function removeHistory(string $version) { diff --git a/system/Database/MySQLi/Connection.php b/system/Database/MySQLi/Connection.php index 7c6d45c4909d..8d189e620448 100644 --- a/system/Database/MySQLi/Connection.php +++ b/system/Database/MySQLi/Connection.php @@ -89,7 +89,7 @@ class Connection extends BaseConnection implements ConnectionInterface * @return mixed * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ - public function connect($persistent = false) + public function connect(bool $persistent = false) { // Do we have a socket path? if ($this->hostname[0] === '/') @@ -245,6 +245,8 @@ public function reconnect() /** * Close the database connection. + * + * @return void */ protected function _close() { @@ -258,9 +260,9 @@ protected function _close() * * @param string $databaseName * - * @return mixed + * @return boolean */ - public function setDatabase(string $databaseName) + public function setDatabase(string $databaseName): bool { if ($databaseName === '') { @@ -287,9 +289,9 @@ public function setDatabase(string $databaseName) /** * Returns a string containing the version of the database being used. * - * @return mixed + * @return string */ - public function getVersion() + public function getVersion(): string { if (isset($this->dataCache['version'])) { @@ -313,7 +315,7 @@ public function getVersion() * * @return mixed */ - public function execute($sql) + public function execute(string $sql) { while ($this->connID->more_results()) { @@ -338,7 +340,7 @@ public function execute($sql) * * @return string */ - protected function prepQuery($sql) + protected function prepQuery(string $sql): string { // mysqli_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack // modifies the query so that it a proper number of affected rows is returned. @@ -355,7 +357,7 @@ protected function prepQuery($sql) /** * Returns the total number of rows affected by this query. * - * @return mixed + * @return int */ public function affectedRows(): int { @@ -394,7 +396,7 @@ protected function _escapeString(string $str): string * * @return string */ - protected function _listTables($prefixLimit = false): string + protected function _listTables(bool $prefixLimit = false): string { $sql = 'SHOW TABLES FROM ' . $this->escapeIdentifiers($this->database); @@ -439,19 +441,19 @@ public function _fieldData(string $table): array } $query = $query->getResultObject(); - $retval = []; + $retVal = []; for ($i = 0, $c = count($query); $i < $c; $i++) { - $retval[$i] = new \stdClass(); - $retval[$i]->name = $query[$i]->Field; + $retVal[$i] = new \stdClass(); + $retVal[$i]->name = $query[$i]->Field; - sscanf($query[$i]->Type, '%[a-z](%d)', $retval[$i]->type, $retval[$i]->max_length); + sscanf($query[$i]->Type, '%[a-z](%d)', $retVal[$i]->type, $retVal[$i]->max_length); - $retval[$i]->default = $query[$i]->Default; - $retval[$i]->primary_key = (int)($query[$i]->Key === 'PRI'); + $retVal[$i]->default = $query[$i]->Default; + $retVal[$i]->primary_key = (int)($query[$i]->Key === 'PRI'); } - return $retval; + return $retVal; } //-------------------------------------------------------------------- @@ -550,7 +552,7 @@ public function _foreignKeyData(string $table): array } $query = $query->getResultObject(); - $retval = []; + $retVal = []; foreach ($query as $row) { $obj = new \stdClass(); @@ -558,10 +560,10 @@ public function _foreignKeyData(string $table): array $obj->table_name = $row->TABLE_NAME; $obj->foreign_table_name = $row->REFERENCED_TABLE_NAME; - $retval[] = $obj; + $retVal[] = $obj; } - return $retval; + return $retVal; } //-------------------------------------------------------------------- @@ -575,7 +577,7 @@ public function _foreignKeyData(string $table): array * * @return array */ - public function error() + public function error(): array { if (! empty($this->mysqli->connect_errno)) { @@ -598,7 +600,7 @@ public function error() * * @return integer */ - public function insertID() + public function insertID(): int { return $this->connID->insert_id; } diff --git a/system/Database/MySQLi/PreparedQuery.php b/system/Database/MySQLi/PreparedQuery.php index 668df92ecfa3..89a339c2d2e9 100644 --- a/system/Database/MySQLi/PreparedQuery.php +++ b/system/Database/MySQLi/PreparedQuery.php @@ -80,9 +80,9 @@ public function _prepare(string $sql, array $options = []) * * @param array $data * - * @return \CodeIgniter\Database\ResultInterface + * @return bool */ - public function _execute($data) + public function _execute(array $data): bool { if (is_null($this->statement)) { diff --git a/system/Database/MySQLi/Result.php b/system/Database/MySQLi/Result.php index 2906324e0927..5d66f86ec0e8 100644 --- a/system/Database/MySQLi/Result.php +++ b/system/Database/MySQLi/Result.php @@ -85,26 +85,28 @@ public function getFieldNames(): array */ public function getFieldData(): array { - $retval = []; + $retVal = []; $fieldData = $this->resultID->fetch_fields(); foreach ($fieldData as $i => $data) { - $retval[$i] = new \stdClass(); - $retval[$i]->name = $data->name; - $retval[$i]->type = $data->type; - $retval[$i]->max_length = $data->max_length; - $retval[$i]->primary_key = (int) ($data->flags & 2); - $retval[$i]->default = $data->def; + $retVal[$i] = new \stdClass(); + $retVal[$i]->name = $data->name; + $retVal[$i]->type = $data->type; + $retVal[$i]->max_length = $data->max_length; + $retVal[$i]->primary_key = (int) ($data->flags & 2); + $retVal[$i]->default = $data->def; } - return $retval; + return $retVal; } //-------------------------------------------------------------------- /** * Frees the current result. + * + * @return void */ public function freeResult() { @@ -126,7 +128,7 @@ public function freeResult() * * @return mixed */ - public function dataSeek($n = 0) + public function dataSeek(int $n = 0) { return $this->resultID->data_seek($n); } @@ -138,7 +140,7 @@ public function dataSeek($n = 0) * * Overridden by driver classes. * - * @return array + * @return mixed */ protected function fetchAssoc() { @@ -156,7 +158,7 @@ protected function fetchAssoc() * * @return object */ - protected function fetchObject($className = 'stdClass') + protected function fetchObject(string $className = 'stdClass') { return $this->resultID->fetch_object($className); } diff --git a/system/Database/MySQLi/Utils.php b/system/Database/MySQLi/Utils.php index 25d4036e4e4d..2a6565c602ff 100644 --- a/system/Database/MySQLi/Utils.php +++ b/system/Database/MySQLi/Utils.php @@ -38,12 +38,13 @@ namespace CodeIgniter\Database\MySQLi; +use CodeIgniter\Database\BaseUtils; use CodeIgniter\Database\Exceptions\DatabaseException; /** * Utils for MySQLi */ -class Utils extends \CodeIgniter\Database\BaseUtils +class Utils extends BaseUtils { /** diff --git a/system/Database/Postgre/Builder.php b/system/Database/Postgre/Builder.php index 7ab065aa9992..df9104305c1f 100644 --- a/system/Database/Postgre/Builder.php +++ b/system/Database/Postgre/Builder.php @@ -53,7 +53,6 @@ class Builder extends BaseBuilder */ protected $randomKeyword = [ 'RANDOM()', - 'RANDOM()', ]; //-------------------------------------------------------------------- @@ -98,7 +97,7 @@ public function orderBy(string $orderBy, string $direction = '', bool $escape = * @param string $column * @param integer $value * - * @return boolean + * @return mixed */ public function increment(string $column, int $value = 1) { @@ -117,7 +116,7 @@ public function increment(string $column, int $value = 1) * @param string $column * @param integer $value * - * @return boolean + * @return mixed */ public function decrement(string $column, int $value = 1) { @@ -141,7 +140,7 @@ public function decrement(string $column, int $value = 1) * @param array $set An associative array of insert values * @param boolean $returnSQL * - * @return boolean TRUE on success, FALSE on failure + * @return mixed * @throws DatabaseException * @internal param true $bool returns the generated SQL, false executes the query. */ diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index 56aec4f905e0..eda14acc5dea 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -78,7 +78,7 @@ class Connection extends BaseConnection implements ConnectionInterface * @param boolean $persistent * @return mixed */ - public function connect($persistent = false) + public function connect(bool $persistent = false) { if (empty($this->DSN)) { @@ -121,7 +121,7 @@ public function connect($persistent = false) * Keep or establish the connection if no queries have been sent for * a length of time exceeding the server's idle timeout. * - * @return mixed + * @return void */ public function reconnect() { @@ -135,6 +135,8 @@ public function reconnect() /** * Close the database connection. + * + * @return void */ protected function _close() { @@ -148,9 +150,9 @@ protected function _close() * * @param string $databaseName * - * @return mixed + * @return boolean */ - public function setDatabase(string $databaseName) + public function setDatabase(string $databaseName): bool { return false; } @@ -160,9 +162,9 @@ public function setDatabase(string $databaseName) /** * Returns a string containing the version of the database being used. * - * @return mixed + * @return string */ - public function getVersion() + public function getVersion(): string { if (isset($this->dataCache['version'])) { @@ -186,7 +188,7 @@ public function getVersion() * * @return resource */ - public function execute($sql) + public function execute(string $sql) { return pg_query($this->connID, $sql); } @@ -196,7 +198,7 @@ public function execute($sql) /** * Returns the total number of rows affected by this query. * - * @return mixed + * @return int */ public function affectedRows(): int { @@ -210,7 +212,7 @@ public function affectedRows(): int * * Escapes data based on type * - * @param string $str + * @param mixed $str * @return mixed */ public function escape($str) @@ -259,7 +261,7 @@ protected function _escapeString(string $str): string * * @return string */ - protected function _listTables($prefixLimit = false): string + protected function _listTables(bool $prefixLimit = false): string { $sql = 'SELECT "table_name" FROM "information_schema"."tables" WHERE "table_schema" = \'' . $this->schema . "'"; @@ -312,17 +314,17 @@ public function _fieldData(string $table): array } $query = $query->getResultObject(); - $retval = []; + $retVal = []; for ($i = 0, $c = count($query); $i < $c; $i ++) { - $retval[$i] = new \stdClass(); - $retval[$i]->name = $query[$i]->column_name; - $retval[$i]->type = $query[$i]->data_type; - $retval[$i]->default = $query[$i]->column_default; - $retval[$i]->max_length = $query[$i]->character_maximum_length > 0 ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision; + $retVal[$i] = new \stdClass(); + $retVal[$i]->name = $query[$i]->column_name; + $retVal[$i]->type = $query[$i]->data_type; + $retVal[$i]->default = $query[$i]->column_default; + $retVal[$i]->max_length = $query[$i]->character_maximum_length > 0 ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision; } - return $retval; + return $retVal; } //-------------------------------------------------------------------- @@ -347,7 +349,7 @@ public function _indexData(string $table): array } $query = $query->getResultObject(); - $retval = []; + $retVal = []; foreach ($query as $row) { $obj = new \stdClass(); @@ -366,10 +368,10 @@ public function _indexData(string $table): array $obj->type = (strpos($row->indexdef, 'CREATE UNIQUE') === 0) ? 'UNIQUE' : 'INDEX'; } - $retval[$obj->name] = $obj; + $retVal[$obj->name] = $obj; } - return $retval; + return $retVal; } //-------------------------------------------------------------------- @@ -401,17 +403,17 @@ public function _foreignKeyData(string $table): array } $query = $query->getResultObject(); - $retval = []; + $retVal = []; foreach ($query as $row) { $obj = new \stdClass(); $obj->constraint_name = $row->constraint_name; $obj->table_name = $row->table_name; $obj->foreign_table_name = $row->foreign_table_name; - $retval[] = $obj; + $retVal[] = $obj; } - return $retval; + return $retVal; } //-------------------------------------------------------------------- @@ -425,7 +427,7 @@ public function _foreignKeyData(string $table): array * * @return array */ - public function error() + public function error(): array { return [ 'code' => '', @@ -440,7 +442,7 @@ public function error() * * @return integer */ - public function insertID() + public function insertID(): int { $v = pg_version($this->connID); // 'server' key is only available since PostgreSQL 7.4 @@ -540,7 +542,7 @@ protected function buildDSN() * @param string $charset The client encoding to which the data will be converted. * @return boolean */ - protected function setClientEncoding($charset) + protected function setClientEncoding(string $charset): bool { return pg_set_client_encoding($this->connID, $charset) === 0; } diff --git a/system/Database/Postgre/PreparedQuery.php b/system/Database/Postgre/PreparedQuery.php index fdd0aa4a07fd..6275ef96d844 100644 --- a/system/Database/Postgre/PreparedQuery.php +++ b/system/Database/Postgre/PreparedQuery.php @@ -74,6 +74,7 @@ class PreparedQuery extends BasePreparedQuery implements PreparedQueryInterface * Unused in the MySQLi driver. * * @return mixed + * @throws \Exception */ public function _prepare(string $sql, array $options = []) { @@ -104,7 +105,7 @@ public function _prepare(string $sql, array $options = []) * * @return boolean */ - public function _execute($data) + public function _execute(array $data): bool { if (is_null($this->statement)) { diff --git a/system/Database/Postgre/Result.php b/system/Database/Postgre/Result.php index af4af6682ad3..a6bde2419941 100644 --- a/system/Database/Postgre/Result.php +++ b/system/Database/Postgre/Result.php @@ -84,19 +84,19 @@ public function getFieldNames(): array */ public function getFieldData(): array { - $retval = []; + $retVal = []; for ($i = 0, $c = $this->getFieldCount(); $i < $c; $i ++) { - $retval[$i] = new \stdClass(); - $retval[$i]->name = pg_field_name($this->resultID, $i); - $retval[$i]->type = pg_field_type($this->resultID, $i); - $retval[$i]->max_length = pg_field_size($this->resultID, $i); - // $retval[$i]->primary_key = (int)($fieldData[$i]->flags & 2); - // $retval[$i]->default = $fieldData[$i]->def; + $retVal[$i] = new \stdClass(); + $retVal[$i]->name = pg_field_name($this->resultID, $i); + $retVal[$i]->type = pg_field_type($this->resultID, $i); + $retVal[$i]->max_length = pg_field_size($this->resultID, $i); + // $retVal[$i]->primary_key = (int)($fieldData[$i]->flags & 2); + // $retVal[$i]->default = $fieldData[$i]->def; } - return $retval; + return $retVal; } //-------------------------------------------------------------------- @@ -104,7 +104,7 @@ public function getFieldData(): array /** * Frees the current result. * - * @return mixed + * @return void */ public function freeResult() { @@ -126,7 +126,7 @@ public function freeResult() * * @return mixed */ - public function dataSeek($n = 0) + public function dataSeek(int $n = 0) { return pg_result_seek($this->resultID, $n); } @@ -138,7 +138,7 @@ public function dataSeek($n = 0) * * Overridden by driver classes. * - * @return array + * @return mixed */ protected function fetchAssoc() { @@ -156,7 +156,7 @@ protected function fetchAssoc() * * @return object */ - protected function fetchObject($className = 'stdClass') + protected function fetchObject(string $className = 'stdClass') { return pg_fetch_object($this->resultID, null, $className); } diff --git a/system/Database/Postgre/Utils.php b/system/Database/Postgre/Utils.php index 41143e7ecea6..846307c8a422 100644 --- a/system/Database/Postgre/Utils.php +++ b/system/Database/Postgre/Utils.php @@ -37,12 +37,13 @@ namespace CodeIgniter\Database\Postgre; +use CodeIgniter\Database\BaseUtils; use CodeIgniter\Database\Exceptions\DatabaseException; /** * Utils for Postgre */ -class Utils extends \CodeIgniter\Database\BaseUtils +class Utils extends BaseUtils { /** diff --git a/system/Database/QueryInterface.php b/system/Database/QueryInterface.php index 7f5cfb12879d..62450833a308 100644 --- a/system/Database/QueryInterface.php +++ b/system/Database/QueryInterface.php @@ -52,12 +52,13 @@ interface QueryInterface /** * Sets the raw query string to use for this statement. * - * @param string $sql - * @param array $binds + * @param string $sql + * @param mixed $binds + * @param boolean $setEscape * * @return mixed */ - public function setQuery(string $sql, $binds = null); + public function setQuery(string $sql, $binds = null, bool $setEscape = true); //-------------------------------------------------------------------- @@ -91,9 +92,9 @@ public function setDuration(float $start, float $end = null); * * @param integer $decimals The accuracy of the returned time. * - * @return mixed + * @return string */ - public function getDuration(int $decimals = 6); + public function getDuration(int $decimals = 6): string; //-------------------------------------------------------------------- diff --git a/system/Database/ResultInterface.php b/system/Database/ResultInterface.php index af217864fbe1..3fffd4265c1d 100644 --- a/system/Database/ResultInterface.php +++ b/system/Database/ResultInterface.php @@ -53,7 +53,7 @@ interface ResultInterface * * @return mixed */ - public function getResult($type = 'object'): array; + public function getResult(string $type = 'object'): array; //-------------------------------------------------------------------- @@ -96,12 +96,12 @@ public function getResultObject(): array; * * If row doesn't exist, returns null. * - * @param integer $n The index of the results to return + * @param mixed $n The index of the results to return * @param string $type The type of result object. 'array', 'object' or class name. * * @return mixed */ - public function getRow($n = 0, $type = 'object'); + public function getRow($n = 0, string $type = 'object'); //-------------------------------------------------------------------- @@ -115,7 +115,7 @@ public function getRow($n = 0, $type = 'object'); * * @return mixed */ - public function getCustomRowObject($n, string $className); + public function getCustomRowObject(int $n, string $className); //-------------------------------------------------------------------- @@ -128,7 +128,7 @@ public function getCustomRowObject($n, string $className); * * @return mixed */ - public function getRowArray($n = 0); + public function getRowArray(int $n = 0); //-------------------------------------------------------------------- @@ -141,7 +141,7 @@ public function getRowArray($n = 0); * * @return mixed */ - public function getRowObject($n = 0); + public function getRowObject(int $n = 0); //-------------------------------------------------------------------- @@ -164,7 +164,7 @@ public function setRow($key, $value = null); * * @return mixed */ - public function getFirstRow($type = 'object'); + public function getFirstRow(string $type = 'object'); //-------------------------------------------------------------------- @@ -175,7 +175,7 @@ public function getFirstRow($type = 'object'); * * @return mixed */ - public function getLastRow($type = 'object'); + public function getLastRow(string $type = 'object'); //-------------------------------------------------------------------- @@ -186,7 +186,7 @@ public function getLastRow($type = 'object'); * * @return mixed */ - public function getNextRow($type = 'object'); + public function getNextRow(string $type = 'object'); //-------------------------------------------------------------------- @@ -197,7 +197,7 @@ public function getNextRow($type = 'object'); * * @return mixed */ - public function getPreviousRow($type = 'object'); + public function getPreviousRow(string $type = 'object'); //-------------------------------------------------------------------- @@ -208,7 +208,7 @@ public function getPreviousRow($type = 'object'); * * @return mixed */ - public function getUnbufferedRow($type = 'object'); + public function getUnbufferedRow(string $type = 'object'); //-------------------------------------------------------------------- @@ -242,7 +242,7 @@ public function getFieldData(): array; /** * Frees the current result. * - * @return mixed + * @return void */ public function freeResult(); @@ -257,7 +257,7 @@ public function freeResult(); * * @return mixed */ - public function dataSeek($n = 0); + public function dataSeek(int $n = 0); //-------------------------------------------------------------------- } diff --git a/system/Database/SQLite3/Connection.php b/system/Database/SQLite3/Connection.php index 312c1ff408eb..2592ad85a2a3 100644 --- a/system/Database/SQLite3/Connection.php +++ b/system/Database/SQLite3/Connection.php @@ -76,7 +76,7 @@ class Connection extends BaseConnection implements ConnectionInterface * @return mixed * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ - public function connect($persistent = false) + public function connect(bool $persistent = false) { if ($persistent && $this->db->DBDebug) { @@ -100,7 +100,7 @@ public function connect($persistent = false) * Keep or establish the connection if no queries have been sent for * a length of time exceeding the server's idle timeout. * - * @return mixed + * @return void */ public function reconnect() { @@ -127,9 +127,9 @@ protected function _close() * * @param string $databaseName * - * @return mixed + * @return boolean */ - public function setDatabase(string $databaseName) + public function setDatabase(string $databaseName): bool { return false; } @@ -139,9 +139,9 @@ public function setDatabase(string $databaseName) /** * Returns a string containing the version of the database being used. * - * @return mixed + * @return string */ - public function getVersion() + public function getVersion(): string { if (isset($this->dataCache['version'])) { @@ -162,7 +162,7 @@ public function getVersion() * * @return mixed \SQLite3Result object or bool */ - public function execute($sql) + public function execute(string $sql) { return $this->isWriteType($sql) ? $this->connID->exec($sql) @@ -174,7 +174,7 @@ public function execute($sql) /** * Returns the total number of rows affected by this query. * - * @return mixed + * @return int */ public function affectedRows(): int { @@ -204,7 +204,7 @@ protected function _escapeString(string $str): string * * @return string */ - protected function _listTables($prefixLimit = false): string + protected function _listTables(bool $prefixLimit = false): string { return 'SELECT "NAME" FROM "SQLITE_MASTER" WHERE "TYPE" = \'table\'' . (($prefixLimit !== false && $this->DBPrefix !== '') @@ -235,7 +235,7 @@ protected function _listColumns(string $table = ''): string * @return array|false * @throws DatabaseException */ - public function getFieldNames($table) + public function getFieldNames(string $table) { // Is there a cached result? if (isset($this->dataCache['field_names'][$table])) @@ -313,19 +313,19 @@ public function _fieldData(string $table): array { return []; } - $retval = []; + $retVal = []; for ($i = 0, $c = count($query); $i < $c; $i++) { - $retval[$i] = new \stdClass(); - $retval[$i]->name = $query[$i]->name; - $retval[$i]->type = $query[$i]->type; - $retval[$i]->max_length = null; - $retval[$i]->default = $query[$i]->dflt_value; - $retval[$i]->primary_key = isset($query[$i]->pk) ? (bool)$query[$i]->pk : false; - $retval[$i]->nullable = isset($query[$i]->notnull) ? ! (bool)$query[$i]->notnull : false; + $retVal[$i] = new \stdClass(); + $retVal[$i]->name = $query[$i]->name; + $retVal[$i]->type = $query[$i]->type; + $retVal[$i]->max_length = null; + $retVal[$i]->default = $query[$i]->dflt_value; + $retVal[$i]->primary_key = isset($query[$i]->pk) ? (bool)$query[$i]->pk : false; + $retVal[$i]->nullable = isset($query[$i]->notnull) ? ! (bool)$query[$i]->notnull : false; } - return $retval; + return $retVal; } //-------------------------------------------------------------------- @@ -348,7 +348,7 @@ public function _indexData(string $table): array } $query = $query->getResultObject(); - $retval = []; + $retVal = []; foreach ($query as $row) { $obj = new \stdClass(); @@ -367,10 +367,10 @@ public function _indexData(string $table): array $obj->fields[] = $field->name; } - $retval[$obj->name] = $obj; + $retVal[$obj->name] = $obj; } - return $retval; + return $retVal; } //-------------------------------------------------------------------- @@ -395,7 +395,7 @@ public function _foreignKeyData(string $table): array return []; } - $retval = []; + $retVal = []; foreach ($tables as $table) { @@ -408,11 +408,11 @@ public function _foreignKeyData(string $table): array $obj->table_name = $table; $obj->foreign_table_name = $row->table; - $retval[] = $obj; + $retVal[] = $obj; } } - return $retval; + return $retVal; } //-------------------------------------------------------------------- diff --git a/system/Database/SQLite3/PreparedQuery.php b/system/Database/SQLite3/PreparedQuery.php index 50e8deed9fb9..9f9848db8807 100644 --- a/system/Database/SQLite3/PreparedQuery.php +++ b/system/Database/SQLite3/PreparedQuery.php @@ -89,7 +89,7 @@ public function _prepare(string $sql, array $options = []) * * @return boolean */ - public function _execute($data) + public function _execute(array $data): bool { if (is_null($this->statement)) { diff --git a/system/Database/SQLite3/Result.php b/system/Database/SQLite3/Result.php index 8a912bdec366..d1e22ca29452 100644 --- a/system/Database/SQLite3/Result.php +++ b/system/Database/SQLite3/Result.php @@ -92,18 +92,18 @@ public function getFieldData(): array SQLITE3_NULL => 'null', ]; - $retval = []; + $retVal = []; for ($i = 0, $c = $this->getFieldCount(); $i < $c; $i ++) { - $retval[$i] = new \stdClass(); - $retval[$i]->name = $this->resultID->columnName($i); + $retVal[$i] = new \stdClass(); + $retVal[$i]->name = $this->resultID->columnName($i); $type = $this->resultID->columnType($i); - $retval[$i]->type = isset($data_types[$type]) ? $data_types[$type] : $type; - $retval[$i]->max_length = null; + $retVal[$i]->type = isset($data_types[$type]) ? $data_types[$type] : $type; + $retVal[$i]->max_length = null; } - return $retval; + return $retVal; } //-------------------------------------------------------------------- @@ -134,7 +134,7 @@ public function freeResult() * @return mixed * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ - public function dataSeek($n = 0) + public function dataSeek(int $n = 0) { if ($n !== 0) { @@ -151,7 +151,7 @@ public function dataSeek($n = 0) * * Overridden by driver classes. * - * @return array + * @return mixed */ protected function fetchAssoc() { @@ -167,9 +167,9 @@ protected function fetchAssoc() * * @param string $className * - * @return object + * @return object|boolean */ - protected function fetchObject($className = 'stdClass') + protected function fetchObject(string $className = 'stdClass') { // No native support for fetching rows as objects if (($row = $this->fetchAssoc()) === false) diff --git a/system/Database/SQLite3/Table.php b/system/Database/SQLite3/Table.php index 0b31eb4ef955..e1332aeb5d56 100644 --- a/system/Database/SQLite3/Table.php +++ b/system/Database/SQLite3/Table.php @@ -214,6 +214,8 @@ public function modifyColumn(array $field) /** * Creates the new table based on our current fields. + * + * @return mixed */ protected function createTable() { @@ -264,6 +266,8 @@ protected function createTable() * Copies data from our old table to the new one, * taking care map data correctly based on any columns * that have been renamed. + * + * @return void */ protected function copyData() { @@ -297,7 +301,7 @@ protected function copyData() * * @param array|boolean $fields * - * @return array + * @return mixed */ protected function formatFields($fields) { @@ -332,7 +336,7 @@ protected function formatFields($fields) * Converts keys retrieved from the database to * the format needed to create later. * - * @param $keys + * @param mixed $keys * * @return mixed */ @@ -359,6 +363,8 @@ protected function formatKeys($keys) /** * Attempts to drop all indexes and constraints * from the database for this table. + * + * @return null|void */ protected function dropIndexes() { diff --git a/system/Database/SQLite3/Utils.php b/system/Database/SQLite3/Utils.php index bdb8ec0ded66..ec16479f84a3 100644 --- a/system/Database/SQLite3/Utils.php +++ b/system/Database/SQLite3/Utils.php @@ -38,12 +38,13 @@ namespace CodeIgniter\Database\SQLite3; +use CodeIgniter\Database\BaseUtils; use CodeIgniter\Database\Exceptions\DatabaseException; /** * Utils for SQLite3 */ -class Utils extends \CodeIgniter\Database\BaseUtils +class Utils extends BaseUtils { /** diff --git a/tests/_support/Database/MockConnection.php b/tests/_support/Database/MockConnection.php index e78405336187..699595bbfc3a 100644 --- a/tests/_support/Database/MockConnection.php +++ b/tests/_support/Database/MockConnection.php @@ -1,5 +1,6 @@ returnValues['connect'] ?? true; @@ -82,9 +101,9 @@ public function connect($persistent = false) * Keep or establish the connection if no queries have been sent for * a length of time exceeding the server's idle timeout. * - * @return mixed + * @return boolean */ - public function reconnect() + public function reconnect(): bool { return true; } @@ -110,11 +129,11 @@ public function setDatabase(string $databaseName) /** * Returns a string containing the version of the database being used. * - * @return mixed + * @return string */ - public function getVersion() + public function getVersion(): string { - return \CodeIgniter\CodeIgniter::CI_VERSION; + return CodeIgniter::CI_VERSION; } //-------------------------------------------------------------------- @@ -122,11 +141,11 @@ public function getVersion() /** * Executes the query against the database. * - * @param $sql + * @param string $sql * * @return mixed */ - protected function execute($sql) + protected function execute(string $sql) { return $this->returnValues['execute']; } @@ -136,7 +155,7 @@ protected function execute($sql) /** * Returns the total number of rows affected by this query. * - * @return mixed + * @return int */ public function affectedRows(): int { @@ -154,7 +173,7 @@ public function affectedRows(): int * * @return array */ - public function error() + public function error(): array { return [ 'code' => null, @@ -169,7 +188,7 @@ public function error() * * @return integer */ - public function insertID() + public function insertID(): int { return $this->connID->insert_id; } @@ -183,7 +202,7 @@ public function insertID() * * @return string */ - protected function _listTables($constrainByPrefix = false): string + protected function _listTables(bool $constrainByPrefix = false): string { return ''; } diff --git a/tests/_support/Database/MockResult.php b/tests/_support/Database/MockResult.php index d33207ff0464..dfe97a99fd5b 100644 --- a/tests/_support/Database/MockResult.php +++ b/tests/_support/Database/MockResult.php @@ -68,9 +68,9 @@ public function dataSeek($n = 0) * * Overridden by driver classes. * - * @return array + * @return mixed */ - protected function fetchAssoc(): array + protected function fetchAssoc() { }