diff --git a/system/Common.php b/system/Common.php index 7e49231c6a18..11c95e1b9c57 100644 --- a/system/Common.php +++ b/system/Common.php @@ -216,9 +216,19 @@ function config(string $name, bool $getShared = true) /** * Simpler way to create a new Cookie instance. * - * @param string $name Name of the cookie - * @param string $value Value of the cookie - * @param array $options Array of options to be passed to the cookie + * @param string $name Name of the cookie + * @param string $value Value of the cookie + * @param array{ + * prefix?: string, + * max-age?: int|numeric-string, + * expires?: DateTimeInterface|int|string, + * path?: string, + * domain?: string, + * secure?: bool, + * httponly?: bool, + * samesite?: string, + * raw?: bool + * } $options Cookie configuration options * * @throws CookieException */ @@ -352,7 +362,27 @@ function csp_script_nonce(): string * If $getShared === false then a new connection instance will be provided, * otherwise it will all calls will return the same instance. * - * @param array|ConnectionInterface|string|null $db + * @param array{ + * DSN?: string, + * hostname?: string, + * username?: string, + * password?: string, + * database?: string, + * DBDriver?: 'MySQLi'|'OCI8'|'Postgre'|'SQLite3'|'SQLSRV', + * DBPrefix?: string, + * pConnect?: bool, + * DBDebug?: bool, + * charset?: string, + * DBCollat?: string, + * swapPre?: string, + * encrypt?: bool, + * compress?: bool, + * strictOn?: bool, + * failover?: array, + * port?: int, + * dateFormat?: array, + * foreignKeys?: bool + * }|ConnectionInterface|string|null $db * * @return BaseConnection */ @@ -402,13 +432,13 @@ function env(string $key, $default = null) * If $data is an array, then it loops over it, escaping each * 'value' of the key/value pairs. * - * @param array|string $data - * @param 'attr'|'css'|'html'|'js'|'raw'|'url' $context - * @param string|null $encoding Current encoding for escaping. - * If not UTF-8, we convert strings from this encoding - * pre-escaping and back to this encoding post-escaping. + * @param array|string>|string $data + * @param 'attr'|'css'|'html'|'js'|'raw'|'url' $context + * @param string|null $encoding Current encoding for escaping. + * If not UTF-8, we convert strings from this encoding + * pre-escaping and back to this encoding post-escaping. * - * @return array|string + * @return ($data is string ? string : array|string>) * * @throws InvalidArgumentException */ @@ -560,7 +590,7 @@ function function_usable(string $functionName): bool * 2. {namespace}/Helpers * 3. system/Helpers * - * @param array|string $filenames + * @param list|string $filenames * * @throws FileNotFoundException */ diff --git a/system/Helpers/cookie_helper.php b/system/Helpers/cookie_helper.php index 18239fe2ebff..fb1c1f366fed 100644 --- a/system/Helpers/cookie_helper.php +++ b/system/Helpers/cookie_helper.php @@ -24,16 +24,29 @@ * * Accepts seven parameters, or you can submit an associative * array in the first parameter containing all the values. + * ['', 'value', 'expire', '', '', '', '', '', 'name'] * - * @param array|Cookie|string $name Cookie name / array containing binds / Cookie object - * @param string $value The value of the cookie - * @param int $expire The number of seconds until expiration - * @param string $domain For site-wide cookie. Usually: .yourdomain.com - * @param string $path The cookie path - * @param string $prefix The cookie prefix ('': the default prefix) - * @param bool|null $secure True makes the cookie secure - * @param bool|null $httpOnly True makes the cookie accessible via http(s) only (no javascript) - * @param string|null $sameSite The cookie SameSite value + * @param array{ + * name?: string, + * value?: string, + * prefix?: string, + * max-age?: int|numeric-string, + * expire?: DateTimeInterface|int|string, + * path?: string, + * domain?: string, + * secure?: bool, + * httponly?: bool, + * samesite?: string, + * raw?: bool + * }|Cookie|string $name Cookie name / array containing binds / Cookie object + * @param string $value The value of the cookie + * @param int $expire The number of seconds until expiration + * @param string $domain For site-wide cookie. Usually: .yourdomain.com + * @param string $path The cookie path + * @param string $prefix The cookie prefix ('': the default prefix) + * @param bool|null $secure True makes the cookie secure + * @param bool|null $httpOnly True makes the cookie accessible via http(s) only (no javascript) + * @param string|null $sameSite The cookie SameSite value * * @see \CodeIgniter\HTTP\Response::setCookie() */ @@ -62,7 +75,7 @@ function set_cookie( * '': the prefix in Config\Cookie * null: no prefix * - * @return array|string|null + * @return array|string|null * * @see \CodeIgniter\HTTP\IncomingRequest::getCookie() */ diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index 715ea3051735..77b8b7b16465 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -243,13 +243,13 @@ public function testEscapeWithDifferentEncodings(): void public function testEscapeBadContext(): void { $this->expectException('InvalidArgumentException'); - esc(['width' => '800', 'height' => '600'], 'bogus'); + esc(['width' => '800', 'height' => '600'], 'bogus'); // @phpstan-ignore argument.type } public function testEscapeBadContextZero(): void { $this->expectException('InvalidArgumentException'); - esc('