From 784e122d28f9315a5df0f633955db4b017a942ef Mon Sep 17 00:00:00 2001 From: Atish Amte Date: Thu, 11 Apr 2019 21:14:06 +0530 Subject: [PATCH 01/16] Database typos changes --- system/Database/BaseResult.php | 28 +++++++++++++------------- system/Database/MySQLi/Result.php | 8 +++++--- system/Database/Postgre/Result.php | 8 ++++---- system/Database/ResultInterface.php | 26 ++++++++++++------------ system/Database/SQLite3/Result.php | 8 ++++---- tests/_support/Database/MockResult.php | 4 ++-- 6 files changed, 42 insertions(+), 40 deletions(-) diff --git a/system/Database/BaseResult.php b/system/Database/BaseResult.php index ca7f11bb788f..0eda7bf2c0f5 100644 --- a/system/Database/BaseResult.php +++ b/system/Database/BaseResult.php @@ -125,7 +125,7 @@ public function __construct(&$connID, &$resultID) * * @return mixed */ - public function getResult($type = 'object'): array + public function getResult(string $type = 'object'): array { if ($type === 'array') { @@ -296,7 +296,7 @@ public function getResultObject(): array * * @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)) @@ -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/MySQLi/Result.php b/system/Database/MySQLi/Result.php index 2906324e0927..a13f390c29f2 100644 --- a/system/Database/MySQLi/Result.php +++ b/system/Database/MySQLi/Result.php @@ -105,6 +105,8 @@ public function getFieldData(): array /** * 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/Postgre/Result.php b/system/Database/Postgre/Result.php index af4af6682ad3..ec482a3eaf66 100644 --- a/system/Database/Postgre/Result.php +++ b/system/Database/Postgre/Result.php @@ -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/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/Result.php b/system/Database/SQLite3/Result.php index 8a912bdec366..4cfe01bfe830 100644 --- a/system/Database/SQLite3/Result.php +++ b/system/Database/SQLite3/Result.php @@ -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/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() { } From fafc3aaebf4596640c009502b7e71ce64f92e57c Mon Sep 17 00:00:00 2001 From: Atish Amte Date: Thu, 11 Apr 2019 21:20:05 +0530 Subject: [PATCH 02/16] Method phpdoc changes --- system/Database/BaseResult.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/system/Database/BaseResult.php b/system/Database/BaseResult.php index 0eda7bf2c0f5..5b2267d14b05 100644 --- a/system/Database/BaseResult.php +++ b/system/Database/BaseResult.php @@ -123,7 +123,7 @@ 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(string $type = 'object'): array { @@ -291,7 +291,7 @@ 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 @@ -412,8 +412,8 @@ public function getRowObject(int $n = 0) /** * Assigns an item into a particular column slot. * - * @param $key - * @param null $value + * @param mixed $key + * @param mixed $value * * @return mixed */ From a1bb11d898677e8e400a786e8ad39af4931f0ade Mon Sep 17 00:00:00 2001 From: Atish Amte Date: Thu, 11 Apr 2019 21:34:26 +0530 Subject: [PATCH 03/16] Database connection typos changes --- system/Database/BaseConnection.php | 67 ++++++++++++---------- system/Database/ConnectionInterface.php | 10 ++-- system/Database/MySQLi/Connection.php | 8 +-- system/Database/Postgre/Connection.php | 8 +-- system/Database/SQLite3/Connection.php | 8 +-- tests/_support/Database/MockConnection.php | 4 +- 6 files changed, 56 insertions(+), 49 deletions(-) diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index 7e163304a252..bcef56b37c4b 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -422,7 +422,7 @@ public function initialize() * @param boolean $persistent * @return mixed */ - abstract public function connect($persistent = false); + abstract public function connect(bool $persistent = false); //-------------------------------------------------------------------- @@ -526,9 +526,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 +538,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 +586,7 @@ public function addTableAlias(string $table) * * @return mixed */ - abstract protected function execute($sql); + abstract protected function execute(string $sql); //-------------------------------------------------------------------- @@ -599,13 +599,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)) { @@ -750,7 +750,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) { if (! $this->transEnabled) { @@ -924,7 +924,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 +1008,7 @@ public function getLastQuery() * * @return string */ - public function showLastQuery() + public function showLastQuery(): string { return (string) $this->lastQuery; } @@ -1023,7 +1023,7 @@ public function showLastQuery() * * @return float */ - public function getConnectStart() + public function getConnectStart(): float { return $this->connectTime; } @@ -1040,7 +1040,7 @@ public function getConnectStart() * * @return mixed */ - public function getConnectDuration($decimals = 6) + public function getConnectDuration(int $decimals = 6) { return number_format($this->connectDuration, $decimals); } @@ -1067,14 +1067,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 +1313,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 +1334,7 @@ public function prefixTable($table = '') * * @return string */ - public function setPrefix($prefix = '') + public function setPrefix(string $prefix = ''): string { return $this->DBPrefix = $prefix; } @@ -1356,7 +1356,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 +1395,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)) { @@ -1507,7 +1507,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 +1566,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 +1581,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 +1637,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)); } @@ -1803,12 +1803,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/ConnectionInterface.php b/system/Database/ConnectionInterface.php index 76f8a64c3ac4..0b834897e2f4 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; //-------------------------------------------------------------------- diff --git a/system/Database/MySQLi/Connection.php b/system/Database/MySQLi/Connection.php index 7c6d45c4909d..5f62f55d0bb8 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] === '/') @@ -287,9 +287,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 +313,7 @@ public function getVersion() * * @return mixed */ - public function execute($sql) + public function execute(string $sql) { while ($this->connID->more_results()) { diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index 56aec4f905e0..2668c605c699 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)) { @@ -160,9 +160,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 +186,7 @@ public function getVersion() * * @return resource */ - public function execute($sql) + public function execute(string $sql) { return pg_query($this->connID, $sql); } diff --git a/system/Database/SQLite3/Connection.php b/system/Database/SQLite3/Connection.php index 312c1ff408eb..9dd683c7d4be 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) { @@ -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) diff --git a/tests/_support/Database/MockConnection.php b/tests/_support/Database/MockConnection.php index e78405336187..a268e622961c 100644 --- a/tests/_support/Database/MockConnection.php +++ b/tests/_support/Database/MockConnection.php @@ -110,9 +110,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 { return \CodeIgniter\CodeIgniter::CI_VERSION; } From 2e8f171ad792bb364a1d26ecc8ed0ef12f3673f6 Mon Sep 17 00:00:00 2001 From: Atish Amte Date: Thu, 11 Apr 2019 21:50:14 +0530 Subject: [PATCH 04/16] _listtable changes --- system/Database/BaseConnection.php | 2 +- system/Database/MySQLi/Connection.php | 2 +- system/Database/Postgre/Connection.php | 2 +- system/Database/SQLite3/Connection.php | 2 +- tests/_support/Database/MockConnection.php | 37 ++++++++++++++++------ 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index bcef56b37c4b..7d7242cac163 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -1755,7 +1755,7 @@ abstract public function insertID(); * * @return string */ - abstract protected function _listTables($constrainByPrefix = false): string; + abstract protected function _listTables(bool $constrainByPrefix = false): string; //-------------------------------------------------------------------- diff --git a/system/Database/MySQLi/Connection.php b/system/Database/MySQLi/Connection.php index 5f62f55d0bb8..cf8fe511df25 100644 --- a/system/Database/MySQLi/Connection.php +++ b/system/Database/MySQLi/Connection.php @@ -394,7 +394,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); diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index 2668c605c699..b72358050b6d 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -259,7 +259,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 . "'"; diff --git a/system/Database/SQLite3/Connection.php b/system/Database/SQLite3/Connection.php index 9dd683c7d4be..6b1907a188e7 100644 --- a/system/Database/SQLite3/Connection.php +++ b/system/Database/SQLite3/Connection.php @@ -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 !== '') diff --git a/tests/_support/Database/MockConnection.php b/tests/_support/Database/MockConnection.php index a268e622961c..9d32ae982325 100644 --- a/tests/_support/Database/MockConnection.php +++ b/tests/_support/Database/MockConnection.php @@ -1,5 +1,6 @@ returnValues['connect'] ?? true; @@ -82,7 +99,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 boolean */ public function reconnect() { @@ -114,7 +131,7 @@ public function setDatabase(string $databaseName) */ public function getVersion(): string { - return \CodeIgniter\CodeIgniter::CI_VERSION; + return CodeIgniter::CI_VERSION; } //-------------------------------------------------------------------- @@ -122,11 +139,11 @@ public function getVersion(): string /** * 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 +153,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 +171,7 @@ public function affectedRows(): int * * @return array */ - public function error() + public function error(): array { return [ 'code' => null, @@ -169,7 +186,7 @@ public function error() * * @return integer */ - public function insertID() + public function insertID(): int { return $this->connID->insert_id; } @@ -183,7 +200,7 @@ public function insertID() * * @return string */ - protected function _listTables($constrainByPrefix = false): string + protected function _listTables(bool $constrainByPrefix = false): string { return ''; } From 6753e8cfa64e422f96c4399571d4666048cb6ae5 Mon Sep 17 00:00:00 2001 From: Atish Amte Date: Thu, 11 Apr 2019 22:05:58 +0530 Subject: [PATCH 05/16] Database connetion typos changes --- system/Database/BaseConnection.php | 18 +++++++++++------- system/Database/ConnectionInterface.php | 4 ++-- system/Database/MySQLi/Connection.php | 14 ++++++++------ system/Database/Postgre/Connection.php | 16 +++++++++------- system/Database/SQLite3/Connection.php | 10 +++++----- 5 files changed, 35 insertions(+), 27 deletions(-) diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index 7d7242cac163..c278568f1e33 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -428,6 +428,8 @@ abstract public function connect(bool $persistent = false); /** * Close the database connection. + * + * @return void */ public function close() { @@ -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(bool $test_mode = false) + public function transStart(bool $test_mode = false): bool { if (! $this->transEnabled) { @@ -767,7 +771,7 @@ public function transStart(bool $test_mode = false) * * @return boolean */ - public function transComplete() + public function transComplete(): bool { if (! $this->transEnabled) { @@ -1038,9 +1042,9 @@ public function getConnectStart(): float * * @param integer $decimals * - * @return mixed + * @return string */ - public function getConnectDuration(int $decimals = 6) + public function getConnectDuration(int $decimals = 6): string { return number_format($this->connectDuration, $decimals); } @@ -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)) . '_'; @@ -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; //-------------------------------------------------------------------- diff --git a/system/Database/ConnectionInterface.php b/system/Database/ConnectionInterface.php index 0b834897e2f4..a4a9a2745046 100644 --- a/system/Database/ConnectionInterface.php +++ b/system/Database/ConnectionInterface.php @@ -154,7 +154,7 @@ public function getVersion(): string; * 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/MySQLi/Connection.php b/system/Database/MySQLi/Connection.php index cf8fe511df25..8061cb04ed6c 100644 --- a/system/Database/MySQLi/Connection.php +++ b/system/Database/MySQLi/Connection.php @@ -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 === '') { @@ -338,7 +340,7 @@ public function execute(string $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 { @@ -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/Postgre/Connection.php b/system/Database/Postgre/Connection.php index b72358050b6d..5816892dcb65 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -121,7 +121,7 @@ public function connect(bool $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; } @@ -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) @@ -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/SQLite3/Connection.php b/system/Database/SQLite3/Connection.php index 6b1907a188e7..2220cf965d78 100644 --- a/system/Database/SQLite3/Connection.php +++ b/system/Database/SQLite3/Connection.php @@ -100,7 +100,7 @@ public function connect(bool $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; } @@ -174,7 +174,7 @@ public function execute(string $sql) /** * Returns the total number of rows affected by this query. * - * @return mixed + * @return int */ public function affectedRows(): int { @@ -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])) From a283a9ae7b76d93de18f1049442a4219471dd40b Mon Sep 17 00:00:00 2001 From: Atish Amte Date: Thu, 11 Apr 2019 22:19:42 +0530 Subject: [PATCH 06/16] Database connetion typos changes --- system/Database/MySQLi/Connection.php | 20 +++++++-------- system/Database/MySQLi/Result.php | 16 ++++++------ system/Database/Postgre/Connection.php | 28 ++++++++++---------- system/Database/Postgre/Result.php | 16 ++++++------ system/Database/SQLite3/Connection.php | 30 +++++++++++----------- system/Database/SQLite3/Result.php | 12 ++++----- tests/_support/Database/MockConnection.php | 4 ++- 7 files changed, 64 insertions(+), 62 deletions(-) diff --git a/system/Database/MySQLi/Connection.php b/system/Database/MySQLi/Connection.php index 8061cb04ed6c..8d189e620448 100644 --- a/system/Database/MySQLi/Connection.php +++ b/system/Database/MySQLi/Connection.php @@ -441,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; } //-------------------------------------------------------------------- @@ -552,7 +552,7 @@ public function _foreignKeyData(string $table): array } $query = $query->getResultObject(); - $retval = []; + $retVal = []; foreach ($query as $row) { $obj = new \stdClass(); @@ -560,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; } //-------------------------------------------------------------------- diff --git a/system/Database/MySQLi/Result.php b/system/Database/MySQLi/Result.php index a13f390c29f2..5d66f86ec0e8 100644 --- a/system/Database/MySQLi/Result.php +++ b/system/Database/MySQLi/Result.php @@ -85,20 +85,20 @@ 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; } //-------------------------------------------------------------------- diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index 5816892dcb65..eda14acc5dea 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -198,7 +198,7 @@ public function execute(string $sql) /** * Returns the total number of rows affected by this query. * - * @return mixed + * @return int */ public function affectedRows(): int { @@ -314,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; } //-------------------------------------------------------------------- @@ -349,7 +349,7 @@ public function _indexData(string $table): array } $query = $query->getResultObject(); - $retval = []; + $retVal = []; foreach ($query as $row) { $obj = new \stdClass(); @@ -368,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; } //-------------------------------------------------------------------- @@ -403,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; } //-------------------------------------------------------------------- diff --git a/system/Database/Postgre/Result.php b/system/Database/Postgre/Result.php index ec482a3eaf66..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; } //-------------------------------------------------------------------- diff --git a/system/Database/SQLite3/Connection.php b/system/Database/SQLite3/Connection.php index 2220cf965d78..2592ad85a2a3 100644 --- a/system/Database/SQLite3/Connection.php +++ b/system/Database/SQLite3/Connection.php @@ -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/Result.php b/system/Database/SQLite3/Result.php index 4cfe01bfe830..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; } //-------------------------------------------------------------------- diff --git a/tests/_support/Database/MockConnection.php b/tests/_support/Database/MockConnection.php index 9d32ae982325..699595bbfc3a 100644 --- a/tests/_support/Database/MockConnection.php +++ b/tests/_support/Database/MockConnection.php @@ -77,6 +77,8 @@ public function query(string $sql, $binds = null, bool $setEscapeFlags = true, s /** * Connect to the database. * + * @param boolean $persistent + * * @return mixed */ public function connect(bool $persistent = false) @@ -101,7 +103,7 @@ public function connect(bool $persistent = false) * * @return boolean */ - public function reconnect() + public function reconnect(): bool { return true; } From a45a605b60dad38f91a00152193c7cde27caf6bc Mon Sep 17 00:00:00 2001 From: Atish Amte Date: Thu, 11 Apr 2019 22:32:02 +0530 Subject: [PATCH 07/16] Database Utils typos changes --- system/Database/BaseUtils.php | 18 +++++++++--------- system/Database/MySQLi/Utils.php | 3 ++- system/Database/Postgre/Utils.php | 3 ++- system/Database/SQLite3/Utils.php | 3 ++- 4 files changed, 15 insertions(+), 12 deletions(-) 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/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/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/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 { /** From 38abfb1fa78a3bb4a36a72a638fe6a8cd4c380ab Mon Sep 17 00:00:00 2001 From: Atish Amte Date: Thu, 11 Apr 2019 22:37:17 +0530 Subject: [PATCH 08/16] Database MigrationRunner typos changes --- system/Database/MigrationRunner.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/system/Database/MigrationRunner.php b/system/Database/MigrationRunner.php index 810e9a90791c..ea95cfa997a0 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 = []; @@ -674,7 +674,7 @@ protected function getMigrationName(string $migration) * * @return string Current migration version */ - protected function getVersion() + protected function getVersion(): string { $this->ensureTable(); From f33c1ee5b492e7416aff7d8fc7e318e1f54b93db Mon Sep 17 00:00:00 2001 From: Atish Amte Date: Thu, 11 Apr 2019 22:38:40 +0530 Subject: [PATCH 09/16] Database MigrationRunner checkMigration() typos changes --- system/Database/MigrationRunner.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/system/Database/MigrationRunner.php b/system/Database/MigrationRunner.php index ea95cfa997a0..ec66448546ae 100644 --- a/system/Database/MigrationRunner.php +++ b/system/Database/MigrationRunner.php @@ -471,11 +471,11 @@ public function findMigrations(): array * * @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); From bcf8f0cb43605240ab704ebb55acb957a6841f4d Mon Sep 17 00:00:00 2001 From: Atish Amte Date: Thu, 11 Apr 2019 22:40:43 +0530 Subject: [PATCH 10/16] Database Migration typos changes --- system/Database/Migration.php | 2 +- system/Database/MigrationRunner.php | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/system/Database/Migration.php b/system/Database/Migration.php index eb27199dfd62..46b55a62b449 100644 --- a/system/Database/Migration.php +++ b/system/Database/Migration.php @@ -86,7 +86,7 @@ public function __construct(Forge $forge = null) * * @return string */ - public function getDBGroup() + public function getDBGroup(): string { return $this->DBGroup; } diff --git a/system/Database/MigrationRunner.php b/system/Database/MigrationRunner.php index ec66448546ae..3a3604f86e5e 100644 --- a/system/Database/MigrationRunner.php +++ b/system/Database/MigrationRunner.php @@ -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); @@ -695,7 +695,7 @@ protected function getVersion(): string * * @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) { From 282418d28d698de9fea165d5dea74e425903e2c3 Mon Sep 17 00:00:00 2001 From: Atish Amte Date: Thu, 11 Apr 2019 22:42:21 +0530 Subject: [PATCH 11/16] Database config typos changes --- system/Database/Config.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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(); } //-------------------------------------------------------------------- From 48c4dc5891cb4283ea711be9037305d846c29797 Mon Sep 17 00:00:00 2001 From: Atish Amte Date: Thu, 11 Apr 2019 22:44:07 +0530 Subject: [PATCH 12/16] Database SQLite3 Table typos changes --- system/Database/SQLite3/Table.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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() { From 2053cea77bbbebe7a8d82e8230694e95f8df64c4 Mon Sep 17 00:00:00 2001 From: Atish Amte Date: Thu, 11 Apr 2019 22:55:31 +0530 Subject: [PATCH 13/16] Database PreparedQuery typos changes --- system/Database/BasePreparedQuery.php | 15 +++++++++------ system/Database/MySQLi/PreparedQuery.php | 4 ++-- system/Database/Postgre/PreparedQuery.php | 3 ++- system/Database/SQLite3/PreparedQuery.php | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) 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/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/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/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)) { From 2e9529146d2ac9475d3b13665a1be86e5bffb5ca Mon Sep 17 00:00:00 2001 From: Atish Amte Date: Thu, 11 Apr 2019 23:04:13 +0530 Subject: [PATCH 14/16] Database QueryInterface typos changes --- system/Database/QueryInterface.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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; //-------------------------------------------------------------------- From 1f3fadc0940e0a6a375c734ca11acb388e8429ad Mon Sep 17 00:00:00 2001 From: Atish Amte Date: Thu, 11 Apr 2019 23:27:44 +0530 Subject: [PATCH 15/16] Database Builder typos changes --- system/Database/BaseBuilder.php | 8 ++++---- system/Database/Postgre/Builder.php | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) 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/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. */ From b3029fdc0f053ae2fec47ee2e0ecc7a6d3e431f7 Mon Sep 17 00:00:00 2001 From: Atish Amte Date: Thu, 11 Apr 2019 23:28:43 +0530 Subject: [PATCH 16/16] Database Exception alignment changes --- system/Database/Exceptions/DataException.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 @@ -