/**
  * Deletes the profile with given uniqueness.
  *
  * @param string $uniqueness
  *
  * @throws NonExistentUniquenessException
  */
 public function delete($uniqueness)
 {
     /** @var DeleteResult $result */
     $result = $this->connectToStorage->connect()->deleteOne(['_id' => $uniqueness]);
     if ($result->getDeletedCount() === 0) {
         throw new NonExistentUniquenessException($uniqueness);
     }
 }
 /**
  * Picks the profile with given uniqueness.
  *
  * @param string $uniqueness
  *
  * @throws NonExistentUniquenessException
  *
  * @return Profile
  */
 public function pick($uniqueness)
 {
     /** @var Profile $profile */
     $profile = $this->connectToStorage->connect()->findOne(['_id' => $uniqueness]);
     if (is_null($profile)) {
         throw new NonExistentUniquenessException($uniqueness);
     }
     return $profile;
 }
 /**
  * Creates a profile.
  *
  * @param string $uniqueness
  * @param string $password
  *
  * @throws ExistentUniquenessException
  * @throws \MongoCursorException
  *
  * @return string
  */
 public function create($uniqueness, $password)
 {
     $salt = $this->generator->generate();
     $hash = $this->encoder->encode($password, $salt);
     $uniqueness = $uniqueness ?: uniqid();
     try {
         $this->connectToStorage->connect()->insertOne(new Profile($uniqueness, $salt, $hash));
     } catch (\MongoCursorException $e) {
         if (11000 == $e->getCode()) {
             throw new ExistentUniquenessException();
         }
         throw $e;
     }
     return $uniqueness;
 }