Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e3c0981

Browse files
VincentLangletondrejmirtes
authored andcommitted
Support auto encoding
1 parent 163d178 commit e3c0981

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

‎src/Type/Php/MbConvertEncodingFunctionReturnTypeExtension.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
use PHPStan\Type\UnionType;
2121
use function count;
2222
use function str_contains;
23+
use function strtolower;
24+
use function trim;
2325

2426
#[AutowiredService]
2527
final class MbConvertEncodingFunctionReturnTypeExtension implements DynamicFunctionReturnTypeExtension
@@ -81,7 +83,10 @@ public function getTypeFromFunctionCall(
8183
$constantStrings = $fromEncodingArgType->getConstantStrings();
8284
if (count($constantStrings) > 0) {
8385
foreach ($constantStrings as $constantString) {
84-
if (str_contains($constantString->getValue(), ',')) {
86+
if (
87+
str_contains($constantString->getValue(), ',')
88+
|| trim(strtolower($constantString->getValue())) === 'auto'
89+
) {
8590
$returnFalseIfCannotDetectEncoding = true;
8691
break;
8792
}

‎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)

AltStyle によって変換されたページ (->オリジナル) /