Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 41 additions & 11 deletions system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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<string, mixed>,
* port?: int,
* dateFormat?: array<string, string>,
* foreignKeys?: bool
* }|ConnectionInterface|string|null $db
*
* @return BaseConnection
*/
Expand Down Expand Up @@ -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<int|string, array<int|string, mixed>|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<int|string, array<int|string, mixed>|string>)
*
* @throws InvalidArgumentException
*/
Expand Down Expand Up @@ -560,7 +590,7 @@ function function_usable(string $functionName): bool
* 2. {namespace}/Helpers
* 3. system/Helpers
*
* @param array|string $filenames
* @param list<string>|string $filenames
*
* @throws FileNotFoundException
*/
Expand Down
33 changes: 23 additions & 10 deletions system/Helpers/cookie_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
*/
Expand Down Expand Up @@ -62,7 +75,7 @@ function set_cookie(
* '': the prefix in Config\Cookie
* null: no prefix
*
* @return array|string|null
* @return array<string, mixed>|string|null
*
* @see \CodeIgniter\HTTP\IncomingRequest::getCookie()
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/system/CommonFunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<script>', '0');
esc('<script>', '0'); // @phpstan-ignore argument.type
}

public function testEscapeArray(): void
Expand Down
12 changes: 1 addition & 11 deletions utils/phpstan-baseline/argument.type.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 90 errors
# total 88 errors

parameters:
ignoreErrors:
Expand Down Expand Up @@ -52,16 +52,6 @@ parameters:
count: 4
path: ../../tests/system/Commands/RoutesTest.php

-
message: '#^Parameter \#2 \$context of function esc expects ''attr''\|''css''\|''html''\|''js''\|''raw''\|''url'', ''0'' given\.$#'
count: 1
path: ../../tests/system/CommonFunctionsTest.php

-
message: '#^Parameter \#2 \$context of function esc expects ''attr''\|''css''\|''html''\|''js''\|''raw''\|''url'', ''bogus'' given\.$#'
count: 1
path: ../../tests/system/CommonFunctionsTest.php

-
message: '#^Parameter \#2 \$file of class CodeIgniter\\Config\\DotEnv constructor expects string, int given\.$#'
count: 1
Expand Down
2 changes: 1 addition & 1 deletion utils/phpstan-baseline/loader.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 2853 errors
# total 2844 errors
includes:
- argument.type.neon
- assign.propertyType.neon
Expand Down
37 changes: 1 addition & 36 deletions utils/phpstan-baseline/missingType.iterableValue.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 1423 errors
# total 1416 errors

parameters:
ignoreErrors:
Expand Down Expand Up @@ -342,31 +342,6 @@ parameters:
count: 1
path: ../../system/Common.php

-
message: '#^Function cookie\(\) has parameter \$options with no value type specified in iterable type array\.$#'
count: 1
path: ../../system/Common.php

-
message: '#^Function db_connect\(\) has parameter \$db with no value type specified in iterable type array\.$#'
count: 1
path: ../../system/Common.php

-
message: '#^Function esc\(\) has parameter \$data with no value type specified in iterable type array\.$#'
count: 1
path: ../../system/Common.php

-
message: '#^Function esc\(\) return type has no value type specified in iterable type array\.$#'
count: 1
path: ../../system/Common.php

-
message: '#^Function helper\(\) has parameter \$filenames with no value type specified in iterable type array\.$#'
count: 1
path: ../../system/Common.php

-
message: '#^Function log_message\(\) has parameter \$context with no value type specified in iterable type array\.$#'
count: 1
Expand Down Expand Up @@ -3732,16 +3707,6 @@ parameters:
count: 1
path: ../../system/Helpers/array_helper.php

-
message: '#^Function get_cookie\(\) return type has no value type specified in iterable type array\.$#'
count: 1
path: ../../system/Helpers/cookie_helper.php

-
message: '#^Function set_cookie\(\) has parameter \$name with no value type specified in iterable type array\.$#'
count: 1
path: ../../system/Helpers/cookie_helper.php

-
message: '#^Function directory_map\(\) return type has no value type specified in iterable type array\.$#'
count: 1
Expand Down
Loading