Skip to content

Commit b77ae75

Browse files
Improve mb detect encoding signature
1 parent a645445 commit b77ae75

File tree

5 files changed

+57
-2
lines changed

5 files changed

+57
-2
lines changed

resources/functionMap.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6318,7 +6318,8 @@
63186318
'mb_decode_mimeheader' => ['string', 'string'=>'string'],
63196319
'mb_decode_numericentity' => ['string', 'string'=>'string', 'convmap'=>'array', 'encoding'=>'string'],
63206320
'mb_detect_encoding' => ['string|false', 'str'=>'string', 'encoding_list='=>'mixed', 'strict='=>'bool'],
6321-
'mb_detect_order' => ['bool|list<non-falsy-string>', 'encoding_list='=>'non-empty-list<non-falsy-string>|non-falsy-string'],
6321+
'mb_detect_order' => ['bool', 'encoding_list'=>'non-empty-list<non-falsy-string>|non-falsy-string'],
6322+
'mb_detect_order\'1' => ['list<non-falsy-string>'],
63226323
'mb_encode_mimeheader' => ['string', 'str'=>'string', 'charset='=>'string', 'transfer_encoding='=>'string', 'linefeed='=>'string', 'indent='=>'int'],
63236324
'mb_encode_numericentity' => ['string', 'string'=>'string', 'convmap'=>'array', 'encoding='=>'string', 'is_hex='=>'bool'],
63246325
'mb_encoding_aliases' => ['list<non-falsy-string>|false', 'encoding'=>'string'],

resources/functionMap_php80delta.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@
8686
'getenv\'1' => ['array<string, string>', 'varname='=>'null', 'local_only='=>'bool'],
8787
'ldap_set_rebind_proc' => ['bool', 'ldap'=>'resource', 'callback'=>'?callable'],
8888
'mb_decode_numericentity' => ['string|false', 'string'=>'string', 'convmap'=>'array', 'encoding='=>'string'],
89-
'mb_detect_order' => ['bool|list<non-falsy-string>', 'encoding_list='=>'non-empty-list<non-falsy-string>|non-falsy-string|null'],
89+
'mb_detect_order' => ['bool', 'encoding_list'=>'non-empty-list<non-falsy-string>|non-falsy-string'],
90+
'mb_detect_order\'1' => ['list<non-falsy-string>', 'encoding_list='=>'null'],
9091
'mb_encoding_aliases' => ['list<non-falsy-string>', 'encoding'=>'string'],
9192
'mb_str_split' => ['list<string>', 'str'=>'string', 'split_length='=>'positive-int', 'encoding='=>'string'],
9293
'mb_strlen' => ['0|positive-int', 'str'=>'string', 'encoding='=>'string'],
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php declare(strict_types = 1); // lint < 8.0
2+
3+
namespace Bug8922;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @param non-empty-list<non-falsy-string> $array
9+
* @param non-falsy-string $string
10+
* @param mixed $mixed
11+
*/
12+
function doSomething($array, $string, $mixed): void
13+
{
14+
assertType('list<non-falsy-string>', mb_detect_order());
15+
assertType('bool', mb_detect_order(null));
16+
assertType('bool', mb_detect_order($array));
17+
assertType('bool', mb_detect_order($string));
18+
assertType('bool', mb_detect_order($mixed));
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php declare(strict_types = 1); // lint >= 8.0
2+
3+
namespace Bug8922;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @param non-empty-list<non-falsy-string> $array
9+
* @param non-falsy-string $string
10+
* @param mixed $mixed
11+
*/
12+
function doSomething($array, $string, $mixed): void
13+
{
14+
assertType('list<non-falsy-string>', mb_detect_order());
15+
assertType('list<non-falsy-string>', mb_detect_order(null));
16+
assertType('bool', mb_detect_order($array));
17+
assertType('bool', mb_detect_order($string));
18+
assertType('bool|list<non-falsy-string>', mb_detect_order($mixed));
19+
}

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,6 +2248,21 @@ public function testBug12954(): void
22482248
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-12954.php'], []);
22492249
}
22502250

2251+
public function testBug8922(): void
2252+
{
2253+
$errors = [];
2254+
if (PHP_VERSION_ID < 80000) {
2255+
$errors[] = [
2256+
'Parameter #1 $encoding_list of function mb_detect_order expects non-empty-list<non-falsy-string>|non-falsy-string, null given.',
2257+
15,
2258+
'• Type #1 from the union: null is not a list.
2259+
• Type #1 from the union: null is empty.'
2260+
];
2261+
}
2262+
2263+
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-8922.php'], $errors);
2264+
}
2265+
22512266
public function testBug13065(): void
22522267
{
22532268
$errors = [];

0 commit comments

Comments
 (0)