Skip to content

Commit 4f1c243

Browse files
Support auto encoding
1 parent c3babe1 commit 4f1c243

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/Type/Php/MbConvertEncodingFunctionReturnTypeExtension.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ public function getTypeFromFunctionCall(
8181
$constantStrings = $fromEncodingArgType->getConstantStrings();
8282
if (count($constantStrings) > 0) {
8383
foreach ($constantStrings as $constantString) {
84-
if (str_contains($constantString->getValue(), ',')) {
84+
if (
85+
str_contains($constantString->getValue(), ',')
86+
|| trim(strtolower($constantString->getValue())) === 'auto'
87+
) {
8588
$returnFalseIfCannotDetectEncoding = true;
8689
break;
8790
}

tests/PHPStan/Analyser/nsrt/mb-convert-encoding-php7.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,7 @@ function test_mb_convert_encoding(
2929
\PHPStan\Testing\assertType('list<int>|false', mb_convert_encoding($intList, 'UTF-8'));
3030
\PHPStan\Testing\assertType('array{foo: string, bar: int, baz: string}|string|false', mb_convert_encoding($union, 'UTF-8'));
3131
\PHPStan\Testing\assertType('array|string|false', mb_convert_encoding($int, 'UTF-8'));
32+
33+
\PHPStan\Testing\assertType('string|false', mb_convert_encoding($string, 'UTF-8', 'auto'));
34+
\PHPStan\Testing\assertType('string|false', mb_convert_encoding($string, 'UTF-8', ' AUTO '));
3235
};

tests/PHPStan/Analyser/nsrt/mb-convert-encoding-php8.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,7 @@ function test_mb_convert_encoding(
4242
\PHPStan\Testing\assertType('list<string>', mb_convert_encoding($stringList, 'UTF-8', ['FOO']));
4343
\PHPStan\Testing\assertType('list<string>|false', mb_convert_encoding($stringList, 'UTF-8', ['FOO', 'BAR']));
4444
\PHPStan\Testing\assertType('list<string>', mb_convert_encoding($stringList, 'UTF-8', ['FOO,BAR']));
45+
46+
\PHPStan\Testing\assertType('string|false', mb_convert_encoding($string, 'UTF-8', 'auto'));
47+
\PHPStan\Testing\assertType('string|false', mb_convert_encoding($string, 'UTF-8', ' AUTO '));
4548
};

0 commit comments

Comments
 (0)