Skip to content

Commit 4e68814

Browse files
authored
Merge pull request #8983 from paulbalandan/connection-types
fix: return and param types of BaseConnection
2 parents 53bfdef + abfcba7 commit 4e68814

File tree

7 files changed

+32
-79
lines changed

7 files changed

+32
-79
lines changed

phpstan-baseline.php

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,24 +2083,12 @@
20832083
'count' => 1,
20842084
'path' => __DIR__ . '/system/Database/BaseConnection.php',
20852085
];
2086-
$ignoreErrors[] = [
2087-
// identifier: missingType.iterableValue
2088-
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:_fieldData\\(\\) return type has no value type specified in iterable type array\\.$#',
2089-
'count' => 1,
2090-
'path' => __DIR__ . '/system/Database/BaseConnection.php',
2091-
];
20922086
$ignoreErrors[] = [
20932087
// identifier: missingType.iterableValue
20942088
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:callFunction\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#',
20952089
'count' => 1,
20962090
'path' => __DIR__ . '/system/Database/BaseConnection.php',
20972091
];
2098-
$ignoreErrors[] = [
2099-
// identifier: missingType.return
2100-
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:close\\(\\) has no return type specified\\.$#',
2101-
'count' => 1,
2102-
'path' => __DIR__ . '/system/Database/BaseConnection.php',
2103-
];
21042092
$ignoreErrors[] = [
21052093
// identifier: missingType.iterableValue
21062094
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:escape\\(\\) has parameter \\$str with no value type specified in iterable type array\\.$#',
@@ -2131,24 +2119,6 @@
21312119
'count' => 1,
21322120
'path' => __DIR__ . '/system/Database/BaseConnection.php',
21332121
];
2134-
$ignoreErrors[] = [
2135-
// identifier: missingType.iterableValue
2136-
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:getFieldNames\\(\\) return type has no value type specified in iterable type array\\.$#',
2137-
'count' => 1,
2138-
'path' => __DIR__ . '/system/Database/BaseConnection.php',
2139-
];
2140-
$ignoreErrors[] = [
2141-
// identifier: missingType.iterableValue
2142-
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:getForeignKeyData\\(\\) return type has no value type specified in iterable type array\\.$#',
2143-
'count' => 1,
2144-
'path' => __DIR__ . '/system/Database/BaseConnection.php',
2145-
];
2146-
$ignoreErrors[] = [
2147-
// identifier: missingType.iterableValue
2148-
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:listTables\\(\\) return type has no value type specified in iterable type array\\.$#',
2149-
'count' => 1,
2150-
'path' => __DIR__ . '/system/Database/BaseConnection.php',
2151-
];
21522122
$ignoreErrors[] = [
21532123
// identifier: missingType.callable
21542124
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:prepare\\(\\) has parameter \\$func with no signature specified for Closure\\.$#',
@@ -2191,12 +2161,6 @@
21912161
'count' => 1,
21922162
'path' => __DIR__ . '/system/Database/BaseConnection.php',
21932163
];
2194-
$ignoreErrors[] = [
2195-
// identifier: missingType.return
2196-
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:transOff\\(\\) has no return type specified\\.$#',
2197-
'count' => 1,
2198-
'path' => __DIR__ . '/system/Database/BaseConnection.php',
2199-
];
22002164
$ignoreErrors[] = [
22012165
// identifier: missingType.iterableValue
22022166
'message' => '#^Property CodeIgniter\\\\Database\\\\BaseConnection\\:\\:\\$aliasedTables type has no value type specified in iterable type array\\.$#',
@@ -3355,12 +3319,6 @@
33553319
'count' => 1,
33563320
'path' => __DIR__ . '/system/Database/Postgre/Connection.php',
33573321
];
3358-
$ignoreErrors[] = [
3359-
// identifier: missingType.return
3360-
'message' => '#^Method CodeIgniter\\\\Database\\\\Postgre\\\\Connection\\:\\:convertDSN\\(\\) has no return type specified\\.$#',
3361-
'count' => 1,
3362-
'path' => __DIR__ . '/system/Database/Postgre/Connection.php',
3363-
];
33643322
$ignoreErrors[] = [
33653323
// identifier: missingType.iterableValue
33663324
'message' => '#^Method CodeIgniter\\\\Database\\\\Postgre\\\\Connection\\:\\:escape\\(\\) has parameter \\$str with no value type specified in iterable type array\\.$#',
@@ -3967,12 +3925,6 @@
39673925
'count' => 1,
39683926
'path' => __DIR__ . '/system/Database/SQLite3/Connection.php',
39693927
];
3970-
$ignoreErrors[] = [
3971-
// identifier: missingType.iterableValue
3972-
'message' => '#^Method CodeIgniter\\\\Database\\\\SQLite3\\\\Connection\\:\\:getFieldNames\\(\\) return type has no value type specified in iterable type array\\.$#',
3973-
'count' => 1,
3974-
'path' => __DIR__ . '/system/Database/SQLite3/Connection.php',
3975-
];
39763928
$ignoreErrors[] = [
39773929
// identifier: booleanNot.exprNotBoolean
39783930
'message' => '#^Only booleans are allowed in a negated boolean, string given\\.$#',
@@ -9613,24 +9565,6 @@
96139565
'count' => 1,
96149566
'path' => __DIR__ . '/system/Test/Mock/MockConnection.php',
96159567
];
9616-
$ignoreErrors[] = [
9617-
// identifier: missingType.iterableValue
9618-
'message' => '#^Method CodeIgniter\\\\Test\\\\Mock\\\\MockConnection\\:\\:_fieldData\\(\\) return type has no value type specified in iterable type array\\.$#',
9619-
'count' => 1,
9620-
'path' => __DIR__ . '/system/Test/Mock/MockConnection.php',
9621-
];
9622-
$ignoreErrors[] = [
9623-
// identifier: missingType.return
9624-
'message' => '#^Method CodeIgniter\\\\Test\\\\Mock\\\\MockConnection\\:\\:shouldReturn\\(\\) has no return type specified\\.$#',
9625-
'count' => 1,
9626-
'path' => __DIR__ . '/system/Test/Mock/MockConnection.php',
9627-
];
9628-
$ignoreErrors[] = [
9629-
// identifier: missingType.parameter
9630-
'message' => '#^Method CodeIgniter\\\\Test\\\\Mock\\\\MockConnection\\:\\:shouldReturn\\(\\) has parameter \\$return with no type specified\\.$#',
9631-
'count' => 1,
9632-
'path' => __DIR__ . '/system/Test/Mock/MockConnection.php',
9633-
];
96349568
$ignoreErrors[] = [
96359569
// identifier: method.childReturnType
96369570
'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\\(\\)$#',
@@ -9661,12 +9595,6 @@
96619595
'count' => 2,
96629596
'path' => __DIR__ . '/system/Test/Mock/MockConnection.php',
96639597
];
9664-
$ignoreErrors[] = [
9665-
// identifier: method.childReturnType
9666-
'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\\(\\)$#',
9667-
'count' => 2,
9668-
'path' => __DIR__ . '/system/Test/Mock/MockConnection.php',
9669-
];
96709598
$ignoreErrors[] = [
96719599
// identifier: missingType.return
96729600
'message' => '#^Method CodeIgniter\\\\Test\\\\Mock\\\\MockEvents\\:\\:getEventsFile\\(\\) has no return type specified\\.$#',

system/Database/BaseConnection.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,8 @@ public function initialize()
477477

478478
/**
479479
* Close the database connection.
480+
*
481+
* @return void
480482
*/
481483
public function close()
482484
{
@@ -736,6 +738,8 @@ public function simpleQuery(string $sql)
736738
* Disable Transactions
737739
*
738740
* This permits transactions to be disabled at run-time.
741+
*
742+
* @return void
739743
*/
740744
public function transOff()
741745
{
@@ -1454,7 +1458,7 @@ protected function getDriverFunctionPrefix(): string
14541458
/**
14551459
* Returns an array of table names
14561460
*
1457-
* @return array|false
1461+
* @return false|list<string>
14581462
*
14591463
* @throws DatabaseException
14601464
*/
@@ -1481,6 +1485,7 @@ public function listTables(bool $constrainByPrefix = false)
14811485
$query = $this->query($sql);
14821486

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

14861491
$this->dataCache['table_names'][] = $table;
@@ -1531,7 +1536,7 @@ public function tableExists(string $tableName, bool $cached = true): bool
15311536
/**
15321537
* Fetch Field Names
15331538
*
1534-
* @return array|false
1539+
* @return false|list<string>
15351540
*
15361541
* @throws DatabaseException
15371542
*/
@@ -1608,7 +1613,7 @@ public function getIndexData(string $table)
16081613
/**
16091614
* Returns an object with foreign key data
16101615
*
1611-
* @return array
1616+
* @return array<string, stdClass>
16121617
*/
16131618
public function getForeignKeyData(string $table)
16141619
{
@@ -1769,7 +1774,9 @@ abstract protected function _listColumns(string $table = '');
17691774
/**
17701775
* Platform-specific field data information.
17711776
*
1772-
* @see getFieldData()
1777+
* @see getFieldData()
1778+
*
1779+
* @return list<stdClass>
17731780
*/
17741781
abstract protected function _fieldData(string $table): array;
17751782

system/Database/MySQLi/Connection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ public function connect(bool $persistent = false)
237237
/**
238238
* Keep or establish the connection if no queries have been sent for
239239
* a length of time exceeding the server's idle timeout.
240+
*
241+
* @return void
240242
*/
241243
public function reconnect()
242244
{

system/Database/Postgre/Connection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ public function connect(bool $persistent = false)
104104

105105
/**
106106
* Converts the DSN with semicolon syntax.
107+
*
108+
* @return void
107109
*/
108110
private function convertDSN()
109111
{
@@ -143,6 +145,8 @@ private function convertDSN()
143145
/**
144146
* Keep or establish the connection if no queries have been sent for
145147
* a length of time exceeding the server's idle timeout.
148+
*
149+
* @return void
146150
*/
147151
public function reconnect()
148152
{

system/Database/SQLSRV/Connection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ public function getAllErrorMessages(): string
164164
/**
165165
* Keep or establish the connection if no queries have been sent for
166166
* a length of time exceeding the server's idle timeout.
167+
*
168+
* @return void
167169
*/
168170
public function reconnect()
169171
{

system/Database/SQLite3/Connection.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class Connection extends BaseConnection
5555
*/
5656
protected $busyTimeout;
5757

58+
/**
59+
* @return void
60+
*/
5861
public function initialize()
5962
{
6063
parent::initialize();
@@ -101,6 +104,8 @@ public function connect(bool $persistent = false)
101104
/**
102105
* Keep or establish the connection if no queries have been sent for
103106
* a length of time exceeding the server's idle timeout.
107+
*
108+
* @return void
104109
*/
105110
public function reconnect()
106111
{
@@ -211,7 +216,7 @@ protected function _listColumns(string $table = ''): string
211216
}
212217

213218
/**
214-
* @return array|false
219+
* @return false|list<string>
215220
*
216221
* @throws DatabaseException
217222
*/

system/Test/Mock/MockConnection.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ class MockConnection extends BaseConnection
3838
public $database;
3939
public $lastQuery;
4040

41+
/**
42+
* @param mixed $return
43+
*
44+
* @return $this
45+
*/
4146
public function shouldReturn(string $method, $return)
4247
{
4348
$this->returnValues[$method] = $return;
@@ -127,13 +132,13 @@ public function reconnect(): bool
127132
/**
128133
* Select a specific database table to use.
129134
*
130-
* @return mixed
135+
* @return bool
131136
*/
132137
public function setDatabase(string $databaseName)
133138
{
134139
$this->database = $databaseName;
135140

136-
return $this;
141+
return true;
137142
}
138143

139144
/**

0 commit comments

Comments
 (0)