In my code I created an EventFactory like this:
private array $events = [
'post_created' => PostCreatedEvent::class,
'exercise_executed' => ExerciseExecutedEvent::class,
];
public function fromTopicAndData(string $topic, array $data) : Event
{
if (! array_key_exists($topic, $this->events)) {
throw new Exception('Invalid Topic');
}
$event = ($this->events)[$topic];
return $event::createFromData($data);
}
Both PostCreatedEvent and ExerciseExecutedEvent extends an abstract class Event.
Can you tell me if there is a way to annotate the array in such a way as not to receive error from Psalm?