Skip to content

Commit bfd1c52

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

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php

Lines changed: 10 additions & 11 deletions
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,11 +870,12 @@ 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
{
877-
if (count($specifiedTypes->getSureTypes()) > 0) {
878-
$sureTypes = $specifiedTypes->getSureTypes();
879-
$sureNotTypes = $specifiedTypes->getSureNotTypes();
875+
$sureTypes = $specifiedTypes->getSureTypes();
876+
$sureNotTypes = $specifiedTypes->getSureNotTypes();
877+
878+
if (count($sureTypes) > 0) {
880879
$exprString = key($sureTypes);
881880
[, $type] = $sureTypes[$exprString];
882881

@@ -887,12 +886,12 @@ private function determineVariableTypeFromSpecifiedTypes(Type $typeBefore, Speci
887886
return $type;
888887
}
889888

890-
if (count($specifiedTypes->getSureNotTypes()) > 0) {
889+
if (count($sureNotTypes) > 0) {
891890
$sureNotTypes = $specifiedTypes->getSureNotTypes();
892891
$exprString = key($sureNotTypes);
893-
[, $type] = $sureNotTypes[$exprString];
892+
[$exprNode, $type] = $sureNotTypes[$exprString];
894893

895-
return TypeCombinator::remove($typeBefore, $type);
894+
return TypeCombinator::remove($scope->getType($exprNode), $type);
896895
}
897896

898897
throw new ShouldNotHappenException();

0 commit comments

Comments
 (0)