id instanceof UserEntity ? $cmd->id : $this->repo->ofUniqueKey($cmd->id); $user->unverifyEmail(); try { $otherUser = $this->repo->ofEmail($user->getEmail()); if ($otherUser->getId() != $user->getId()) { throw new EmailTakenException($user->getEmail()); } } catch (UserNotFoundException $th) { // Do nothing } // Dispatch the user email updated event $event = new UserEmailUpdatedEvent($user); $this->dispatcher->dispatch($event); return $user; } }