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 f93ac70
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 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 can not contain `null` anymore.');
$reconciled_types[] = Type::getLiteral($enum_case->value);
}

Expand All @@ -3001,10 +3001,11 @@ private static function reconcileValueOf(
return null;
}

assert($enum_case->value !== null, 'Verified enum type above, value can not contain `null` anymore.');
$reconciled_types[] = Type::getLiteral($enum_case->value);
}

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

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

View workflow job for this annotation

GitHub Actions / build

InvalidArgument

src/Psalm/Internal/Type/SimpleAssertionReconciler.php:3008: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
2 changes: 1 addition & 1 deletion src/Psalm/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public static function getLiteral($value)
return new TLiteralInt($value);
}

return new TLiteralString($value);
return TLiteralString::make($value);
}

public static function getString(?string $value = null): Union
Expand Down

0 comments on commit f93ac70

Please sign in to comment.