Skip to content

Commit

Permalink
Enum case value null check instead of instanceof
Browse files Browse the repository at this point in the history
  • Loading branch information
tuqqu committed Aug 31, 2023
1 parent f251c9c commit 76f03cc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
use Psalm\Type\Atomic\TFalse;
use Psalm\Type\Atomic\TGenericObject;
use Psalm\Type\Atomic\TInt;
use Psalm\Type\Atomic\TLiteralInt;
use Psalm\Type\Atomic\TLiteralString;
use Psalm\Type\Atomic\TMixed;
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\Atomic\TNull;
Expand Down Expand Up @@ -1033,13 +1031,7 @@ private static function handleEnumValue(
$case_values = [];

foreach ($enum_cases as $enum_case) {
if ($enum_case->value instanceof TLiteralString
|| $enum_case->value instanceof TLiteralInt) {
$case_values[] = $enum_case->value;
} else {
// this should never happen
$case_values[] = new TMixed();
}
$case_values[] = $enum_case->value ?? new TMixed();
}

/** @psalm-suppress ArgumentTypeCoercion */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
use Psalm\Type\Atomic\TArray;
use Psalm\Type\Atomic\TGenericObject;
use Psalm\Type\Atomic\TKeyedArray;
use Psalm\Type\Atomic\TLiteralInt;
use Psalm\Type\Atomic\TLiteralString;
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\Atomic\TObjectWithProperties;
use Psalm\Type\Union;
Expand Down Expand Up @@ -64,8 +62,7 @@ public static function getGetObjectVarsReturnType(
}
$enum_case_storage = $enum_classlike_storage->enum_cases[$object_type->case_name];

if ($enum_case_storage->value instanceof TLiteralString
|| $enum_case_storage->value instanceof TLiteralInt) {
if ($enum_case_storage->value !== null) {
$properties['value'] = new Union([$enum_case_storage->value]);
}

Expand Down

0 comments on commit 76f03cc

Please sign in to comment.