From b288633349ab3df886e51721ed07a09c09ccce92 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 28 Apr 2022 11:32:24 +0200 Subject: [PATCH] fix --- src/Analyser/MutatingScope.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index 77265a7b512..829921f3d0f 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -62,6 +62,7 @@ use PHPStan\TrinaryLogic; use PHPStan\Type\Accessory\AccessoryLiteralStringType; use PHPStan\Type\Accessory\AccessoryNonEmptyStringType; +use PHPStan\Type\Accessory\AccessoryNumericStringType; use PHPStan\Type\Accessory\NonEmptyArrayType; use PHPStan\Type\ArrayType; use PHPStan\Type\BenevolentUnionType; @@ -688,8 +689,21 @@ private function resolveType(Expr $node): Type if ($type instanceof ConstantStringType) { return new ConstantStringType(~$type->getValue()); } - if ($type instanceof StringType) { - return new StringType(); + if ($type->isString()->yes()) { + $accessories = [ + new StringType(), + ]; + if ($type->isNonEmptyString()->yes()) { + $accessories[] = new AccessoryNonEmptyStringType(); + } + if ($type->isLiteralString()->yes()) { + $accessories[] = new AccessoryLiteralStringType(); + } + if ($type->isNumericString()->yes()) { + $accessories[] = new AccessoryNumericStringType(); + } + + return TypeCombinator::intersect(...$accessories); } if ($type instanceof IntegerType || $type instanceof FloatType) { return new IntegerType(); //no const types here, result depends on PHP_INT_SIZE