Skip to content

Commit 16715c1

Browse files
devbananaondrejmirtes
authored andcommitted
Make filter_var() return non-empty-string if input is non-empty
1 parent 7906779 commit 16715c1

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/Type/Php/FilterVarDynamicReturnTypeExtension.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPStan\Analyser\Scope;
88
use PHPStan\Reflection\FunctionReflection;
99
use PHPStan\Reflection\ReflectionProvider;
10+
use PHPStan\Type\Accessory\AccessoryNonEmptyStringType;
1011
use PHPStan\Type\ArrayType;
1112
use PHPStan\Type\BooleanType;
1213
use PHPStan\Type\Constant\ConstantArrayType;
@@ -17,6 +18,7 @@
1718
use PHPStan\Type\ErrorType;
1819
use PHPStan\Type\FloatType;
1920
use PHPStan\Type\IntegerType;
21+
use PHPStan\Type\IntersectionType;
2022
use PHPStan\Type\MixedType;
2123
use PHPStan\Type\NullType;
2224
use PHPStan\Type\StringType;
@@ -128,6 +130,10 @@ public function getTypeFromFunctionCall(
128130
$type = $this->getFilterTypeMap()[$filterValue] ?? $mixedType;
129131
$otherType = $this->getOtherType($flagsArg, $scope);
130132

133+
if ($inputType->isNonEmptyString()->yes()) {
134+
$type = new IntersectionType([$type, new AccessoryNonEmptyStringType()]);
135+
}
136+
131137
if ($otherType->isSuperTypeOf($type)->no()) {
132138
$type = new UnionType([$type, $otherType]);
133139
}

0 commit comments

Comments
 (0)