Skip to content

Commit

Permalink
qa: resolving psalm issues
Browse files Browse the repository at this point in the history
- remove unused variable
- add assertion to reduce possible types from `TEnumCase`
- use `TypeCombiner` to provide proper `Union` containing all literals

Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
  • Loading branch information
boesing committed Aug 25, 2023
1 parent cd3e294 commit 9c9558a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Psalm/Internal/Type/SimpleAssertionReconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2963,7 +2963,6 @@ private static function reconcileValueOf(

// For now, only enums are supported here
foreach ($assertion_type->type->getAtomicTypes() as $atomic_type) {
$class_name = null;
$enum_case_to_assert = null;
if ($atomic_type instanceof TClassConstant) {
$class_name = $atomic_type->fq_classlike_name;
Expand All @@ -2990,6 +2989,7 @@ private static function reconcileValueOf(
// For value-of<MyBackedEnum>, the assertion is meant to return *ANY* value of *ANY* enum case
if ($enum_case_to_assert === null) {
foreach ($class_storage->enum_cases as $enum_case) {
assert($enum_case->value !== null, 'Verified enum type above, value is either string or int.');
$reconciled_types[] = Type::getLiteral($enum_case->value);
}

Expand All @@ -3004,7 +3004,7 @@ private static function reconcileValueOf(
$reconciled_types[] = Type::getLiteral($enum_case->value);

Check failure on line 3004 in src/Psalm/Internal/Type/SimpleAssertionReconciler.php

View workflow job for this annotation

GitHub Actions / build

PossiblyNullArgument

src/Psalm/Internal/Type/SimpleAssertionReconciler.php:3004:52: PossiblyNullArgument: Argument 1 of Psalm\Type::getLiteral cannot be null, possibly null value provided (see https://psalm.dev/078)
}

return new Union($reconciled_types);
return TypeCombiner::combine($reconciled_types, $codebase, false, false);

Check failure on line 3007 in src/Psalm/Internal/Type/SimpleAssertionReconciler.php

View workflow job for this annotation

GitHub Actions / build

InvalidArgument

src/Psalm/Internal/Type/SimpleAssertionReconciler.php:3007:38: InvalidArgument: Argument 1 of Psalm\Internal\Type\TypeCombiner::combine expects non-empty-list<Psalm\Type\Atomic>, but list{0?: Psalm\Type\Atomic\TLiteralInt|Psalm\Type\Atomic\TLiteralString, ...<Psalm\Type\Atomic\TLiteralInt|Psalm\Type\Atomic\TLiteralString>} provided (see https://psalm.dev/004)
}

/**
Expand Down

0 comments on commit 9c9558a

Please sign in to comment.