Skip to content

Improve mb detect encoding signature #4020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 2.1.x
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion resources/functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6318,7 +6318,8 @@
'mb_decode_mimeheader' => ['string', 'string'=>'string'],
'mb_decode_numericentity' => ['string', 'string'=>'string', 'convmap'=>'array', 'encoding'=>'string'],
'mb_detect_encoding' => ['string|false', 'str'=>'string', 'encoding_list='=>'mixed', 'strict='=>'bool'],
'mb_detect_order' => ['bool|list<non-falsy-string>', 'encoding_list='=>'non-empty-list<non-falsy-string>|non-falsy-string'],
'mb_detect_order' => ['bool', 'encoding_list'=>'non-empty-list<non-falsy-string>|non-falsy-string'],
'mb_detect_order\'1' => ['list<non-falsy-string>'],
'mb_encode_mimeheader' => ['string', 'str'=>'string', 'charset='=>'string', 'transfer_encoding='=>'string', 'linefeed='=>'string', 'indent='=>'int'],
'mb_encode_numericentity' => ['string', 'string'=>'string', 'convmap'=>'array', 'encoding='=>'string', 'is_hex='=>'bool'],
'mb_encoding_aliases' => ['list<non-falsy-string>|false', 'encoding'=>'string'],
Expand Down
3 changes: 2 additions & 1 deletion resources/functionMap_php80delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
'getenv\'1' => ['array<string, string>', 'varname='=>'null', 'local_only='=>'bool'],
'ldap_set_rebind_proc' => ['bool', 'ldap'=>'resource', 'callback'=>'?callable'],
'mb_decode_numericentity' => ['string|false', 'string'=>'string', 'convmap'=>'array', 'encoding='=>'string'],
'mb_detect_order' => ['bool|list<non-falsy-string>', 'encoding_list='=>'non-empty-list<non-falsy-string>|non-falsy-string|null'],
'mb_detect_order' => ['bool', 'encoding_list'=>'non-empty-list<non-falsy-string>|non-falsy-string'],
'mb_detect_order\'1' => ['list<non-falsy-string>', 'encoding_list='=>'null'],
'mb_encoding_aliases' => ['list<non-falsy-string>', 'encoding'=>'string'],
'mb_str_split' => ['list<string>', 'str'=>'string', 'split_length='=>'positive-int', 'encoding='=>'string'],
'mb_strlen' => ['0|positive-int', 'str'=>'string', 'encoding='=>'string'],
Expand Down
19 changes: 19 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-8922-php74.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php // lint < 8.0

namespace Bug8922PHP74;

use function PHPStan\Testing\assertType;

/**
* @param non-empty-list<non-falsy-string> $array
* @param non-falsy-string $string
* @param mixed $mixed
*/
function doSomething($array, $string, $mixed): void
{
assertType('list<non-falsy-string>', mb_detect_order());
assertType('bool', mb_detect_order(null));
assertType('bool', mb_detect_order($array));
assertType('bool', mb_detect_order($string));
assertType('bool', mb_detect_order($mixed));
}
19 changes: 19 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-8922.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php // lint >= 8.0

namespace Bug8922;

use function PHPStan\Testing\assertType;

/**
* @param non-empty-list<non-falsy-string> $array
* @param non-falsy-string $string
* @param mixed $mixed
*/
function doSomething($array, $string, $mixed): void
{
assertType('list<non-falsy-string>', mb_detect_order());
assertType('list<non-falsy-string>', mb_detect_order(null));
assertType('bool', mb_detect_order($array));
assertType('bool', mb_detect_order($string));
assertType('bool|list<non-falsy-string>', mb_detect_order($mixed));
}
15 changes: 15 additions & 0 deletions tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2248,6 +2248,21 @@ public function testBug12954(): void
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-12954.php'], []);
}

public function testBug8922(): void
{
$errors = [];
if (PHP_VERSION_ID < 80000) {
$errors[] = [
'Parameter #1 $encoding_list of function mb_detect_order expects non-empty-list<non-falsy-string>|non-falsy-string, null given.',
15,
'• Type #1 from the union: null is not a list.
• Type #1 from the union: null is empty.',
];
}

$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-8922.php'], $errors);
}

public function testBug13065(): void
{
$errors = [];
Expand Down
Loading