Skip to content

Commit

Permalink
Faster ObjectType->getEnumCases() type substraction
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Jul 2, 2024
1 parent c6b961d commit d2c1054
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/Type/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -1229,21 +1229,24 @@ public function getEnumCases(): array

$className = $classReflection->getName();

$cases = [];
foreach ($classReflection->getEnumCases() as $enumCase) {
$cases[] = new EnumCaseObjectType($className, $enumCase->getName(), $classReflection);
}

if ($this->subtractedType !== null) {
$subtracedEnumCases = $this->subtractedType->getEnumCases();
foreach ($cases as $i => $case) {
$caseName = $case->getEnumCaseName();
foreach ($subtracedEnumCases as $subtracedCase) {
if ($caseName === $subtracedCase->getEnumCaseName()) {
unset($cases[$i]);
continue 2;
}
$subtracedEnumCaseNames = [];

foreach ($this->subtractedType->getEnumCases() as $subtracedCase) {
$subtracedEnumCaseNames[$subtracedCase->getEnumCaseName()] = true;
}

$cases = [];
foreach ($classReflection->getEnumCases() as $enumCase) {
if (array_key_exists($enumCase->getName(), $subtracedEnumCaseNames)) {
continue;
}
$cases[] = new EnumCaseObjectType($className, $enumCase->getName(), $classReflection);
}
} else {
$cases = [];
foreach ($classReflection->getEnumCases() as $enumCase) {
$cases[] = new EnumCaseObjectType($className, $enumCase->getName(), $classReflection);
}
}

Check failure on line 1252 in src/Type/ObjectType.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, ubuntu-latest)

Parameter #1 $array (list<PHPStan\Type\Enum\EnumCaseObjectType>) of array_values is already a list, call has no effect.
Expand Down

0 comments on commit d2c1054

Please sign in to comment.