From fa06a8bf0c12396d88d791a7d9f186493e20db38 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 22 Apr 2024 08:53:27 +0900 Subject: [PATCH 01/10] fix: incorrect Security exception message This is a server side misconfiguration, not a client error. --- system/HTTP/ResponseTrait.php | 2 +- system/Language/en/Security.php | 1 + system/Security/Exceptions/SecurityException.php | 10 ++++++++++ tests/system/HTTP/ResponseSendTest.php | 5 +---- user_guide_src/source/changelogs/v4.5.2.rst | 2 ++ 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/system/HTTP/ResponseTrait.php b/system/HTTP/ResponseTrait.php index 2d4295116807..45f07d186170 100644 --- a/system/HTTP/ResponseTrait.php +++ b/system/HTTP/ResponseTrait.php @@ -670,7 +670,7 @@ private function dispatchCookies(): void foreach ($this->cookieStore->display() as $cookie) { if ($cookie->isSecure() && ! $request->isSecure()) { - throw SecurityException::forDisallowedAction(); + throw SecurityException::forInsecureCookie(); } $name = $cookie->getPrefixedName(); diff --git a/system/Language/en/Security.php b/system/Language/en/Security.php index 145abaab71e7..fd906e378a29 100644 --- a/system/Language/en/Security.php +++ b/system/Language/en/Security.php @@ -14,6 +14,7 @@ // Security language settings return [ 'disallowedAction' => 'The action you requested is not allowed.', + 'insecureCookie' => 'Attempted to send a secure cookie over a non-secure connection.', // @deprecated 'invalidSameSite' => 'The SameSite value must be None, Lax, Strict, or a blank string. Given: "{0}"', diff --git a/system/Security/Exceptions/SecurityException.php b/system/Security/Exceptions/SecurityException.php index 16383fc25bfc..ed1d76825036 100644 --- a/system/Security/Exceptions/SecurityException.php +++ b/system/Security/Exceptions/SecurityException.php @@ -20,6 +20,7 @@ class SecurityException extends FrameworkException implements HTTPExceptionInter { /** * Throws when some specific action is not allowed. + * This is used for CSRF protection. * * @return static */ @@ -28,6 +29,15 @@ public static function forDisallowedAction() return new static(lang('Security.disallowedAction'), 403); } + /** + * Throws if a secure cookie is dispatched when the current connection is not + * secure. + */ + public static function forInsecureCookie(): static + { + return new static(lang('Security.insecureCookie')); + } + /** * Throws when the source string contains invalid UTF-8 characters. * diff --git a/tests/system/HTTP/ResponseSendTest.php b/tests/system/HTTP/ResponseSendTest.php index a4cc67765d3d..6159ee1140ba 100644 --- a/tests/system/HTTP/ResponseSendTest.php +++ b/tests/system/HTTP/ResponseSendTest.php @@ -162,14 +162,11 @@ public function testRedirectResponseCookies(): void /** * Make sure secure cookies are not sent with HTTP request - * - * @ runInSeparateProcess - * @ preserveGlobalState disabled */ public function testDoNotSendUnSecureCookie(): void { $this->expectException(SecurityException::class); - $this->expectExceptionMessage('The action you requested is not allowed'); + $this->expectExceptionMessage('Attempted to send a secure cookie over a non-secure connection.'); $request = $this->createMock(IncomingRequest::class); $request->method('isSecure')->willReturn(false); diff --git a/user_guide_src/source/changelogs/v4.5.2.rst b/user_guide_src/source/changelogs/v4.5.2.rst index d578360b720a..8824d3c72b96 100644 --- a/user_guide_src/source/changelogs/v4.5.2.rst +++ b/user_guide_src/source/changelogs/v4.5.2.rst @@ -18,6 +18,8 @@ BREAKING Message Changes *************** +- Added ``Security.insecureCookie`` message. + ******* Changes ******* From 7e8ebbcda98516e91526b7749f61634b48437c14 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Fri, 19 Apr 2024 17:02:44 +0700 Subject: [PATCH 02/10] docs: @param BaseBuilder.php --- system/Database/BaseBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php index 1f0807cdbbde..62916eeaa63b 100644 --- a/system/Database/BaseBuilder.php +++ b/system/Database/BaseBuilder.php @@ -2865,7 +2865,7 @@ public function deleteBatch($set = null, $constraints = null, int $batchSize = 1 * * @param string $table Protected table name * @param list $keys QBKeys - * @paramst> $values QBSet + * @param list $values QBSet */ protected function _deleteBatch(string $table, array $keys, array $values): string { From 590793e139ea326e79659319adfa5bbf7b91727e Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Fri, 19 Apr 2024 17:41:32 +0700 Subject: [PATCH 03/10] docs: specify phpdoc BaseBuilder --- phpstan-baseline.php | 98 +++++---------------------------- system/Database/BaseBuilder.php | 14 +++-- 2 files changed, 23 insertions(+), 89 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index caaad61d6e84..a7f3f149999b 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -1791,36 +1791,11 @@ 'count' => 1, 'path' => __DIR__ . '/system/Database/BaseBuilder.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:_deleteBatch\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/BaseBuilder.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:_insert\\(\\) has parameter \\$keys with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/BaseBuilder.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:_insert\\(\\) has parameter \\$unescapedKeys with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/BaseBuilder.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:_like\\(\\) has parameter \\$field with no value type specified in iterable type array\\.$#', 'count' => 1, 'path' => __DIR__ . '/system/Database/BaseBuilder.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:_replace\\(\\) has parameter \\$keys with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/BaseBuilder.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:_replace\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/BaseBuilder.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:_update\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#', 'count' => 1, @@ -2206,6 +2181,11 @@ 'count' => 1, 'path' => __DIR__ . '/system/Database/BaseBuilder.php', ]; +$ignoreErrors[] = [ + 'message' => '#^Parameter \\#3 \\.\\.\\.\\$arrays of function array_map expects array, int\\|string given\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/system/Database/BaseBuilder.php', +]; $ignoreErrors[] = [ 'message' => '#^Property CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:\\$QBFrom type has no value type specified in iterable type array\\.$#', 'count' => 1, @@ -3121,21 +3101,6 @@ 'count' => 3, 'path' => __DIR__ . '/system/Database/OCI8/Builder.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\OCI8\\\\Builder\\:\\:_deleteBatch\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/OCI8/Builder.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\OCI8\\\\Builder\\:\\:_replace\\(\\) has parameter \\$keys with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/OCI8/Builder.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\OCI8\\\\Builder\\:\\:_replace\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/OCI8/Builder.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\Database\\\\OCI8\\\\Builder\\:\\:_update\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#', 'count' => 1, @@ -3156,6 +3121,11 @@ 'count' => 1, 'path' => __DIR__ . '/system/Database/OCI8/Builder.php', ]; +$ignoreErrors[] = [ + 'message' => '#^Parameter \\#3 \\.\\.\\.\\$arrays of function array_map expects array, int\\|string given\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/system/Database/OCI8/Builder.php', +]; $ignoreErrors[] = [ 'message' => '#^Property CodeIgniter\\\\Database\\\\OCI8\\\\Builder\\:\\:\\$randomKeyword type has no value type specified in iterable type array\\.$#', 'count' => 1, @@ -3317,27 +3287,17 @@ 'path' => __DIR__ . '/system/Database/Postgre/Builder.php', ]; $ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\Postgre\\\\Builder\\:\\:_deleteBatch\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/Postgre/Builder.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\Postgre\\\\Builder\\:\\:_insert\\(\\) has parameter \\$keys with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/Postgre/Builder.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\Postgre\\\\Builder\\:\\:_insert\\(\\) has parameter \\$unescapedKeys with no value type specified in iterable type array\\.$#', + 'message' => '#^Method CodeIgniter\\\\Database\\\\Postgre\\\\Builder\\:\\:_update\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#', 'count' => 1, 'path' => __DIR__ . '/system/Database/Postgre/Builder.php', ]; $ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\Postgre\\\\Builder\\:\\:_update\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#', + 'message' => '#^Method CodeIgniter\\\\Database\\\\Postgre\\\\Builder\\:\\:replace\\(\\) has parameter \\$set with no value type specified in iterable type array\\.$#', 'count' => 1, 'path' => __DIR__ . '/system/Database/Postgre/Builder.php', ]; $ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\Postgre\\\\Builder\\:\\:replace\\(\\) has parameter \\$set with no value type specified in iterable type array\\.$#', + 'message' => '#^Parameter \\#3 \\.\\.\\.\\$arrays of function array_map expects array, int\\|string given\\.$#', 'count' => 1, 'path' => __DIR__ . '/system/Database/Postgre/Builder.php', ]; @@ -3676,26 +3636,6 @@ 'count' => 9, 'path' => __DIR__ . '/system/Database/SQLSRV/Builder.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\SQLSRV\\\\Builder\\:\\:_insert\\(\\) has parameter \\$keys with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/SQLSRV/Builder.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\SQLSRV\\\\Builder\\:\\:_insert\\(\\) has parameter \\$unescapedKeys with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/SQLSRV/Builder.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\SQLSRV\\\\Builder\\:\\:_replace\\(\\) has parameter \\$keys with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/SQLSRV/Builder.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\SQLSRV\\\\Builder\\:\\:_replace\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/SQLSRV/Builder.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\Database\\\\SQLSRV\\\\Builder\\:\\:_update\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#', 'count' => 1, @@ -3907,17 +3847,7 @@ 'path' => __DIR__ . '/system/Database/SQLite3/Builder.php', ]; $ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\SQLite3\\\\Builder\\:\\:_deleteBatch\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/SQLite3/Builder.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\SQLite3\\\\Builder\\:\\:_replace\\(\\) has parameter \\$keys with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/SQLite3/Builder.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\SQLite3\\\\Builder\\:\\:_replace\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#', + 'message' => '#^Parameter \\#3 \\.\\.\\.\\$arrays of function array_map expects array, int\\|string given\\.$#', 'count' => 1, 'path' => __DIR__ . '/system/Database/SQLite3/Builder.php', ]; diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php index 62916eeaa63b..4c80edc0aa39 100644 --- a/system/Database/BaseBuilder.php +++ b/system/Database/BaseBuilder.php @@ -2376,7 +2376,9 @@ protected function validateInsert(): bool /** * Generates a platform-specific insert string from the supplied data * - * @param string $table Protected table name + * @param string $table Protected table name + * @param list $keys QBKeys + * @param list $unescapedKeys QBSet */ protected function _insert(string $table, array $keys, array $unescapedKeys): string { @@ -2416,7 +2418,9 @@ public function replace(?array $set = null) /** * Generates a platform-specific replace string from the supplied data * - * @param string $table Protected table name + * @param string $table Protected table name + * @param list $keys QBKeys + * @param list $values QBSet */ protected function _replace(string $table, array $keys, array $values): string { @@ -2863,9 +2867,9 @@ public function deleteBatch($set = null, $constraints = null, int $batchSize = 1 * * @used-by batchExecute() * - * @param string $table Protected table name - * @param list $keys QBKeys - * @param list $values QBSet + * @param string $table Protected table name + * @param list $keys QBKeys + * @param list $values QBSet */ protected function _deleteBatch(string $table, array $keys, array $values): string { From abfb7f6a2d3ffec3d33875abce76684753b6c372 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Mon, 22 Apr 2024 09:23:24 +0700 Subject: [PATCH 04/10] docs: generate baseline --- phpstan-baseline.php | 20 -------------------- system/Database/BaseBuilder.php | 11 ++++++----- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index a7f3f149999b..3260e4b6f8cb 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -1796,11 +1796,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Database/BaseBuilder.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:_update\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/BaseBuilder.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:_whereIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#', 'count' => 1, @@ -3101,11 +3096,6 @@ 'count' => 3, 'path' => __DIR__ . '/system/Database/OCI8/Builder.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\OCI8\\\\Builder\\:\\:_update\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/OCI8/Builder.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\Database\\\\OCI8\\\\Builder\\:\\:fieldsFromQuery\\(\\) return type has no value type specified in iterable type array\\.$#', 'count' => 1, @@ -3286,11 +3276,6 @@ 'count' => 7, 'path' => __DIR__ . '/system/Database/Postgre/Builder.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\Postgre\\\\Builder\\:\\:_update\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/Postgre/Builder.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\Database\\\\Postgre\\\\Builder\\:\\:replace\\(\\) has parameter \\$set with no value type specified in iterable type array\\.$#', 'count' => 1, @@ -3636,11 +3621,6 @@ 'count' => 9, 'path' => __DIR__ . '/system/Database/SQLSRV/Builder.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\SQLSRV\\\\Builder\\:\\:_update\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/SQLSRV/Builder.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\Database\\\\SQLSRV\\\\Builder\\:\\:fieldsFromQuery\\(\\) return type has no value type specified in iterable type array\\.$#', 'count' => 1, diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php index 4c80edc0aa39..d552580703ec 100644 --- a/system/Database/BaseBuilder.php +++ b/system/Database/BaseBuilder.php @@ -2377,8 +2377,8 @@ protected function validateInsert(): bool * Generates a platform-specific insert string from the supplied data * * @param string $table Protected table name - * @param list $keys QBKeys - * @param list $unescapedKeys QBSet + * @param list $keys Keys of QBSet + * @param list $unescapedKeys Values of QBSet */ protected function _insert(string $table, array $keys, array $unescapedKeys): string { @@ -2419,8 +2419,8 @@ public function replace(?array $set = null) * Generates a platform-specific replace string from the supplied data * * @param string $table Protected table name - * @param list $keys QBKeys - * @param list $values QBSet + * @param list $keys Keys of QBSet + * @param list $values Values of QBSet */ protected function _replace(string $table, array $keys, array $values): string { @@ -2516,7 +2516,8 @@ public function update($set = null, $where = null, ?int $limit = null): bool /** * Generates a platform-specific update string from the supplied data * - * @param string $table Protected table name + * @param string $table Protected table name + * @param array $values QBSet */ protected function _update(string $table, array $values): string { From 715dff050873b7bf1183ef24e2af0678bf22659d Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Mon, 22 Apr 2024 09:45:41 +0700 Subject: [PATCH 05/10] docs: _like phpdocs --- phpstan-baseline.php | 5 ----- system/Database/BaseBuilder.php | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 3260e4b6f8cb..3fdb6424df80 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -1791,11 +1791,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Database/BaseBuilder.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:_like\\(\\) has parameter \\$field with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Database/BaseBuilder.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:_whereIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#', 'count' => 1, diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php index d552580703ec..36a6ba7d73b9 100644 --- a/system/Database/BaseBuilder.php +++ b/system/Database/BaseBuilder.php @@ -1090,7 +1090,7 @@ public function orNotHavingLike($field, string $match = '', string $side = 'both * @used-by notHavingLike() * @used-by orNotHavingLike() * - * @param array|RawSql|string $field + * @param list|RawSql|string $field * * @return $this */ From d7a5a878cc4383570b50a7f11fe1f4d844778651 Mon Sep 17 00:00:00 2001 From: obozdag Date: Mon, 22 Apr 2024 19:55:09 +0200 Subject: [PATCH 06/10] docs: Change connecting and Query Builder link names in database/examples.rst Change connecting and Query Builder link names in database/examples.rst --- user_guide_src/source/database/examples.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/database/examples.rst b/user_guide_src/source/database/examples.rst index a88608e85651..f7dfc4b85891 100644 --- a/user_guide_src/source/database/examples.rst +++ b/user_guide_src/source/database/examples.rst @@ -24,7 +24,7 @@ your :doc:`configuration ` settings: Once loaded the class is ready to be used as described below. .. note:: If all your pages require database access you can connect - automatically. See the :doc:`connecting ` page for details. + automatically. See the :doc:`Connecting to a Database ` page for details. Standard Query With Multiple Results (Object Version) ===================================================== @@ -66,7 +66,7 @@ Standard Insert Query Builder Query =================== -The :doc:`Query Builder Pattern ` gives you a simplified +The :doc:`Query Builder ` gives you a simplified means of retrieving data: .. literalinclude:: examples/007.php From a53ae657b644475adb8bc869532abab71b3def1d Mon Sep 17 00:00:00 2001 From: obozdag Date: Mon, 22 Apr 2024 20:07:30 +0200 Subject: [PATCH 07/10] docs: Change page header in database/examples.rst Change page header in database/examples.rst --- user_guide_src/source/database/examples.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/user_guide_src/source/database/examples.rst b/user_guide_src/source/database/examples.rst index f7dfc4b85891..43a2bdceac62 100644 --- a/user_guide_src/source/database/examples.rst +++ b/user_guide_src/source/database/examples.rst @@ -1,6 +1,6 @@ -################################## -Database Quick Start: Example Code -################################## +########################### +Quick Start: Usage Examples +########################### The following page contains example code showing how the database class is used. For complete details please read the individual pages From dde1de7ebcaa825c59cada173a16b312957a9f61 Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 23 Apr 2024 11:35:48 +0900 Subject: [PATCH 08/10] test: add test for Model returns Entity with Casts --- tests/_support/Entity/UserWithCasts.php | 23 +++++++++++++++ .../Models/UserEntityWithCastsModel.php | 29 +++++++++++++++++++ tests/system/Models/FindModelTest.php | 19 ++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 tests/_support/Entity/UserWithCasts.php create mode 100644 tests/_support/Models/UserEntityWithCastsModel.php diff --git a/tests/_support/Entity/UserWithCasts.php b/tests/_support/Entity/UserWithCasts.php new file mode 100644 index 000000000000..cfe1981fa3fa --- /dev/null +++ b/tests/_support/Entity/UserWithCasts.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace Tests\Support\Entity; + +use CodeIgniter\Entity\Entity; + +class UserWithCasts extends Entity +{ + protected $casts = [ + 'email' => 'json', + ]; +} diff --git a/tests/_support/Models/UserEntityWithCastsModel.php b/tests/_support/Models/UserEntityWithCastsModel.php new file mode 100644 index 000000000000..2ea32c88f842 --- /dev/null +++ b/tests/_support/Models/UserEntityWithCastsModel.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace Tests\Support\Models; + +use CodeIgniter\Model; +use Tests\Support\Entity\UserWithCasts; + +class UserEntityWithCastsModel extends Model +{ + protected $table = 'user'; + protected $allowedFields = [ + 'name', + 'email', + 'country', + 'deleted_at', + ]; + protected $returnType = UserWithCasts::class; +} diff --git a/tests/system/Models/FindModelTest.php b/tests/system/Models/FindModelTest.php index d27fcb791bb3..24946b4e2965 100644 --- a/tests/system/Models/FindModelTest.php +++ b/tests/system/Models/FindModelTest.php @@ -15,8 +15,10 @@ use CodeIgniter\Database\Exceptions\DataException; use CodeIgniter\Exceptions\ModelException; +use Tests\Support\Entity\UserWithCasts; use Tests\Support\Models\JobModel; use Tests\Support\Models\SecondaryModel; +use Tests\Support\Models\UserEntityWithCastsModel; use Tests\Support\Models\UserModel; /** @@ -32,6 +34,23 @@ public function testFindReturnsRow(): void $this->assertSame('Musician', $this->model->find(4)->name); } + public function testFindReturnsEntityWithCasts(): void + { + $this->createModel(UserEntityWithCastsModel::class); + $this->model->builder()->truncate(); + $user = new UserWithCasts([ + 'name' => 'John Smith', + 'email' => ['foo@example.jp', 'bar@example.com'], + 'country' => 'US', + ]); + $id = $this->model->insert($user, true); + + $user = $this->model->find($id); + + $this->assertSame('John Smith', $user->name); + $this->assertSame(['foo@example.jp', 'bar@example.com'], $user->email); + } + public function testFindReturnsMultipleRows(): void { $this->createModel(JobModel::class); From c6e17476f319df179d0b18c967e7732f039abb22 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Tue, 23 Apr 2024 11:24:25 +0700 Subject: [PATCH 09/10] Update system/Database/BaseBuilder.php Co-authored-by: kenjis --- system/Database/BaseBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php index 36a6ba7d73b9..c20f59920ff2 100644 --- a/system/Database/BaseBuilder.php +++ b/system/Database/BaseBuilder.php @@ -1090,7 +1090,7 @@ public function orNotHavingLike($field, string $match = '', string $side = 'both * @used-by notHavingLike() * @used-by orNotHavingLike() * - * @param list|RawSql|string $field + * @param array|RawSql|string $field * * @return $this */ From 8427340e5344c20c2bd6ef0584030f6e69f31457 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 25 Apr 2024 16:49:12 +0900 Subject: [PATCH 10/10] test: add @var for PHPStan ------ ----------------------------------------------------- Line tests/system/Models/FindModelTest.php ------ ----------------------------------------------------- 50 Cannot access property $name on array. 51 Cannot access property $email on array. ------ ----------------------------------------------------- --- tests/system/Models/FindModelTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/system/Models/FindModelTest.php b/tests/system/Models/FindModelTest.php index 24946b4e2965..b0b835bc1067 100644 --- a/tests/system/Models/FindModelTest.php +++ b/tests/system/Models/FindModelTest.php @@ -45,6 +45,7 @@ public function testFindReturnsEntityWithCasts(): void ]); $id = $this->model->insert($user, true); + /** @var UserWithCasts $user */ $user = $this->model->find($id); $this->assertSame('John Smith', $user->name);