在我的代码中,我创建了一个这样的 EventFactory:
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);
}
PostCreatedEvent和ExerciseExecutedEvent都扩展了一个抽象类Event。
你能告诉我是否有办法以不从 Psalm 接收错误的方式注释数组?