From 586c56c8912e71f5d53d5509c26dadc442593a41 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 14 Apr 2023 17:08:48 +0900 Subject: [PATCH 1/5] docs: remove type resource in @template It seems Psalm does not allow to use `resource` in @template type. See - https://github.com/codeigniter4/settings/pull/60#issuecomment-1414894845 - https://github.com/codeigniter4/shield/pull/195#issuecomment-1508037593 --- system/Database/BaseConnection.php | 4 ++-- system/Database/BasePreparedQuery.php | 6 +++--- system/Database/BaseResult.php | 4 ++-- system/Database/ConnectionInterface.php | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index 5f141b73c21c..670dd0494984 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -46,8 +46,8 @@ * @property bool $transFailure * @property bool $transStatus * - * @template TConnection of object|resource - * @template TResult of object|resource + * @template TConnection + * @template TResult * * @implements ConnectionInterface */ diff --git a/system/Database/BasePreparedQuery.php b/system/Database/BasePreparedQuery.php index 3253562f95a4..fa6da537a525 100644 --- a/system/Database/BasePreparedQuery.php +++ b/system/Database/BasePreparedQuery.php @@ -18,11 +18,11 @@ use ErrorException; /** - * @template TConnection of object|resource - * @template TStatement of object|resource - * @template TResult of object|resource * * @implements PreparedQueryInterface + * @template TConnection + * @template TStatement + * @template TResult */ abstract class BasePreparedQuery implements PreparedQueryInterface { diff --git a/system/Database/BaseResult.php b/system/Database/BaseResult.php index 6910aa98aea6..1ce7d7c8c592 100644 --- a/system/Database/BaseResult.php +++ b/system/Database/BaseResult.php @@ -15,10 +15,10 @@ use stdClass; /** - * @template TConnection of object|resource - * @template TResult of object|resource * * @implements ResultInterface + * @template TConnection + * @template TResult */ abstract class BaseResult implements ResultInterface { diff --git a/system/Database/ConnectionInterface.php b/system/Database/ConnectionInterface.php index 57fca79df428..85125eb1ae62 100644 --- a/system/Database/ConnectionInterface.php +++ b/system/Database/ConnectionInterface.php @@ -12,8 +12,8 @@ namespace CodeIgniter\Database; /** - * @template TConnection of object|resource - * @template TResult of object|resource + * @template TConnection + * @template TResult */ interface ConnectionInterface { From f7c5b7e3f0cc03803f741e2fdfd8a547a91f5282 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 14 Apr 2023 17:13:49 +0900 Subject: [PATCH 2/5] docs: remove unused @templete in interfaces --- system/Database/BasePreparedQuery.php | 4 +--- system/Database/BaseResult.php | 2 -- system/Database/PreparedQueryInterface.php | 7 +------ system/Database/ResultInterface.php | 4 ---- 4 files changed, 2 insertions(+), 15 deletions(-) diff --git a/system/Database/BasePreparedQuery.php b/system/Database/BasePreparedQuery.php index fa6da537a525..807936015881 100644 --- a/system/Database/BasePreparedQuery.php +++ b/system/Database/BasePreparedQuery.php @@ -18,8 +18,6 @@ use ErrorException; /** - * - * @implements PreparedQueryInterface * @template TConnection * @template TStatement * @template TResult @@ -111,7 +109,7 @@ abstract public function _prepare(string $sql, array $options = []); * prepared query. Upon success, will return a Results object. * * @return bool|ResultInterface - * @phpstan-return bool|ResultInterface + * @phpstan-return bool|ResultInterface * * @throws DatabaseException */ diff --git a/system/Database/BaseResult.php b/system/Database/BaseResult.php index 1ce7d7c8c592..d8867719c4e7 100644 --- a/system/Database/BaseResult.php +++ b/system/Database/BaseResult.php @@ -15,8 +15,6 @@ use stdClass; /** - * - * @implements ResultInterface * @template TConnection * @template TResult */ diff --git a/system/Database/PreparedQueryInterface.php b/system/Database/PreparedQueryInterface.php index 7dbd985f8802..87a22d971660 100644 --- a/system/Database/PreparedQueryInterface.php +++ b/system/Database/PreparedQueryInterface.php @@ -13,11 +13,6 @@ use BadMethodCallException; -/** - * @template TConnection of object|resource - * @template TStatement of object|resource - * @template TResult of object|resource - */ interface PreparedQueryInterface { /** @@ -25,7 +20,7 @@ interface PreparedQueryInterface * prepared query. Upon success, will return a Results object. * * @return bool|ResultInterface - * @phpstan-return bool|ResultInterface + * @phpstan-return bool|ResultInterface */ public function execute(...$data); diff --git a/system/Database/ResultInterface.php b/system/Database/ResultInterface.php index 9aa788aba307..1b23c6d024d1 100644 --- a/system/Database/ResultInterface.php +++ b/system/Database/ResultInterface.php @@ -13,10 +13,6 @@ use stdClass; -/** - * @template TConnection of object|resource - * @template TResult of object|resource - */ interface ResultInterface { /** From 372435da15dad2a97886f2fc574837aa592cbda6 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 14 Apr 2023 17:16:23 +0900 Subject: [PATCH 3/5] docs: fix @return type --- system/Database/BaseResult.php | 4 +++- system/Database/MySQLi/Result.php | 2 ++ system/Database/Postgre/Result.php | 2 ++ system/Database/SQLSRV/Result.php | 2 ++ system/Database/SQLite3/Result.php | 2 ++ system/Test/Mock/MockResult.php | 4 ++-- 6 files changed, 13 insertions(+), 3 deletions(-) diff --git a/system/Database/BaseResult.php b/system/Database/BaseResult.php index d8867719c4e7..f10411cd2534 100644 --- a/system/Database/BaseResult.php +++ b/system/Database/BaseResult.php @@ -497,6 +497,8 @@ abstract public function getFieldData(): array; /** * Frees the current result. + * + * @return void */ abstract public function freeResult(); @@ -523,7 +525,7 @@ abstract protected function fetchAssoc(); * * Overridden by child classes. * - * @return object + * @return Entity|false|object|stdClass */ abstract protected function fetchObject(string $className = 'stdClass'); } diff --git a/system/Database/MySQLi/Result.php b/system/Database/MySQLi/Result.php index d41cc24d3216..afe23486d7e8 100644 --- a/system/Database/MySQLi/Result.php +++ b/system/Database/MySQLi/Result.php @@ -103,6 +103,8 @@ public function getFieldData(): array /** * Frees the current result. + * + * @return void */ public function freeResult() { diff --git a/system/Database/Postgre/Result.php b/system/Database/Postgre/Result.php index 3617e2a399dc..84ee1514ec42 100644 --- a/system/Database/Postgre/Result.php +++ b/system/Database/Postgre/Result.php @@ -69,6 +69,8 @@ public function getFieldData(): array /** * Frees the current result. + * + * @return void */ public function freeResult() { diff --git a/system/Database/SQLSRV/Result.php b/system/Database/SQLSRV/Result.php index 0aa68b01e2ac..ea1117d3bc3f 100755 --- a/system/Database/SQLSRV/Result.php +++ b/system/Database/SQLSRV/Result.php @@ -103,6 +103,8 @@ public function getFieldData(): array /** * Frees the current result. + * + * @return void */ public function freeResult() { diff --git a/system/Database/SQLite3/Result.php b/system/Database/SQLite3/Result.php index 10c0ea00d232..b2175d9d198b 100644 --- a/system/Database/SQLite3/Result.php +++ b/system/Database/SQLite3/Result.php @@ -80,6 +80,8 @@ public function getFieldData(): array /** * Frees the current result. + * + * @return void */ public function freeResult() { diff --git a/system/Test/Mock/MockResult.php b/system/Test/Mock/MockResult.php index 689a1392ec14..b2e4b2ec2dcf 100644 --- a/system/Test/Mock/MockResult.php +++ b/system/Test/Mock/MockResult.php @@ -46,7 +46,7 @@ public function getFieldData(): array /** * Frees the current result. * - * @return mixed + * @return void */ public function freeResult() { @@ -59,7 +59,7 @@ public function freeResult() * * @param int $n * - * @return mixed + * @return bool */ public function dataSeek($n = 0) { From bd17c8f7eb6e0dad80d72c486588f2355ae4112e Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 14 Apr 2023 17:16:42 +0900 Subject: [PATCH 4/5] fix: MockResult::dataSeek() return type --- system/Database/OCI8/Result.php | 1 + system/Test/Mock/MockResult.php | 1 + 2 files changed, 2 insertions(+) diff --git a/system/Database/OCI8/Result.php b/system/Database/OCI8/Result.php index 68f663bf828a..63682e2a229c 100644 --- a/system/Database/OCI8/Result.php +++ b/system/Database/OCI8/Result.php @@ -13,6 +13,7 @@ use CodeIgniter\Database\BaseResult; use CodeIgniter\Entity\Entity; +use stdClass; /** * Result for OCI8 diff --git a/system/Test/Mock/MockResult.php b/system/Test/Mock/MockResult.php index b2e4b2ec2dcf..87654b1dd779 100644 --- a/system/Test/Mock/MockResult.php +++ b/system/Test/Mock/MockResult.php @@ -63,6 +63,7 @@ public function freeResult() */ public function dataSeek($n = 0) { + return true; } /** From 377ef3d6f9231aeb3952e9058d400efef04d1516 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 30 Apr 2023 11:37:13 +0900 Subject: [PATCH 5/5] docs: restore @template with no types --- system/Database/BasePreparedQuery.php | 4 +++- system/Database/BaseResult.php | 2 ++ system/Database/PreparedQueryInterface.php | 7 ++++++- system/Database/ResultInterface.php | 4 ++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/system/Database/BasePreparedQuery.php b/system/Database/BasePreparedQuery.php index 807936015881..bfc0a608ea05 100644 --- a/system/Database/BasePreparedQuery.php +++ b/system/Database/BasePreparedQuery.php @@ -21,6 +21,8 @@ * @template TConnection * @template TStatement * @template TResult + * + * @implements PreparedQueryInterface */ abstract class BasePreparedQuery implements PreparedQueryInterface { @@ -109,7 +111,7 @@ abstract public function _prepare(string $sql, array $options = []); * prepared query. Upon success, will return a Results object. * * @return bool|ResultInterface - * @phpstan-return bool|ResultInterface + * @phpstan-return bool|ResultInterface * * @throws DatabaseException */ diff --git a/system/Database/BaseResult.php b/system/Database/BaseResult.php index f10411cd2534..c5f603a28127 100644 --- a/system/Database/BaseResult.php +++ b/system/Database/BaseResult.php @@ -17,6 +17,8 @@ /** * @template TConnection * @template TResult + * + * @implements ResultInterface */ abstract class BaseResult implements ResultInterface { diff --git a/system/Database/PreparedQueryInterface.php b/system/Database/PreparedQueryInterface.php index 87a22d971660..7b55991835c8 100644 --- a/system/Database/PreparedQueryInterface.php +++ b/system/Database/PreparedQueryInterface.php @@ -13,6 +13,11 @@ use BadMethodCallException; +/** + * @template TConnection + * @template TStatement + * @template TResult + */ interface PreparedQueryInterface { /** @@ -20,7 +25,7 @@ interface PreparedQueryInterface * prepared query. Upon success, will return a Results object. * * @return bool|ResultInterface - * @phpstan-return bool|ResultInterface + * @phpstan-return bool|ResultInterface */ public function execute(...$data); diff --git a/system/Database/ResultInterface.php b/system/Database/ResultInterface.php index 1b23c6d024d1..c959a7cb2292 100644 --- a/system/Database/ResultInterface.php +++ b/system/Database/ResultInterface.php @@ -13,6 +13,10 @@ use stdClass; +/** + * @template TConnection + * @template TResult + */ interface ResultInterface { /**