Skip to content

Commit

Permalink
Fix slow enum-union with lots of cases
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Mar 22, 2024
1 parent 0f2366b commit b00bb14
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,11 @@ parameters:
count: 4
path: src/Type/TypeCombinator.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Enum\\\\EnumCaseObjectType is error\\-prone and deprecated\\. Use Type\\:\\:getEnumCases\\(\\) instead\\.$#"
count: 1
path: src/Type/TypeCombinator.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\FloatType is error\\-prone and deprecated\\. Use Type\\:\\:isFloat\\(\\) instead\\.$#"
count: 1
Expand Down
4 changes: 2 additions & 2 deletions src/Type/TypeCombinator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PHPStan\Type\Constant\ConstantFloatType;
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\Generic\GenericClassStringType;
use PHPStan\Type\Generic\TemplateArrayType;
use PHPStan\Type\Generic\TemplateBenevolentUnionType;
Expand Down Expand Up @@ -200,8 +201,7 @@ public static function union(Type ...$types): Type
if ($types[$i] instanceof StringType && !$types[$i] instanceof ClassStringType) {
$hasGenericScalarTypes[ConstantStringType::class] = true;
}
$enumCases = $types[$i]->getEnumCases();
if (count($enumCases) === 1) {
if ($types[$i] instanceof EnumCaseObjectType) {
$enumCaseTypes[$types[$i]->describe(VerbosityLevel::cache())] = $types[$i];

unset($types[$i]);
Expand Down

0 comments on commit b00bb14

Please sign in to comment.