Skip to content

Commit 2659130

Browse files
committed
simplify MbStrlenFunctionReturnTypeExtension
1 parent c0c9d1f commit 2659130

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/Type/Php/MbStrlenFunctionReturnTypeExtension.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use PHPStan\Reflection\FunctionReflection;
99
use PHPStan\Reflection\ParametersAcceptorSelector;
1010
use PHPStan\ShouldNotHappenException;
11-
use PHPStan\Type\BooleanType;
1211
use PHPStan\Type\Constant\ConstantBooleanType;
1312
use PHPStan\Type\Constant\ConstantIntegerType;
1413
use PHPStan\Type\Constant\ConstantStringType;
@@ -93,16 +92,7 @@ public function getTypeFromFunctionCall(
9392
}
9493

9594
$argType = $scope->getType($args[0]->value);
96-
97-
if ($argType->isSuperTypeOf(new BooleanType())->yes()) {
98-
$constantScalars = TypeCombinator::remove($argType, new BooleanType())->getConstantScalarTypes();
99-
if (count($constantScalars) > 0) {
100-
$constantScalars[] = new ConstantBooleanType(true);
101-
$constantScalars[] = new ConstantBooleanType(false);
102-
}
103-
} else {
104-
$constantScalars = $argType->getConstantScalarTypes();
105-
}
95+
$constantScalars = $argType->getConstantScalarTypes();
10696

10797
$lengths = [];
10898
foreach ($constantScalars as $constantScalar) {

tests/PHPStan/Analyser/nsrt/bug-10952b.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,14 @@ public function test(): void
3737
mb_strlen($string) > 0 => assertType('non-empty-string', $string),
3838
default => assertType("''", $string),
3939
};
40+
41+
assertType('int<0, 1>', strlen($this->getBool()));
42+
assertType('int<0, 1>', mb_strlen($this->getBool()));
4043
}
44+
45+
public function getBool(): bool
46+
{
47+
return rand(0, 1) === 1;
48+
}
49+
4150
}

0 commit comments

Comments
 (0)