Skip to content

Commit 49f7925

Browse files
Try
1 parent ab9ecd3 commit 49f7925

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/Type/Php/MbConvertEncodingFunctionReturnTypeExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ public function getTypeFromFunctionCall(
5252

5353
$result = TypeCombinator::intersect($initialReturnType, $this->generalizeStringType($argType));
5454
if ($result instanceof NeverType) {
55-
return null;
55+
$result = $initialReturnType;
5656
}
5757

5858
if ($this->phpVersion->throwsValueErrorForInternalFunctions()) {
5959
if (!isset($functionCall->getArgs()[2])) {
60-
return $result;
60+
return TypeCombinator::remove($result, new ConstantBooleanType(false));
6161
}
6262
$fromEncodingArgType = $scope->getType($functionCall->getArgs()[2]->value);
6363

@@ -90,7 +90,7 @@ public function getTypeFromFunctionCall(
9090
}
9191

9292
if (!$returnFalseIfCannotDetectEncoding) {
93-
return $result;
93+
return TypeCombinator::remove($result, new ConstantBooleanType(false));
9494
}
9595
}
9696

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ function test_mb_convert_encoding(
2020
string|array|bool $union,
2121
int $int,
2222
): void {
23-
\PHPStan\Testing\assertType('array|string|false', mb_convert_encoding($mixed, 'UTF-8'));
23+
\PHPStan\Testing\assertType('array|string', mb_convert_encoding($mixed, 'UTF-8'));
2424
\PHPStan\Testing\assertType('string', mb_convert_encoding($constantString, 'UTF-8'));
2525
\PHPStan\Testing\assertType('string', mb_convert_encoding($string, 'UTF-8'));
2626
\PHPStan\Testing\assertType('array', mb_convert_encoding($mixedArray, 'UTF-8'));
2727
\PHPStan\Testing\assertType('array{foo: string, bar: int, baz: string}', mb_convert_encoding($structuredArray, 'UTF-8'));
2828
\PHPStan\Testing\assertType('list<string>', mb_convert_encoding($stringList, 'UTF-8'));
2929
\PHPStan\Testing\assertType('list<int>', mb_convert_encoding($intList, 'UTF-8'));
30-
\PHPStan\Testing\assertType('array{foo: string, bar: int, baz: string}|string|false', mb_convert_encoding($union, 'UTF-8'));
31-
\PHPStan\Testing\assertType('array|string|false', mb_convert_encoding($int, 'UTF-8'));
30+
\PHPStan\Testing\assertType('array{foo: string, bar: int, baz: string}|string', mb_convert_encoding($union, 'UTF-8'));
31+
\PHPStan\Testing\assertType('array|string', mb_convert_encoding($int, 'UTF-8'));
3232

3333
\PHPStan\Testing\assertType('string', mb_convert_encoding($string, 'UTF-8', 'FOO'));
3434
\PHPStan\Testing\assertType('string|false', mb_convert_encoding($string, 'UTF-8', $string));

0 commit comments

Comments
 (0)