Skip to content

Commit

Permalink
Use getFiniteTypes() in some places
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jun 19, 2023
1 parent 7912caf commit fa9a951
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/Reflection/InitializerExprTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1309,10 +1309,10 @@ public function resolveIdenticalType(Type $leftType, Type $rightType): BooleanTy
return new ConstantBooleanType($leftType->getValue() === $rightType->getValue());
}

$leftTypeEnumCases = $leftType->getEnumCases();
$rightTypeEnumCases = $rightType->getEnumCases();
if (count($leftTypeEnumCases) === 1 && count($rightTypeEnumCases) === 1) {
return new ConstantBooleanType($leftTypeEnumCases[0]->equals($rightTypeEnumCases[0]));
$leftTypeFiniteTypes = $leftType->getFiniteTypes();
$rightTypeFiniteType = $rightType->getFiniteTypes();
if (count($leftTypeFiniteTypes) === 1 && count($rightTypeFiniteType) === 1) {
return new ConstantBooleanType($leftTypeFiniteTypes[0]->equals($rightTypeFiniteType[0]));
}

$isSuperset = $leftType->isSuperTypeOf($rightType);
Expand Down
6 changes: 2 additions & 4 deletions src/Rules/Comparison/ImpossibleCheckTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,8 @@ public function findSpecifiedType(
$needleArg = $node->getArgs()[0]->value;
$needleType = ($this->treatPhpDocTypesAsCertain ? $scope->getType($needleArg) : $scope->getNativeType($needleArg));
$valueType = $haystackType->getIterableValueType();
$constantNeedleTypesCount = count($needleType->getConstantScalarValues())
+ count($needleType->getEnumCases());
$constantHaystackTypesCount = count($valueType->getConstantScalarValues())
+ count($valueType->getEnumCases());
$constantNeedleTypesCount = count($needleType->getFiniteTypes());
$constantHaystackTypesCount = count($valueType->getFiniteTypes());
$isNeedleSupertype = $needleType->isSuperTypeOf($valueType);
if ($haystackType->isConstantArray()->no()) {
if ($haystackType->isIterableAtLeastOnce()->yes()) {
Expand Down

0 comments on commit fa9a951

Please sign in to comment.