Skip to content

Commit dfc3c13

Browse files
committed
Better usage of PHPStan API.
1 parent 56f11e4 commit dfc3c13

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

‎src/Type/Php/FilterFunctionReturnTypeHelper.php‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use PHPStan\Type\Type;
2929
use PHPStan\Type\TypeCombinator;
3030
use PHPStan\Type\UnionType;
31-
use function array_filter;
3231
use function array_key_exists;
3332
use function array_merge;
3433
use function hexdec;
@@ -415,17 +414,11 @@ private function determineExactType(Type $in, int $filterValue, Type $defaultTyp
415414

416415
$inString = $in->toString();
417416
if ($inString instanceof UnionType) {
418-
$inStringTypes = $inString->getTypes();
419-
// Replace ConstantStringType of value === "" by NullType.
420-
$types = array_filter(
421-
$inStringTypes,
422-
static fn (Type $type): bool => $type instanceof ConstantStringType && $type->getValue() !== '',
417+
return $inString->traverse(
418+
static fn (Type $type): Type => $type->getConstantStrings() === [$type] && $type->getValue() === ''
419+
? new NullType()
420+
: $type,
423421
);
424-
if ($types !== $inStringTypes) {
425-
$types[] = new NullType();
426-
}
427-
428-
return new UnionType($types);
429422
}
430423

431424
return new UnionType([new AccessoryNonEmptyStringType(), new NullType()]);

0 commit comments

Comments
 (0)