From f93ac70a0a72e4bd070debb9eebd41eed3358d58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20B=C3=B6sing?= <2189546+boesing@users.noreply.github.com> Date: Sat, 26 Aug 2023 00:24:36 +0200 Subject: [PATCH] qa: resolving psalm issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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> --- src/Psalm/Internal/Type/SimpleAssertionReconciler.php | 5 +++-- src/Psalm/Type.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php index 5b48139c8..a1ac4bff2 100644 --- a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php +++ b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php @@ -2963,7 +2963,6 @@ class SimpleAssertionReconciler extends Reconciler // 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; @@ -2990,6 +2989,7 @@ class SimpleAssertionReconciler extends Reconciler // For value-of, 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); } @@ -3001,10 +3001,11 @@ class SimpleAssertionReconciler extends Reconciler 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); } /** diff --git a/src/Psalm/Type.php b/src/Psalm/Type.php index 23399f7f6..5a34e81a1 100644 --- a/src/Psalm/Type.php +++ b/src/Psalm/Type.php @@ -269,7 +269,7 @@ abstract class Type return new TLiteralInt($value); } - return new TLiteralString($value); + return TLiteralString::make($value); } public static function getString(?string $value = null): Union