Skip to content

Commit

Permalink
Merge pull request #8983 from paulbalandan/connection-types
Browse files Browse the repository at this point in the history
fix: return and param types of BaseConnection
  • Loading branch information
paulbalandan authored Jun 22, 2024
2 parents 53bfdef + abfcba7 commit 4e68814
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 79 deletions.
72 changes: 0 additions & 72 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -2083,24 +2083,12 @@
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseConnection.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:_fieldData\\(\\) return type has no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseConnection.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:callFunction\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseConnection.php',
];
$ignoreErrors[] = [
// identifier: missingType.return
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:close\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseConnection.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:escape\\(\\) has parameter \\$str with no value type specified in iterable type array\\.$#',
Expand Down Expand Up @@ -2131,24 +2119,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseConnection.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:getFieldNames\\(\\) return type has no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseConnection.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:getForeignKeyData\\(\\) return type has no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseConnection.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:listTables\\(\\) return type has no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseConnection.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:prepare\\(\\) has parameter \\$func with no signature specified for Closure\\.$#',
Expand Down Expand Up @@ -2191,12 +2161,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseConnection.php',
];
$ignoreErrors[] = [
// identifier: missingType.return
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:transOff\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseConnection.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Property CodeIgniter\\\\Database\\\\BaseConnection\\:\\:\\$aliasedTables type has no value type specified in iterable type array\\.$#',
Expand Down Expand Up @@ -3355,12 +3319,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Database/Postgre/Connection.php',
];
$ignoreErrors[] = [
// identifier: missingType.return
'message' => '#^Method CodeIgniter\\\\Database\\\\Postgre\\\\Connection\\:\\:convertDSN\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/Postgre/Connection.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\Postgre\\\\Connection\\:\\:escape\\(\\) has parameter \\$str with no value type specified in iterable type array\\.$#',
Expand Down Expand Up @@ -3967,12 +3925,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Database/SQLite3/Connection.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\SQLite3\\\\Connection\\:\\:getFieldNames\\(\\) return type has no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/SQLite3/Connection.php',
];
$ignoreErrors[] = [
// identifier: booleanNot.exprNotBoolean
'message' => '#^Only booleans are allowed in a negated boolean, string given\\.$#',
Expand Down Expand Up @@ -9613,24 +9565,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Test/Mock/MockConnection.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Test\\\\Mock\\\\MockConnection\\:\\:_fieldData\\(\\) return type has no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Test/Mock/MockConnection.php',
];
$ignoreErrors[] = [
// identifier: missingType.return
'message' => '#^Method CodeIgniter\\\\Test\\\\Mock\\\\MockConnection\\:\\:shouldReturn\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Test/Mock/MockConnection.php',
];
$ignoreErrors[] = [
// identifier: missingType.parameter
'message' => '#^Method CodeIgniter\\\\Test\\\\Mock\\\\MockConnection\\:\\:shouldReturn\\(\\) has parameter \\$return with no type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Test/Mock/MockConnection.php',
];
$ignoreErrors[] = [
// identifier: method.childReturnType
'message' => '#^Return type \\(array\\{code\\: int\\|string\\|null, message\\: string\\|null\\}\\) of method CodeIgniter\\\\Test\\\\Mock\\\\MockConnection\\:\\:error\\(\\) should be covariant with return type \\(array\\<string, int\\|string\\>\\) of method CodeIgniter\\\\Database\\\\ConnectionInterface\\<object\\|resource,object\\|resource\\>\\:\\:error\\(\\)$#',
Expand Down Expand Up @@ -9661,12 +9595,6 @@
'count' => 2,
'path' => __DIR__ . '/system/Test/Mock/MockConnection.php',
];
$ignoreErrors[] = [
// identifier: method.childReturnType
'message' => '#^Return type \\(mixed\\) of method CodeIgniter\\\\Test\\\\Mock\\\\MockConnection\\:\\:setDatabase\\(\\) should be covariant with return type \\(bool\\) of method CodeIgniter\\\\Database\\\\ConnectionInterface\\<object\\|resource,object\\|resource\\>\\:\\:setDatabase\\(\\)$#',
'count' => 2,
'path' => __DIR__ . '/system/Test/Mock/MockConnection.php',
];
$ignoreErrors[] = [
// identifier: missingType.return
'message' => '#^Method CodeIgniter\\\\Test\\\\Mock\\\\MockEvents\\:\\:getEventsFile\\(\\) has no return type specified\\.$#',
Expand Down
15 changes: 11 additions & 4 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,8 @@ public function initialize()

/**
* Close the database connection.
*
* @return void
*/
public function close()
{
Expand Down Expand Up @@ -736,6 +738,8 @@ public function simpleQuery(string $sql)
* Disable Transactions
*
* This permits transactions to be disabled at run-time.
*
* @return void
*/
public function transOff()
{
Expand Down Expand Up @@ -1454,7 +1458,7 @@ protected function getDriverFunctionPrefix(): string
/**
* Returns an array of table names
*
* @return array|false
* @return false|list<string>
*
* @throws DatabaseException
*/
Expand All @@ -1481,6 +1485,7 @@ public function listTables(bool $constrainByPrefix = false)
$query = $this->query($sql);

foreach ($query->getResultArray() as $row) {
/** @var string $table */
$table = $row['table_name'] ?? $row['TABLE_NAME'] ?? $row[array_key_first($row)];

$this->dataCache['table_names'][] = $table;
Expand Down Expand Up @@ -1531,7 +1536,7 @@ public function tableExists(string $tableName, bool $cached = true): bool
/**
* Fetch Field Names
*
* @return array|false
* @return false|list<string>
*
* @throws DatabaseException
*/
Expand Down Expand Up @@ -1608,7 +1613,7 @@ public function getIndexData(string $table)
/**
* Returns an object with foreign key data
*
* @return array
* @return array<string, stdClass>
*/
public function getForeignKeyData(string $table)
{
Expand Down Expand Up @@ -1769,7 +1774,9 @@ abstract protected function _listColumns(string $table = '');
/**
* Platform-specific field data information.
*
* @see getFieldData()
* @see getFieldData()
*
* @return list<stdClass>
*/
abstract protected function _fieldData(string $table): array;

Expand Down
2 changes: 2 additions & 0 deletions system/Database/MySQLi/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ 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 void
*/
public function reconnect()
{
Expand Down
4 changes: 4 additions & 0 deletions system/Database/Postgre/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public function connect(bool $persistent = false)

/**
* Converts the DSN with semicolon syntax.
*
* @return void
*/
private function convertDSN()
{
Expand Down Expand Up @@ -143,6 +145,8 @@ private function convertDSN()
/**
* Keep or establish the connection if no queries have been sent for
* a length of time exceeding the server's idle timeout.
*
* @return void
*/
public function reconnect()
{
Expand Down
2 changes: 2 additions & 0 deletions system/Database/SQLSRV/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ public function getAllErrorMessages(): string
/**
* Keep or establish the connection if no queries have been sent for
* a length of time exceeding the server's idle timeout.
*
* @return void
*/
public function reconnect()
{
Expand Down
7 changes: 6 additions & 1 deletion system/Database/SQLite3/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class Connection extends BaseConnection
*/
protected $busyTimeout;

/**
* @return void
*/
public function initialize()
{
parent::initialize();
Expand Down Expand Up @@ -101,6 +104,8 @@ 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 void
*/
public function reconnect()
{
Expand Down Expand Up @@ -211,7 +216,7 @@ protected function _listColumns(string $table = ''): string
}

/**
* @return array|false
* @return false|list<string>
*
* @throws DatabaseException
*/
Expand Down
9 changes: 7 additions & 2 deletions system/Test/Mock/MockConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class MockConnection extends BaseConnection
public $database;
public $lastQuery;

/**
* @param mixed $return
*
* @return $this
*/
public function shouldReturn(string $method, $return)
{
$this->returnValues[$method] = $return;
Expand Down Expand Up @@ -127,13 +132,13 @@ public function reconnect(): bool
/**
* Select a specific database table to use.
*
* @return mixed
* @return bool
*/
public function setDatabase(string $databaseName)
{
$this->database = $databaseName;

return $this;
return true;
}

/**
Expand Down

0 comments on commit 4e68814

Please sign in to comment.