Skip to content

Commit dc86569

Browse files
committed
Update TypeSpecifier.php
1 parent eeb0b33 commit dc86569

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/Analyser/TypeSpecifier.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,13 +1579,18 @@ private function getConditionalSpecifiedTypes(
15791579
if (!array_key_exists($parameterName, $argsMap)) {
15801580
return null;
15811581
}
1582+
$parameterExpr = $argsMap[$parameterName];
15821583

15831584
$targetType = $conditionalType->getTarget();
15841585
$ifType = $conditionalType->getIf();
15851586
$elseType = $conditionalType->getElse();
15861587

15871588
if (
1588-
$argsMap[$parameterName] instanceof Node\Scalar
1589+
(
1590+
$parameterExpr instanceof Node\Scalar
1591+
|| ($parameterExpr instanceof ConstFetch && in_array(strtolower($parameterExpr->name->toString()), ['true', 'false', 'null'], true))
1592+
)
1593+
&& !$targetType instanceof UnionType
15891594
&& $targetType->isConstantScalarValue()->yes()
15901595
) {
15911596
return null;
@@ -1600,7 +1605,7 @@ private function getConditionalSpecifiedTypes(
16001605
}
16011606

16021607
$specifiedTypes = $this->create(
1603-
$argsMap[$parameterName],
1608+
$parameterExpr,
16041609
$targetType,
16051610
$context,
16061611
$scope,
@@ -1611,7 +1616,7 @@ private function getConditionalSpecifiedTypes(
16111616
$context = $context->negate();
16121617
}
16131618

1614-
$specifiedTypes = $specifiedTypes->unionWith($this->specifyTypesInCondition($scope, $argsMap[$parameterName], $context));
1619+
$specifiedTypes = $specifiedTypes->unionWith($this->specifyTypesInCondition($scope, $parameterExpr, $context));
16151620
}
16161621

16171622
return $specifiedTypes;

0 commit comments

Comments
 (0)