Skip to content

Commit 8570fc7

Browse files
committed
Remove weirdness of determineVariableTypeFromSpecifiedTypes by using the scope
1 parent 4edf14f commit 8570fc7

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,7 @@ private function handleAll(
792792
TypeSpecifierContext::createTruthy()
793793
);
794794

795-
$typeBefore = $scope->getType($node->getArgs()[0]->value);
796-
$type = $this->determineVariableTypeFromSpecifiedTypes($typeBefore, $specifiedTypes);
795+
$type = $this->determineVariableTypeFromSpecifiedTypes($scope, $specifiedTypes);
797796

798797
return $this->arrayOrIterable(
799798
$scope,
@@ -829,8 +828,7 @@ private function handleNullOr(
829828
TypeSpecifierContext::createTruthy()
830829
);
831830

832-
$typeBefore = $scope->getType($node->getArgs()[0]->value);
833-
$type = $this->determineVariableTypeFromSpecifiedTypes($typeBefore, $specifiedTypes);
831+
$type = $this->determineVariableTypeFromSpecifiedTypes($scope, $specifiedTypes);
834832

835833
return $this->typeSpecifier->create($node->getArgs()[0]->value, TypeCombinator::addNull($type), TypeSpecifierContext::createTruthy(), false, $scope);
836834
}
@@ -872,7 +870,7 @@ private function arrayOrIterable(
872870
);
873871
}
874872

875-
private function determineVariableTypeFromSpecifiedTypes(Type $typeBefore, SpecifiedTypes $specifiedTypes): Type
873+
private function determineVariableTypeFromSpecifiedTypes(Scope $scope, SpecifiedTypes $specifiedTypes): Type
876874
{
877875
if (count($specifiedTypes->getSureTypes()) > 0) {
878876
$sureTypes = $specifiedTypes->getSureTypes();
@@ -890,9 +888,9 @@ private function determineVariableTypeFromSpecifiedTypes(Type $typeBefore, Speci
890888
if (count($specifiedTypes->getSureNotTypes()) > 0) {
891889
$sureNotTypes = $specifiedTypes->getSureNotTypes();
892890
$exprString = key($sureNotTypes);
893-
[, $type] = $sureNotTypes[$exprString];
891+
[$exprNode, $type] = $sureNotTypes[$exprString];
894892

895-
return TypeCombinator::remove($typeBefore, $type);
893+
return TypeCombinator::remove($scope->getType($exprNode), $type);
896894
}
897895

898896
throw new ShouldNotHappenException();

0 commit comments

Comments
 (0)