Skip to content

Commit a6a23dc

Browse files
committed
Refactor PreInc and PreDec
1 parent c737095 commit a6a23dc

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/Analyser/MutatingScope.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,6 +1763,7 @@ private function resolveType(Expr $node): Type
17631763
} elseif ($node instanceof Expr\PreInc || $node instanceof Expr\PreDec) {
17641764
$varType = $this->getType($node->var);
17651765
$varScalars = TypeUtils::getConstantScalars($varType);
1766+
$stringType = new StringType();
17661767
if (count($varScalars) > 0) {
17671768
$newTypes = [];
17681769

@@ -1777,19 +1778,18 @@ private function resolveType(Expr $node): Type
17771778
$newTypes[] = $this->getTypeFromValue($varValue);
17781779
}
17791780
return TypeCombinator::union(...$newTypes);
1780-
} elseif ($varType instanceof IntegerRangeType) {
1781-
return $varType->shift($node instanceof Expr\PreInc ? +1 : -1);
1782-
}
1783-
1784-
$stringType = new StringType();
1785-
if ($stringType->isSuperTypeOf($varType)->yes()) {
1781+
} elseif ($stringType->isSuperTypeOf($varType)->yes()) {
17861782
if ($varType->isLiteralString()->yes()) {
17871783
return new IntersectionType([$stringType, new AccessoryLiteralStringType()]);
17881784
}
17891785
return $stringType;
17901786
}
17911787

1792-
return $varType->toNumber();
1788+
if ($node instanceof Expr\PreInc) {
1789+
return $this->getType(new BinaryOp\Plus($node->var, new LNumber(1)));
1790+
}
1791+
1792+
return $this->getType(new BinaryOp\Minus($node->var, new LNumber(1)));
17931793
} elseif ($node instanceof Expr\Yield_) {
17941794
$functionReflection = $this->getFunction();
17951795
if ($functionReflection === null) {

0 commit comments

Comments
 (0)