Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
clxmstaab authored and ondrejmirtes committed Apr 29, 2022
1 parent 8626231 commit 62f8022
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/Analyser/TypeSpecifier.php
Expand Up @@ -23,7 +23,9 @@
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\ShouldNotHappenException;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Accessory\AccessoryLiteralStringType;
use PHPStan\Type\Accessory\AccessoryNonEmptyStringType;
use PHPStan\Type\Accessory\AccessoryNumericStringType;
use PHPStan\Type\Accessory\HasOffsetType;
use PHPStan\Type\Accessory\HasPropertyType;
use PHPStan\Type\Accessory\NonEmptyArrayType;
Expand Down Expand Up @@ -236,8 +238,18 @@ public function specifyTypesInCondition(
}
$argType = $scope->getType($exprNode->getArgs()[0]->value);
if ($argType->isString()->yes()) {
$accessories = [
new AccessoryNonEmptyStringType(),
];
if ($argType->isLiteralString()->yes()) {
$accessories[] = new AccessoryLiteralStringType();
}
if ($argType->isNumericString()->yes()) {
$accessories[] = new AccessoryNumericStringType();
}

$funcTypes = $this->create($exprNode, $constantType, $context, false, $scope, $rootExpr);
$valueTypes = $this->create($exprNode->getArgs()[0]->value, new AccessoryNonEmptyStringType(), $newContext, false, $scope, $rootExpr);
$valueTypes = $this->create($exprNode->getArgs()[0]->value, TypeCombinator::intersect(...$accessories), $newContext, false, $scope, $rootExpr);
return $funcTypes->unionWith($valueTypes);
}
}
Expand Down Expand Up @@ -536,7 +548,17 @@ public function specifyTypesInCondition(
) {
$argType = $scope->getType($expr->right->getArgs()[0]->value);
if ($argType->isString()->yes()) {
$result = $result->unionWith($this->create($expr->right->getArgs()[0]->value, new AccessoryNonEmptyStringType(), $context, false, $scope, $rootExpr));
$accessories = [
new AccessoryNonEmptyStringType(),
];
if ($argType->isLiteralString()->yes()) {
$accessories[] = new AccessoryLiteralStringType();
}
if ($argType->isNumericString()->yes()) {
$accessories[] = new AccessoryNumericStringType();
}

$result = $result->unionWith($this->create($expr->right->getArgs()[0]->value, TypeCombinator::intersect(...$accessories), $context, false, $scope, $rootExpr));
}
}
}
Expand Down

0 comments on commit 62f8022

Please sign in to comment.