/** * Deletes the profile with given uniqueness. * * @param string $uniqueness * * @throws NonExistentProfileException */ public function delete($uniqueness) { /** @var DeleteResult $result */ $result = $this->connectToStorage->connect()->deleteOne(['_id' => $uniqueness]); if ($result->getDeletedCount() === 0) { throw new NonExistentProfileException(); } }
/** * Creates a profile. * * @param string $uniqueness * @param string $email * * @throws InvalidEmailException * * @return string */ public function create($uniqueness, $email) { if (!Validator::email()->validate($email)) { throw new InvalidEmailException(); } $uniqueness = $uniqueness ?: uniqid(); $this->connectToStorage->connect()->insertOne(new Profile($uniqueness, $email)); return $uniqueness; }
/** * Collects profiles. * * @return Profiles */ public function collect() { $profiles = new Profiles($this->connectToStorage->connect()->find()); return $profiles; }