From 5fb77f194377cd6b60784c72309abef735f1e8c2 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Sun, 23 Aug 2026 21:02:32 +0800 Subject: [PATCH] refactor: fix phpstan errors in `Connection` --- system/Database/BaseConnection.php | 125 +++++++------- system/Database/ConnectionInterface.php | 6 +- system/Database/MySQLi/Connection.php | 37 +---- system/Database/OCI8/Connection.php | 54 +------ system/Database/Postgre/Connection.php | 47 +----- system/Database/SQLSRV/Connection.php | 42 +---- system/Database/SQLite3/Connection.php | 39 +---- tests/system/Database/Live/EscapeTest.php | 3 + tests/system/Database/Live/GetVersionTest.php | 2 + .../Database/Live/MySQLi/FoundRowsTest.php | 3 + .../Database/Live/MySQLi/NumberNativeTest.php | 3 + .../Live/OCI8/CallStoredProcedureTest.php | 7 + tests/system/Database/Live/OrderTest.php | 3 + .../Database/Live/PreparedQueryTest.php | 3 + utils/phpstan-baseline/loader.neon | 2 +- utils/phpstan-baseline/method.notFound.neon | 17 +- .../missingType.iterableValue.neon | 152 +----------------- utils/phpstan-baseline/property.notFound.neon | 27 +--- .../phpstan-baseline/property.phpDocType.neon | 27 +--- 19 files changed, 103 insertions(+), 496 deletions(-) diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index f872ab2bdc06..98ec9df3e2b9 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -25,35 +25,35 @@ use Throwable; /** - * @property-read array $aliasedTables - * @property-read string $charset - * @property-read bool $compress - * @property-read float $connectDuration - * @property-read float $connectTime - * @property-read string $database - * @property-read array $dateFormat - * @property-read string $DBCollat - * @property-read bool $DBDebug - * @property-read string $DBDriver - * @property-read string $DBPrefix - * @property-read string $DSN - * @property-read array|bool $encrypt - * @property-read array $failover - * @property-read string $hostname - * @property-read Query $lastQuery - * @property-read string $password - * @property-read bool $pConnect - * @property-read int|string $port - * @property-read bool $pretend - * @property-read string $queryClass - * @property-read array $reservedIdentifiers - * @property-read bool $strictOn - * @property-read string $subdriver - * @property-read string $swapPre - * @property-read int $transDepth - * @property-read bool $transFailure - * @property-read bool $transStatus - * @property-read string $username + * @property-read list $aliasedTables + * @property-read string $charset + * @property-read bool $compress + * @property-read float $connectDuration + * @property-read float $connectTime + * @property-read string $database + * @property-read array $dateFormat + * @property-read string $DBCollat + * @property-read bool $DBDebug + * @property-read string $DBDriver + * @property-read string $DBPrefix + * @property-read string $DSN + * @property-read array|bool $encrypt + * @property-read list> $failover + * @property-read string $hostname + * @property-read Query $lastQuery + * @property-read string $password + * @property-read bool $pConnect + * @property-read int|string $port + * @property-read bool $pretend + * @property-read string $queryClass + * @property-read list $reservedIdentifiers + * @property-read bool $strictOn + * @property-read string $subdriver + * @property-read string $swapPre + * @property-read int $transDepth + * @property-read bool $transFailure + * @property-read bool $transStatus + * @property-read string $username * * @template TConnection * @template TResult @@ -177,7 +177,7 @@ abstract class BaseConnection implements ConnectionInterface /** * Encryption flag/data * - * @var array|bool + * @var array|bool */ protected $encrypt = false; @@ -202,7 +202,7 @@ abstract class BaseConnection implements ConnectionInterface /** * Settings for a failover connection. * - * @var array + * @var list> */ protected $failover = []; @@ -240,14 +240,14 @@ abstract class BaseConnection implements ConnectionInterface * * Identifiers that must NOT be escaped. * - * @var array + * @var list */ protected $reservedIdentifiers = ['*']; /** * Identifier escape character * - * @var array|string + * @var list|string */ public $escapeChar = '"'; @@ -268,15 +268,12 @@ abstract class BaseConnection implements ConnectionInterface /** * RegExp used to escape identifiers * - * @var array + * @var list */ protected $pregEscapeChar = []; /** - * Holds previously looked up data - * for performance reasons. - * - * @var array + * @var array */ public $dataCache = []; @@ -374,7 +371,7 @@ abstract class BaseConnection implements ConnectionInterface ]; /** - * Saves our connection settings. + * @param array $params */ public function __construct(array $params) { @@ -739,6 +736,8 @@ public function getPlatform(): string * collected during use of the Builder, and set here * so queries are built correctly. * + * @param list $aliases + * * @return $this */ public function setAliasedTables(array $aliases) @@ -1111,7 +1110,7 @@ abstract protected function _transRollback(): bool; /** * Returns a non-shared new instance of the query builder for this connection. * - * @param array|string|TableName $tableName + * @param array|string|TableName $tableName * * @return BaseBuilder * @@ -1156,6 +1155,7 @@ public function newQuery(): BaseBuilder * }) * * @param Closure(BaseConnection): mixed $func + * @param array $options * * @return BasePreparedQuery|null */ @@ -1242,12 +1242,12 @@ public function getConnectDuration(int $decimals = 6): string * insert the table prefix (if it exists) in the proper position, and escape only * the correct identifiers. * - * @param array|int|string|TableName $item - * @param bool $prefixSingle Prefix a table name with no segments? - * @param bool $protectIdentifiers Protect table or column names? - * @param bool $fieldExists Supplied $item contains a column name? + * @param array|int|string|TableName $item + * @param bool $prefixSingle Prefix a table name with no segments? + * @param bool $protectIdentifiers Protect table or column names? + * @param bool $fieldExists Supplied $item contains a column name? * - * @return ($item is array ? array : string) + * @return ($item is array ? array : string) */ public function protectIdentifiers($item, bool $prefixSingle = false, ?bool $protectIdentifiers = null, bool $fieldExists = true) { @@ -1448,9 +1448,9 @@ private function escapeTableName(TableName $tableName): string * * This function escapes column and table names * - * @param array|string $item + * @param array|string $item * - * @return ($item is array ? array : string) + * @return ($item is array ? array : string) */ public function escapeIdentifiers($item) { @@ -1534,7 +1534,7 @@ abstract public function affectedRows(): int; * * @param mixed $str * - * @return ($str is array ? array : float|int|string) + * @return ($str is array ? array : float|int|string) */ public function escape($str) { @@ -1638,7 +1638,7 @@ protected function _escapeString(string $str): string * This function enables you to call PHP database functions that are not natively included * in CodeIgniter, in a platform independent manner. * - * @param array ...$params + * @param mixed ...$params * * @throws DatabaseException */ @@ -1682,7 +1682,7 @@ protected function getDriverFunctionPrefix(): string */ public function listTables(bool $constrainByPrefix = false) { - if (isset($this->dataCache['table_names']) && $this->dataCache['table_names']) { + if (($this->dataCache['table_names'] ?? []) !== []) { $tables = $constrainByPrefix ? preg_grep("/^{$this->DBPrefix}/", $this->dataCache['table_names']) : $this->dataCache['table_names']; @@ -1847,21 +1847,18 @@ public function getForeignKeyData(string $table) /** * Converts array of arrays generated by _foreignKeyData() to array of objects * - * @return array + * @param array, + * foreign_table_name: string, + * foreign_column_name: list, + * on_delete: string, + * on_update: string|null, + * match: string|null, + * }> $data * - * array[ - * {constraint_name} => - * stdClass[ - * 'constraint_name' => string, - * 'table_name' => string, - * 'column_name' => string[], - * 'foreign_table_name' => string, - * 'foreign_column_name' => string[], - * 'on_delete' => string, - * 'on_update' => string, - * 'match' => string - * ] - * ] + * @return array */ protected function foreignKeyDataToObjects(array $data) { diff --git a/system/Database/ConnectionInterface.php b/system/Database/ConnectionInterface.php index d1206155125c..0474736b5cd2 100644 --- a/system/Database/ConnectionInterface.php +++ b/system/Database/ConnectionInterface.php @@ -118,7 +118,7 @@ public function simpleQuery(string $sql); /** * Returns an instance of the query builder for this connection. * - * @param array|string $tableName Table name. + * @param array|string $tableName Table name. * * @return BaseBuilder Builder. */ @@ -139,7 +139,7 @@ public function getLastQuery(); * * @param mixed $str * - * @return ($str is array ? array : float|int|string) + * @return ($str is array ? array : float|int|string) */ public function escape($str); @@ -147,7 +147,7 @@ public function escape($str); * Allows for custom calls to the database engine that are not * supported through our database layer. * - * @param array ...$params + * @param mixed ...$params * * @return mixed */ diff --git a/system/Database/MySQLi/Connection.php b/system/Database/MySQLi/Connection.php index 29cb80b168c5..10e56e944dd4 100644 --- a/system/Database/MySQLi/Connection.php +++ b/system/Database/MySQLi/Connection.php @@ -15,7 +15,6 @@ use CodeIgniter\Database\BaseConnection; use CodeIgniter\Database\Exceptions\DatabaseException; -use CodeIgniter\Database\TableName; use CodeIgniter\Exceptions\LogicException; use mysqli; use mysqli_result; @@ -51,7 +50,7 @@ class Connection extends BaseConnection /** * Identifier escape character * - * @var string + * @var list|string */ public $escapeChar = '`'; @@ -234,11 +233,6 @@ public function connect(bool $persistent = false) return false; } - /** - * Close the database connection. - * - * @return void - */ protected function _close() { $this->connID->close(); @@ -379,10 +373,7 @@ public function escapeLikeStringDirect($str) } /** - * Generates the SQL for listing tables in a platform-dependent manner. * Uses escapeLikeStringDirect(). - * - * @param string|null $tableName If $tableName is provided will return only this table if exists. */ protected function _listTables(bool $prefixLimit = false, ?string $tableName = null): string { @@ -399,11 +390,6 @@ protected function _listTables(bool $prefixLimit = false, ?string $tableName = n return $sql; } - /** - * Generates a platform-specific query string so that the column names can be fetched. - * - * @param string|TableName $table - */ protected function _listColumns($table = ''): string { $tableName = $this->protectIdentifiers( @@ -417,10 +403,6 @@ protected function _listColumns($table = ''): string } /** - * Returns an array of objects with field data - * - * @return list - * * @throws DatabaseException */ protected function _fieldData(string $table): array @@ -449,10 +431,6 @@ protected function _fieldData(string $table): array } /** - * Returns an array of objects with index data - * - * @return array - * * @throws DatabaseException * @throws LogicException */ @@ -497,10 +475,6 @@ protected function _indexData(string $table): array } /** - * Returns an array of objects with Foreign key data - * - * @return array - * * @throws DatabaseException */ protected function _foreignKeyData(string $table): array @@ -598,25 +572,16 @@ public function insertID(): int return $this->connID->insert_id; } - /** - * Begin Transaction - */ protected function _transBegin(): bool { return $this->connID->begin_transaction(); } - /** - * Commit Transaction - */ protected function _transCommit(): bool { return $this->connID->commit(); } - /** - * Rollback Transaction - */ protected function _transRollback(): bool { return $this->connID->rollback(); diff --git a/system/Database/OCI8/Connection.php b/system/Database/OCI8/Connection.php index 6f3d0dd7794c..0d700ef095cf 100644 --- a/system/Database/OCI8/Connection.php +++ b/system/Database/OCI8/Connection.php @@ -37,7 +37,7 @@ class Connection extends BaseConnection /** * Identifier escape character * - * @var string + * @var list|string */ public $escapeChar = '"'; @@ -46,7 +46,7 @@ class Connection extends BaseConnection * * Identifiers that must NOT be escaped. * - * @var array + * @var list */ protected $reservedIdentifiers = [ '*', @@ -155,11 +155,6 @@ public function connect(bool $persistent = false) : $func($this->username, $this->password, $this->DSN, $this->charset); } - /** - * Close the database connection. - * - * @return void - */ protected function _close() { if (is_resource($this->cursorId)) { @@ -283,11 +278,6 @@ public function affectedRows(): int return oci_num_rows($this->stmtId); } - /** - * Generates the SQL for listing tables in a platform-dependent manner. - * - * @param string|null $tableName If $tableName is provided will return only this table if exists. - */ protected function _listTables(bool $prefixLimit = false, ?string $tableName = null): string { $sql = 'SELECT "TABLE_NAME" FROM "USER_TABLES"'; @@ -304,11 +294,6 @@ protected function _listTables(bool $prefixLimit = false, ?string $tableName = n return $sql; } - /** - * Generates a platform-specific query string so that the column names can be fetched. - * - * @param string|TableName $table - */ protected function _listColumns($table = ''): string { if ($table instanceof TableName) { @@ -328,10 +313,6 @@ protected function _listColumns($table = ''): string } /** - * Returns an array of objects with field data - * - * @return list - * * @throws DatabaseException */ protected function _fieldData(string $table): array @@ -385,10 +366,6 @@ private function normalizeDefault(?string $default): ?string } /** - * Returns an array of objects with index data - * - * @return array - * * @throws DatabaseException */ protected function _indexData(string $table): array @@ -434,10 +411,6 @@ protected function _indexData(string $table): array } /** - * Returns an array of objects with Foreign key data - * - * @return array - * * @throws DatabaseException */ protected function _foreignKeyData(string $table): array @@ -544,14 +517,8 @@ public function getCursor() /** * Executes a stored procedure * - * @param string $procedureName procedure name to execute - * @param array $params params array keys - * KEY OPTIONAL NOTES - * name no the name of the parameter should be in : format - * value no the value of the parameter. If this is an OUT or IN OUT parameter, - * this should be a reference to a variable - * type yes the type of the parameter - * length yes the max size of the parameter + * @param string $procedureName Procedure name to execute + * @param list $params `name` must be in `:` format. `value` is bound by reference. * * @return bool|Query|Result */ @@ -565,7 +532,7 @@ public function storedProcedure(string $procedureName, array $params) $sql = sprintf( 'BEGIN %s (' . substr(str_repeat(',%s', count($params)), 1) . '); END;', $procedureName, - ...array_map(static fn ($row) => $row['name'], $params), + ...array_map(static fn (array $row): string => $row['name'], $params), ); $this->resetStmtId = false; @@ -580,7 +547,7 @@ public function storedProcedure(string $procedureName, array $params) /** * Bind parameters * - * @param array $params + * @param list $params * * @return void */ @@ -734,9 +701,6 @@ protected function buildDSN() $this->DSN = ''; } - /** - * Begin Transaction - */ protected function _transBegin(): bool { $this->commitMode = OCI_NO_AUTO_COMMIT; @@ -744,9 +708,6 @@ protected function _transBegin(): bool return true; } - /** - * Commit Transaction - */ protected function _transCommit(): bool { $this->commitMode = OCI_COMMIT_ON_SUCCESS; @@ -754,9 +715,6 @@ protected function _transCommit(): bool return oci_commit($this->connID); } - /** - * Rollback Transaction - */ protected function _transRollback(): bool { $this->commitMode = OCI_COMMIT_ON_SUCCESS; diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index fc5421a894ea..a152b90aa539 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -47,7 +47,7 @@ class Connection extends BaseConnection /** * Identifier escape character * - * @var string + * @var list|string */ public $escapeChar = '"'; @@ -157,11 +157,6 @@ private function convertDSN() $this->DSN = $output; } - /** - * Close the database connection. - * - * @return void - */ protected function _close() { pg_close($this->connID); @@ -251,15 +246,6 @@ public function affectedRows(): int return pg_affected_rows($this->resultID); } - /** - * "Smart" Escape String - * - * Escapes data based on type - * - * @param mixed $str - * - * @return ($str is array ? array : float|int|string) - */ public function escape($str) { if (! $this->connID) { @@ -297,11 +283,6 @@ protected function _escapeString(string $str): string return pg_escape_string($this->connID, $str); } - /** - * Generates the SQL for listing tables in a platform-dependent manner. - * - * @param string|null $tableName If $tableName is provided will return only this table if exists. - */ protected function _listTables(bool $prefixLimit = false, ?string $tableName = null): string { $sql = 'SELECT "table_name" FROM "information_schema"."tables" WHERE "table_schema" = \'' . $this->schema . "'"; @@ -319,11 +300,6 @@ protected function _listTables(bool $prefixLimit = false, ?string $tableName = n return $sql; } - /** - * Generates a platform-specific query string so that the column names can be fetched. - * - * @param string|TableName $table - */ protected function _listColumns($table = ''): string { if ($table instanceof TableName) { @@ -339,10 +315,6 @@ protected function _listColumns($table = ''): string } /** - * Returns an array of objects with field data - * - * @return list - * * @throws DatabaseException */ protected function _fieldData(string $table): array @@ -374,10 +346,6 @@ protected function _fieldData(string $table): array } /** - * Returns an array of objects with index data - * - * @return array - * * @throws DatabaseException */ protected function _indexData(string $table): array @@ -413,10 +381,6 @@ protected function _indexData(string $table): array } /** - * Returns an array of objects with Foreign key data - * - * @return array - * * @throws DatabaseException */ protected function _foreignKeyData(string $table): array @@ -593,25 +557,16 @@ protected function setClientEncoding(string $charset): bool return pg_set_client_encoding($this->connID, $charset) === 0; } - /** - * Begin Transaction - */ protected function _transBegin(): bool { return (bool) pg_query($this->connID, 'BEGIN'); } - /** - * Commit Transaction - */ protected function _transCommit(): bool { return (bool) pg_query($this->connID, 'COMMIT'); } - /** - * Rollback Transaction - */ protected function _transRollback(): bool { return (bool) pg_query($this->connID, 'ROLLBACK'); diff --git a/system/Database/SQLSRV/Connection.php b/system/Database/SQLSRV/Connection.php index ce1a210341d3..5e82e7b2abf3 100644 --- a/system/Database/SQLSRV/Connection.php +++ b/system/Database/SQLSRV/Connection.php @@ -54,7 +54,7 @@ class Connection extends BaseConnection /** * Identifier escape character * - * @var string + * @var list|string */ public $escapeChar = '"'; @@ -84,9 +84,6 @@ class Connection extends BaseConnection */ protected $_reserved_identifiers = ['*']; - /** - * Class constructor - */ public function __construct(array $params) { parent::__construct($params); @@ -166,11 +163,6 @@ public function getAllErrorMessages(): string return implode("\n", $errors); } - /** - * Close the database connection. - * - * @return void - */ protected function _close() { sqlsrv_close($this->connID); @@ -192,11 +184,6 @@ public function insertID(): int return (int) ($this->query('SELECT SCOPE_IDENTITY() AS insert_id')->getRow()->insert_id ?? 0); } - /** - * Generates the SQL for listing tables in a platform-dependent manner. - * - * @param string|null $tableName If $tableName is provided will return only this table if exists. - */ protected function _listTables(bool $prefixLimit = false, ?string $tableName = null): string { $sql = 'SELECT [TABLE_NAME] AS "name"' @@ -216,11 +203,6 @@ protected function _listTables(bool $prefixLimit = false, ?string $tableName = n return $sql; } - /** - * Generates a platform-specific query string so that the column names can be fetched. - * - * @param string|TableName $table - */ protected function _listColumns($table = ''): string { if ($table instanceof TableName) { @@ -236,10 +218,6 @@ protected function _listColumns($table = ''): string } /** - * Returns an array of objects with index data - * - * @return array - * * @throws DatabaseException */ protected function _indexData(string $table): array @@ -273,11 +251,6 @@ protected function _indexData(string $table): array } /** - * Returns an array of objects with Foreign key data - * referenced_object_id parent_object_id - * - * @return array - * * @throws DatabaseException */ protected function _foreignKeyData(string $table): array @@ -340,10 +313,6 @@ protected function _enableForeignKeyChecks() } /** - * Returns an array of objects with field data - * - * @return list - * * @throws DatabaseException */ protected function _fieldData(string $table): array @@ -412,25 +381,16 @@ private function normalizeDefault(?string $default): ?string return $default; } - /** - * Begin Transaction - */ protected function _transBegin(): bool { return sqlsrv_begin_transaction($this->connID); } - /** - * Commit Transaction - */ protected function _transCommit(): bool { return sqlsrv_commit($this->connID); } - /** - * Rollback Transaction - */ protected function _transRollback(): bool { return sqlsrv_rollback($this->connID); diff --git a/system/Database/SQLite3/Connection.php b/system/Database/SQLite3/Connection.php index a78fca8c8b65..23ca0eaa5c35 100644 --- a/system/Database/SQLite3/Connection.php +++ b/system/Database/SQLite3/Connection.php @@ -39,7 +39,7 @@ class Connection extends BaseConnection /** * Identifier escape character * - * @var string + * @var list|string */ public $escapeChar = '`'; @@ -119,11 +119,6 @@ public function connect(bool $persistent = false) } } - /** - * Close the database connection. - * - * @return void - */ protected function _close() { $this->connID->close(); @@ -198,11 +193,6 @@ protected function _escapeString(string $str): string return $this->connID->escapeString($str); } - /** - * Generates the SQL for listing tables in a platform-dependent manner. - * - * @param string|null $tableName If $tableName is provided will return only this table if exists. - */ protected function _listTables(bool $prefixLimit = false, ?string $tableName = null): string { if ((string) $tableName !== '') { @@ -218,11 +208,6 @@ protected function _listTables(bool $prefixLimit = false, ?string $tableName = n : ''); } - /** - * Generates a platform-specific query string so that the column names can be fetched. - * - * @param string|TableName $table - */ protected function _listColumns($table = ''): string { if ($table instanceof TableName) { @@ -281,10 +266,6 @@ public function getFieldNames($tableName) } /** - * Returns an array of objects with field data - * - * @return list - * * @throws DatabaseException */ protected function _fieldData(string $table): array @@ -319,10 +300,6 @@ protected function _fieldData(string $table): array } /** - * Returns an array of objects with index data - * - * @return array - * * @throws DatabaseException */ protected function _indexData(string $table): array @@ -375,11 +352,6 @@ protected function _indexData(string $table): array return $retVal; } - /** - * Returns an array of objects with Foreign key data - * - * @return array - */ protected function _foreignKeyData(string $table): array { if (! $this->supportsForeignKeys()) { @@ -446,25 +418,16 @@ public function insertID(): int return $this->connID->lastInsertRowID(); } - /** - * Begin Transaction - */ protected function _transBegin(): bool { return $this->connID->exec('BEGIN TRANSACTION'); } - /** - * Commit Transaction - */ protected function _transCommit(): bool { return $this->connID->exec('END TRANSACTION'); } - /** - * Rollback Transaction - */ protected function _transRollback(): bool { return $this->connID->exec('ROLLBACK'); diff --git a/tests/system/Database/Live/EscapeTest.php b/tests/system/Database/Live/EscapeTest.php index adc5d414e34e..b3c27601ac42 100644 --- a/tests/system/Database/Live/EscapeTest.php +++ b/tests/system/Database/Live/EscapeTest.php @@ -13,6 +13,7 @@ namespace CodeIgniter\Database\Live; +use CodeIgniter\Database\MySQLi\Connection as MySQLiConnection; use CodeIgniter\Database\RawSql; use CodeIgniter\I18n\Time; use CodeIgniter\Test\CIUnitTestCase; @@ -100,6 +101,8 @@ public function testEscapeLikeStringStringable(): void public function testEscapeLikeStringDirect(): void { if ($this->db->DBDriver === 'MySQLi') { + $this->assertInstanceOf(MySQLiConnection::class, $this->db); + $expected = "SHOW COLUMNS FROM brands WHERE column LIKE 'wild\\_chars%'"; $sql = "SHOW COLUMNS FROM brands WHERE column LIKE '" . $this->db->escapeLikeStringDirect('wild_chars') . "%'"; diff --git a/tests/system/Database/Live/GetVersionTest.php b/tests/system/Database/Live/GetVersionTest.php index 93678e3b8356..cb4e5c1f5386 100644 --- a/tests/system/Database/Live/GetVersionTest.php +++ b/tests/system/Database/Live/GetVersionTest.php @@ -13,6 +13,7 @@ namespace CodeIgniter\Database\Live; +use CodeIgniter\Database\MySQLi\Connection as MySQLiConnection; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\DatabaseTestTrait; use PHPUnit\Framework\Attributes\Group; @@ -30,6 +31,7 @@ final class GetVersionTest extends CIUnitTestCase public function testGetVersion(): void { if ($this->db->DBDriver === 'MySQLi') { + $this->assertInstanceOf(MySQLiConnection::class, $this->db); $this->db->mysqli = false; } diff --git a/tests/system/Database/Live/MySQLi/FoundRowsTest.php b/tests/system/Database/Live/MySQLi/FoundRowsTest.php index b39f8999085d..122af23b24cd 100644 --- a/tests/system/Database/Live/MySQLi/FoundRowsTest.php +++ b/tests/system/Database/Live/MySQLi/FoundRowsTest.php @@ -13,6 +13,7 @@ namespace CodeIgniter\Database\Live\MySQLi; +use CodeIgniter\Database\MySQLi\Connection as MySQLiConnection; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\DatabaseTestTrait; use Config\Database; @@ -56,6 +57,7 @@ public function testEnableFoundRows(): void $db1 = Database::connect($this->tests); + $this->assertInstanceOf(MySQLiConnection::class, $db1); $this->assertTrue($db1->foundRows); } @@ -65,6 +67,7 @@ public function testDisableFoundRows(): void $db1 = Database::connect($this->tests); + $this->assertInstanceOf(MySQLiConnection::class, $db1); $this->assertFalse($db1->foundRows); } diff --git a/tests/system/Database/Live/MySQLi/NumberNativeTest.php b/tests/system/Database/Live/MySQLi/NumberNativeTest.php index 3834c4c3f9b0..c419cd6e8e01 100644 --- a/tests/system/Database/Live/MySQLi/NumberNativeTest.php +++ b/tests/system/Database/Live/MySQLi/NumberNativeTest.php @@ -13,6 +13,7 @@ namespace CodeIgniter\Database\Live\MySQLi; +use CodeIgniter\Database\MySQLi\Connection as MySQLiConnection; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\DatabaseTestTrait; use Config\Database; @@ -54,6 +55,7 @@ public function testEnableNumberNative(): void $this->markTestSkipped('Only MySQLi can complete this test.'); } + $this->assertInstanceOf(MySQLiConnection::class, $db1); $this->assertTrue($db1->numberNative); } @@ -67,6 +69,7 @@ public function testDisableNumberNative(): void $this->markTestSkipped('Only MySQLi can complete this test.'); } + $this->assertInstanceOf(MySQLiConnection::class, $db1); $this->assertFalse($db1->numberNative); } diff --git a/tests/system/Database/Live/OCI8/CallStoredProcedureTest.php b/tests/system/Database/Live/OCI8/CallStoredProcedureTest.php index 32c9efbf0624..8404e2378ae2 100644 --- a/tests/system/Database/Live/OCI8/CallStoredProcedureTest.php +++ b/tests/system/Database/Live/OCI8/CallStoredProcedureTest.php @@ -13,6 +13,7 @@ namespace CodeIgniter\Database\Live\OCI8; +use CodeIgniter\Database\OCI8\Connection as OCI8Connection; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\DatabaseTestTrait; use PHPUnit\Framework\Attributes\Group; @@ -38,6 +39,8 @@ protected function setUp(): void public function testCallPackageProcedure(): void { + $this->assertInstanceOf(OCI8Connection::class, $this->db); + $result = '0'; $this->db->storedProcedure('calculator.plus', [ @@ -60,6 +63,8 @@ public function testCallPackageProcedure(): void public function testCallStoredProcedure(): void { + $this->assertInstanceOf(OCI8Connection::class, $this->db); + $result = '0'; $this->db->storedProcedure('plus', [ @@ -82,6 +87,8 @@ public function testCallStoredProcedure(): void public function testCallStoredProcedureForCursor(): void { + $this->assertInstanceOf(OCI8Connection::class, $this->db); + $result = $this->db->getCursor(); $this->db->storedProcedure('one', [ diff --git a/tests/system/Database/Live/OrderTest.php b/tests/system/Database/Live/OrderTest.php index 1451222b5ceb..521078e79e18 100644 --- a/tests/system/Database/Live/OrderTest.php +++ b/tests/system/Database/Live/OrderTest.php @@ -13,6 +13,7 @@ namespace CodeIgniter\Database\Live; +use CodeIgniter\Database\SQLSRV\Connection as SQLSRVConnection; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\DatabaseTestTrait; use PHPUnit\Framework\Attributes\Group; @@ -84,6 +85,8 @@ public function testOrderRandom(): void if ($this->db->DBDriver === 'MySQLi') { $key = 'RAND()'; } elseif ($this->db->DBDriver === 'SQLSRV') { + $this->assertInstanceOf(SQLSRVConnection::class, $this->db); + $key = 'NEWID()'; $table = '"' . $this->db->getDatabase() . '"."' . $this->db->schema . '".' . $table; } elseif ($this->db->DBDriver === 'OCI8') { diff --git a/tests/system/Database/Live/PreparedQueryTest.php b/tests/system/Database/Live/PreparedQueryTest.php index 304269969a2d..5561b310a814 100644 --- a/tests/system/Database/Live/PreparedQueryTest.php +++ b/tests/system/Database/Live/PreparedQueryTest.php @@ -17,6 +17,7 @@ use CodeIgniter\Database\Exceptions\DatabaseException; use CodeIgniter\Database\Query; use CodeIgniter\Database\ResultInterface; +use CodeIgniter\Database\SQLSRV\Connection as SQLSRVConnection; use CodeIgniter\Exceptions\BadMethodCallException; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\DatabaseTestTrait; @@ -76,6 +77,8 @@ public function testPrepareReturnsPreparedQuery(): void } if ($this->db->DBDriver === 'SQLSRV') { + $this->assertInstanceOf(SQLSRVConnection::class, $this->db); + $database = $this->db->getDatabase(); $expected = "INSERT INTO {$ec}{$database}{$ec}.{$ec}{$this->db->schema}{$ec}.{$ec}{$pre}user{$ec} ({$ec}name{$ec},{$ec}email{$ec},{$ec}country{$ec}) VALUES ({$placeholders})"; } else { diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index b3302ee9448e..a6bf6b71991c 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,4 +1,4 @@ -# total 654 errors +# total 607 errors includes: - argument.type.neon diff --git a/utils/phpstan-baseline/method.notFound.neon b/utils/phpstan-baseline/method.notFound.neon index 432b04269975..5fbb5963bf85 100644 --- a/utils/phpstan-baseline/method.notFound.neon +++ b/utils/phpstan-baseline/method.notFound.neon @@ -1,4 +1,4 @@ -# total 32 errors +# total 27 errors parameters: ignoreErrors: @@ -22,21 +22,6 @@ parameters: count: 2 path: ../../tests/system/Commands/Utilities/Routes/FilterFinderTest.php - - - message: '#^Call to an undefined method CodeIgniter\\Database\\BaseConnection\:\:escapeLikeStringDirect\(\)\.$#' - count: 1 - path: ../../tests/system/Database/Live/EscapeTest.php - - - - message: '#^Call to an undefined method CodeIgniter\\Database\\BaseConnection\:\:getCursor\(\)\.$#' - count: 1 - path: ../../tests/system/Database/Live/OCI8/CallStoredProcedureTest.php - - - - message: '#^Call to an undefined method CodeIgniter\\Database\\BaseConnection\:\:storedProcedure\(\)\.$#' - count: 3 - path: ../../tests/system/Database/Live/OCI8/CallStoredProcedureTest.php - - message: '#^Call to an undefined method CodeIgniter\\HTTP\\ResponseInterface\:\:pretend\(\)\.$#' count: 3 diff --git a/utils/phpstan-baseline/missingType.iterableValue.neon b/utils/phpstan-baseline/missingType.iterableValue.neon index 6777cc2472c3..a70bd3c72915 100644 --- a/utils/phpstan-baseline/missingType.iterableValue.neon +++ b/utils/phpstan-baseline/missingType.iterableValue.neon @@ -1,4 +1,4 @@ -# total 470 errors +# total 440 errors parameters: ignoreErrors: @@ -317,116 +317,6 @@ parameters: count: 1 path: ../../system/DataConverter/DataConverter.php - - - message: '#^Class CodeIgniter\\Database\\BaseConnection has PHPDoc tag @property\-read for property \$aliasedTables with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - - - message: '#^Class CodeIgniter\\Database\\BaseConnection has PHPDoc tag @property\-read for property \$dateFormat with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - - - message: '#^Class CodeIgniter\\Database\\BaseConnection has PHPDoc tag @property\-read for property \$encrypt with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - - - message: '#^Class CodeIgniter\\Database\\BaseConnection has PHPDoc tag @property\-read for property \$failover with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - - - message: '#^Class CodeIgniter\\Database\\BaseConnection has PHPDoc tag @property\-read for property \$reservedIdentifiers with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - - - message: '#^Method CodeIgniter\\Database\\BaseConnection\:\:__construct\(\) has parameter \$params with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - - - message: '#^Method CodeIgniter\\Database\\BaseConnection\:\:callFunction\(\) has parameter \$params with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - - - message: '#^Method CodeIgniter\\Database\\BaseConnection\:\:escapeIdentifiers\(\) has parameter \$item with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - - - message: '#^Method CodeIgniter\\Database\\BaseConnection\:\:escapeIdentifiers\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - - - message: '#^Method CodeIgniter\\Database\\BaseConnection\:\:escape\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - - - message: '#^Method CodeIgniter\\Database\\BaseConnection\:\:foreignKeyDataToObjects\(\) has parameter \$data with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - - - message: '#^Method CodeIgniter\\Database\\BaseConnection\:\:prepare\(\) has parameter \$options with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - - - message: '#^Method CodeIgniter\\Database\\BaseConnection\:\:protectIdentifiers\(\) has parameter \$item with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - - - message: '#^Method CodeIgniter\\Database\\BaseConnection\:\:protectIdentifiers\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - - - message: '#^Method CodeIgniter\\Database\\BaseConnection\:\:setAliasedTables\(\) has parameter \$aliases with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - - - message: '#^Method CodeIgniter\\Database\\BaseConnection\:\:table\(\) has parameter \$tableName with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - - - message: '#^Property CodeIgniter\\Database\\BaseConnection\:\:\$dataCache type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - - - message: '#^Property CodeIgniter\\Database\\BaseConnection\:\:\$encrypt type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - - - message: '#^Property CodeIgniter\\Database\\BaseConnection\:\:\$escapeChar type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - - - message: '#^Property CodeIgniter\\Database\\BaseConnection\:\:\$failover type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - - - message: '#^Property CodeIgniter\\Database\\BaseConnection\:\:\$pregEscapeChar type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - - - message: '#^Property CodeIgniter\\Database\\BaseConnection\:\:\$reservedIdentifiers type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/BaseConnection.php - - message: '#^Method CodeIgniter\\Database\\BasePreparedQuery\:\:_execute\(\) has parameter \$data with no value type specified in iterable type array\.$#' count: 1 @@ -487,21 +377,6 @@ parameters: count: 1 path: ../../system/Database/Config.php - - - message: '#^Method CodeIgniter\\Database\\ConnectionInterface\:\:callFunction\(\) has parameter \$params with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/ConnectionInterface.php - - - - message: '#^Method CodeIgniter\\Database\\ConnectionInterface\:\:escape\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/ConnectionInterface.php - - - - message: '#^Method CodeIgniter\\Database\\ConnectionInterface\:\:table\(\) has parameter \$tableName with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/ConnectionInterface.php - - message: '#^Method CodeIgniter\\Database\\Database\:\:initDriver\(\) has parameter \$argument with no value type specified in iterable type array\.$#' count: 1 @@ -582,21 +457,6 @@ parameters: count: 1 path: ../../system/Database/MySQLi/Utils.php - - - message: '#^Method CodeIgniter\\Database\\OCI8\\Connection\:\:bindParams\(\) has parameter \$params with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/OCI8/Connection.php - - - - message: '#^Method CodeIgniter\\Database\\OCI8\\Connection\:\:storedProcedure\(\) has parameter \$params with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/OCI8/Connection.php - - - - message: '#^Property CodeIgniter\\Database\\OCI8\\Connection\:\:\$reservedIdentifiers type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/OCI8/Connection.php - - message: '#^Method CodeIgniter\\Database\\OCI8\\PreparedQuery\:\:_execute\(\) has parameter \$data with no value type specified in iterable type array\.$#' count: 1 @@ -612,11 +472,6 @@ parameters: count: 1 path: ../../system/Database/OCI8/Utils.php - - - message: '#^Method CodeIgniter\\Database\\Postgre\\Connection\:\:escape\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/Postgre/Connection.php - - message: '#^Method CodeIgniter\\Database\\Postgre\\PreparedQuery\:\:_execute\(\) has parameter \$data with no value type specified in iterable type array\.$#' count: 1 @@ -657,11 +512,6 @@ parameters: count: 1 path: ../../system/Database/Query.php - - - message: '#^Method CodeIgniter\\Database\\SQLSRV\\Connection\:\:__construct\(\) has parameter \$params with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Database/SQLSRV/Connection.php - - message: '#^Method CodeIgniter\\Database\\SQLSRV\\PreparedQuery\:\:_execute\(\) has parameter \$data with no value type specified in iterable type array\.$#' count: 1 diff --git a/utils/phpstan-baseline/property.notFound.neon b/utils/phpstan-baseline/property.notFound.neon index ebd40c7f58a3..13dd11a84ac9 100644 --- a/utils/phpstan-baseline/property.notFound.neon +++ b/utils/phpstan-baseline/property.notFound.neon @@ -1,32 +1,7 @@ -# total 28 errors +# total 21 errors parameters: ignoreErrors: - - - message: '#^Access to an undefined property CodeIgniter\\Database\\BaseConnection\:\:\$mysqli\.$#' - count: 1 - path: ../../tests/system/Database/Live/GetVersionTest.php - - - - message: '#^Access to an undefined property CodeIgniter\\Database\\BaseConnection\:\:\$foundRows\.$#' - count: 2 - path: ../../tests/system/Database/Live/MySQLi/FoundRowsTest.php - - - - message: '#^Access to an undefined property CodeIgniter\\Database\\BaseConnection\:\:\$numberNative\.$#' - count: 2 - path: ../../tests/system/Database/Live/MySQLi/NumberNativeTest.php - - - - message: '#^Access to an undefined property CodeIgniter\\Database\\BaseConnection\:\:\$schema\.$#' - count: 1 - path: ../../tests/system/Database/Live/OrderTest.php - - - - message: '#^Access to an undefined property CodeIgniter\\Database\\BaseConnection\:\:\$schema\.$#' - count: 1 - path: ../../tests/system/Database/Live/PreparedQueryTest.php - - message: '#^Access to an undefined property CodeIgniter\\Database\\BaseConnection\:\:\$schema\.$#' count: 2 diff --git a/utils/phpstan-baseline/property.phpDocType.neon b/utils/phpstan-baseline/property.phpDocType.neon index 5b7e09269507..275166c25508 100644 --- a/utils/phpstan-baseline/property.phpDocType.neon +++ b/utils/phpstan-baseline/property.phpDocType.neon @@ -1,12 +1,7 @@ -# total 22 errors +# total 17 errors parameters: ignoreErrors: - - - message: '#^PHPDoc type string of property CodeIgniter\\Database\\MySQLi\\Connection\:\:\$escapeChar is not the same as PHPDoc type array\|string of overridden property CodeIgniter\\Database\\BaseConnection\\:\:\$escapeChar\.$#' - count: 1 - path: ../../system/Database/MySQLi/Connection.php - - message: '#^PHPDoc type string of property CodeIgniter\\Database\\MySQLi\\Utils\:\:\$listDatabases is not the same as PHPDoc type bool\|string of overridden property CodeIgniter\\Database\\BaseUtils\:\:\$listDatabases\.$#' count: 1 @@ -17,21 +12,11 @@ parameters: count: 1 path: ../../system/Database/MySQLi/Utils.php - - - message: '#^PHPDoc type string of property CodeIgniter\\Database\\OCI8\\Connection\:\:\$escapeChar is not the same as PHPDoc type array\|string of overridden property CodeIgniter\\Database\\BaseConnection\\:\:\$escapeChar\.$#' - count: 1 - path: ../../system/Database/OCI8/Connection.php - - message: '#^PHPDoc type string of property CodeIgniter\\Database\\OCI8\\Utils\:\:\$listDatabases is not the same as PHPDoc type bool\|string of overridden property CodeIgniter\\Database\\BaseUtils\:\:\$listDatabases\.$#' count: 1 path: ../../system/Database/OCI8/Utils.php - - - message: '#^PHPDoc type string of property CodeIgniter\\Database\\Postgre\\Connection\:\:\$escapeChar is not the same as PHPDoc type array\|string of overridden property CodeIgniter\\Database\\BaseConnection\\:\:\$escapeChar\.$#' - count: 1 - path: ../../system/Database/Postgre/Connection.php - - message: '#^PHPDoc type string of property CodeIgniter\\Database\\Postgre\\Utils\:\:\$listDatabases is not the same as PHPDoc type bool\|string of overridden property CodeIgniter\\Database\\BaseUtils\:\:\$listDatabases\.$#' count: 1 @@ -42,11 +27,6 @@ parameters: count: 1 path: ../../system/Database/Postgre/Utils.php - - - message: '#^PHPDoc type string of property CodeIgniter\\Database\\SQLSRV\\Connection\:\:\$escapeChar is not the same as PHPDoc type array\|string of overridden property CodeIgniter\\Database\\BaseConnection\\:\:\$escapeChar\.$#' - count: 1 - path: ../../system/Database/SQLSRV/Connection.php - - message: '#^PHPDoc type string of property CodeIgniter\\Database\\SQLSRV\\Utils\:\:\$listDatabases is not the same as PHPDoc type bool\|string of overridden property CodeIgniter\\Database\\BaseUtils\:\:\$listDatabases\.$#' count: 1 @@ -57,11 +37,6 @@ parameters: count: 1 path: ../../system/Database/SQLSRV/Utils.php - - - message: '#^PHPDoc type string of property CodeIgniter\\Database\\SQLite3\\Connection\:\:\$escapeChar is not the same as PHPDoc type array\|string of overridden property CodeIgniter\\Database\\BaseConnection\\:\:\$escapeChar\.$#' - count: 1 - path: ../../system/Database/SQLite3/Connection.php - - message: '#^PHPDoc type string of property CodeIgniter\\Database\\SQLite3\\Utils\:\:\$optimizeTable is not the same as PHPDoc type bool\|string of overridden property CodeIgniter\\Database\\BaseUtils\:\:\$optimizeTable\.$#' count: 1