Add template types to Connection

This commit is contained in:
John Paul E. Balandan, CPA 2022-10-20 22:40:04 +08:00
parent 763a5d94df
commit 62d5cf4a92
No known key found for this signature in database
GPG Key ID: FB7B51499BC27610
15 changed files with 55 additions and 155 deletions

View File

@ -106,87 +106,12 @@ parameters:
path: system/Database/Migration.php
-
message: "#^Cannot access property \\$errno on bool\\|object\\|resource\\.$#"
message: "#^Property CodeIgniter\\\\Database\\\\BaseConnection\\<mysqli\\|false\\>\\:\\:\\$strictOn \\(bool\\) in isset\\(\\) is not nullable\\.$#"
count: 1
path: system/Database/MySQLi/Connection.php
-
message: "#^Cannot access property \\$error on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/MySQLi/Connection.php
-
message: "#^Cannot access property \\$insert_id on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/MySQLi/Connection.php
-
message: "#^Cannot call method autocommit\\(\\) on bool\\|object\\|resource\\.$#"
count: 3
path: system/Database/MySQLi/Connection.php
-
message: "#^Cannot call method begin_transaction\\(\\) on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/MySQLi/Connection.php
-
message: "#^Cannot call method close\\(\\) on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/MySQLi/Connection.php
-
message: "#^Cannot call method commit\\(\\) on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/MySQLi/Connection.php
-
message: "#^Cannot call method more_results\\(\\) on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/MySQLi/Connection.php
-
message: "#^Cannot call method next_result\\(\\) on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/MySQLi/Connection.php
-
message: "#^Cannot call method query\\(\\) on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/MySQLi/Connection.php
-
message: "#^Cannot call method real_escape_string\\(\\) on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/MySQLi/Connection.php
-
message: "#^Cannot call method rollback\\(\\) on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/MySQLi/Connection.php
-
message: "#^Cannot call method select_db\\(\\) on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/MySQLi/Connection.php
-
message: "#^Cannot call method store_result\\(\\) on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/MySQLi/Connection.php
-
message: "#^Property CodeIgniter\\\\Database\\\\BaseConnection\\:\\:\\$strictOn \\(bool\\) in isset\\(\\) is not nullable\\.$#"
count: 1
path: system/Database/MySQLi/Connection.php
-
message: "#^Property CodeIgniter\\\\Database\\\\MySQLi\\\\Connection\\:\\:\\$mysqli \\(mysqli\\) in empty\\(\\) is not falsy\\.$#"
count: 1
path: system/Database/MySQLi/Connection.php
-
message: "#^Access to an undefined property CodeIgniter\\\\Database\\\\BaseConnection\\:\\:\\$mysqli\\.$#"
message: "#^Access to an undefined property CodeIgniter\\\\Database\\\\BaseConnection\\<mysqli\\|false\\>\\:\\:\\$mysqli\\.$#"
count: 3
path: system/Database/MySQLi/PreparedQuery.php
@ -245,61 +170,6 @@ parameters:
count: 13
path: system/Database/SQLSRV/Forge.php
-
message: "#^Cannot call method changes\\(\\) on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/SQLite3/Connection.php
-
message: "#^Cannot call method close\\(\\) on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/SQLite3/Connection.php
-
message: "#^Cannot call method escapeString\\(\\) on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/SQLite3/Connection.php
-
message: "#^Cannot call method exec\\(\\) on bool\\|object\\|resource\\.$#"
count: 4
path: system/Database/SQLite3/Connection.php
-
message: "#^Cannot call method lastErrorCode\\(\\) on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/SQLite3/Connection.php
-
message: "#^Cannot call method lastErrorMsg\\(\\) on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/SQLite3/Connection.php
-
message: "#^Cannot call method lastInsertRowID\\(\\) on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/SQLite3/Connection.php
-
message: "#^Cannot call method query\\(\\) on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/SQLite3/Connection.php
-
message: "#^Cannot call method lastErrorCode\\(\\) on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/SQLite3/PreparedQuery.php
-
message: "#^Cannot call method lastErrorMsg\\(\\) on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/SQLite3/PreparedQuery.php
-
message: "#^Cannot call method prepare\\(\\) on bool\\|object\\|resource\\.$#"
count: 1
path: system/Database/SQLite3/PreparedQuery.php
-
message: "#^Cannot call method columnName\\(\\) on object\\|resource\\|false\\.$#"
count: 2
@ -566,7 +436,7 @@ parameters:
path: system/Test/FeatureTestCase.php
-
message: "#^Cannot access property \\$insert_id on bool\\|object\\|resource\\.$#"
message: "#^Cannot access property \\$insert_id on object\\|resource\\|false\\.$#"
count: 1
path: system/Test/Mock/MockConnection.php

View File

@ -45,6 +45,10 @@ use Throwable;
* @property int $transDepth
* @property bool $transFailure
* @property bool $transStatus
*
* @template TConnection of false|object|resource
*
* @implements ConnectionInterface<TConnection>
*/
abstract class BaseConnection implements ConnectionInterface
{
@ -189,7 +193,8 @@ abstract class BaseConnection implements ConnectionInterface
/**
* Connection ID
*
* @var bool|object|resource
* @var false|object|resource
* @phpstan-var TConnection
*/
public $connID = false;
@ -457,7 +462,8 @@ abstract class BaseConnection implements ConnectionInterface
* get that connection. If you pass either alias in and only a single
* connection is present, it must return the sole connection.
*
* @return mixed
* @return false|object|resource
* @phpstan-return TConnection
*/
public function getConnection(?string $alias = null)
{

View File

@ -20,9 +20,10 @@ use ErrorException;
/**
* Base prepared query
*
* @template TConnection of false|object|resource
* @template TStatement of object|resource
*
* @implements PreparedQueryInterface<TStatement>
* @implements PreparedQueryInterface<TConnection, TStatement>
*/
abstract class BasePreparedQuery implements PreparedQueryInterface
{
@ -60,6 +61,7 @@ abstract class BasePreparedQuery implements PreparedQueryInterface
* A reference to the db connection to use.
*
* @var BaseConnection
* @phpstan-var BaseConnection<TConnection>
*/
protected $db;

View File

@ -13,27 +13,31 @@ namespace CodeIgniter\Database;
/**
* Interface ConnectionInterface
*
* @template TConnection of false|object|resource
*/
interface ConnectionInterface
{
/**
* Initializes the database connection/settings.
*
* @return mixed
* @return void
*/
public function initialize();
/**
* Connect to the database.
*
* @return mixed
* @return false|object|resource
* @phpstan-return TConnection
*/
public function connect(bool $persistent = false);
/**
* Create a persistent database connection.
*
* @return mixed
* @return false|object|resource
* @phpstan-return TConnection
*/
public function persistentConnect();
@ -41,7 +45,7 @@ interface ConnectionInterface
* 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();
@ -51,7 +55,8 @@ interface ConnectionInterface
* get that connection. If you pass either alias in and only a single
* connection is present, it must return the sole connection.
*
* @return mixed
* @return false|object|resource
* @phpstan-return TConnection
*/
public function getConnection(?string $alias = null);

View File

@ -14,13 +14,15 @@ namespace CodeIgniter\Database\MySQLi;
use CodeIgniter\Database\BaseConnection;
use CodeIgniter\Database\Exceptions\DatabaseException;
use LogicException;
use MySQLi;
use mysqli;
use mysqli_sql_exception;
use stdClass;
use Throwable;
/**
* Connection for MySQLi
*
* @extends BaseConnection<false|mysqli>
*/
class Connection extends BaseConnection
{
@ -54,7 +56,7 @@ class Connection extends BaseConnection
*
* Has to be preserved without being assigned to $conn_id.
*
* @var MySQLi
* @var false|mysqli
*/
public $mysqli;
@ -72,7 +74,7 @@ class Connection extends BaseConnection
/**
* Connect to the database.
*
* @return mixed
* @return false|mysqli
*
* @throws DatabaseException
*/

View File

@ -14,12 +14,13 @@ namespace CodeIgniter\Database\MySQLi;
use BadMethodCallException;
use CodeIgniter\Database\BasePreparedQuery;
use CodeIgniter\Database\Exceptions\DatabaseException;
use mysqli;
use mysqli_stmt;
/**
* Prepared query for MySQLi
*
* @extends BasePreparedQuery<mysqli_stmt>
* @extends BasePreparedQuery<false|mysqli, mysqli_stmt>
*/
class PreparedQuery extends BasePreparedQuery
{

View File

@ -20,6 +20,8 @@ use stdClass;
/**
* Connection for OCI8
*
* @extends BaseConnection<false|resource>
*/
class Connection extends BaseConnection implements ConnectionInterface
{
@ -113,7 +115,7 @@ class Connection extends BaseConnection implements ConnectionInterface
/**
* Connect to the database.
*
* @return mixed
* @return false|resource
*/
public function connect(bool $persistent = false)
{

View File

@ -19,7 +19,7 @@ use CodeIgniter\Database\PreparedQueryInterface;
/**
* Prepared query for OCI8
*
* @extends BasePreparedQuery<resource>
* @extends BasePreparedQuery<false|resource, resource>
*/
class PreparedQuery extends BasePreparedQuery implements PreparedQueryInterface
{

View File

@ -15,10 +15,13 @@ use CodeIgniter\Database\BaseConnection;
use CodeIgniter\Database\Exceptions\DatabaseException;
use CodeIgniter\Database\RawSql;
use ErrorException;
use PgSql\Connection as PgSqlConnection;
use stdClass;
/**
* Connection for Postgre
*
* @extends BaseConnection<false|PgSqlConnection>
*/
class Connection extends BaseConnection
{
@ -51,7 +54,8 @@ class Connection extends BaseConnection
/**
* Connect to the database.
*
* @return mixed
* @return false|resource
* @phpstan-return false|PgSqlConnection
*/
public function connect(bool $persistent = false)
{

View File

@ -15,11 +15,13 @@ use BadMethodCallException;
use CodeIgniter\Database\BasePreparedQuery;
use CodeIgniter\Database\Exceptions\DatabaseException;
use Exception;
use PgSql\Connection as PgSqlConnection;
use PgSql\Result as PgSqlResult;
/**
* Prepared query for Postgre
*
* @extends BasePreparedQuery<\PgSql\Result>
* @extends BasePreparedQuery<false|PgSqlConnection, PgSqlResult>
*/
class PreparedQuery extends BasePreparedQuery
{

View File

@ -16,6 +16,7 @@ use BadMethodCallException;
/**
* Prepared query interface
*
* @template TConnection of false|object|resource
* @template TStatement of object|resource
*/
interface PreparedQueryInterface

View File

@ -17,6 +17,8 @@ use stdClass;
/**
* Connection for SQLSRV
*
* @extends BaseConnection<false|resource>
*/
class Connection extends BaseConnection
{
@ -95,7 +97,7 @@ class Connection extends BaseConnection
/**
* Connect to the database.
*
* @return mixed
* @return false|resource
*
* @throws DatabaseException
*/

View File

@ -19,7 +19,7 @@ use Exception;
/**
* Prepared query for Postgre
*
* @extends BasePreparedQuery<resource>
* @extends BasePreparedQuery<false|resource, resource>
*/
class PreparedQuery extends BasePreparedQuery
{

View File

@ -21,6 +21,8 @@ use stdClass;
/**
* Connection for SQLite3
*
* @extends BaseConnection<SQLite3>
*/
class Connection extends BaseConnection
{
@ -55,7 +57,7 @@ class Connection extends BaseConnection
/**
* Connect to the database.
*
* @return mixed
* @return SQLite3
*
* @throws DatabaseException
*/
@ -153,7 +155,7 @@ class Connection extends BaseConnection
*/
protected function _escapeString(string $str): string
{
if (! $this->connID) {
if (! $this->connID instanceof SQLite3) {
$this->initialize();
}
@ -200,7 +202,7 @@ class Connection extends BaseConnection
return $this->dataCache['field_names'][$table];
}
if (empty($this->connID)) {
if (! $this->connID instanceof SQLite3) {
$this->initialize();
}

View File

@ -14,12 +14,13 @@ namespace CodeIgniter\Database\SQLite3;
use BadMethodCallException;
use CodeIgniter\Database\BasePreparedQuery;
use CodeIgniter\Database\Exceptions\DatabaseException;
use SQLite3;
use SQLite3Stmt;
/**
* Prepared query for SQLite3
*
* @extends BasePreparedQuery<SQLite3Stmt>
* @extends BasePreparedQuery<SQLite3, SQLite3Stmt>
*/
class PreparedQuery extends BasePreparedQuery
{