/**
  * @param SerieTokenInterface $serieToken
  * @return SerieTokenInterface|null
  */
 public function getNextInSerie(SerieTokenInterface $serieToken)
 {
     $matchingSerieToken = $this->getMapper()->find($serieToken->getUserId(), $serieToken->getSerie());
     if (!$matchingSerieToken) {
         return null;
     } elseif (!$matchingSerieToken->getExpiresAt() || $matchingSerieToken->getExpiresAt() < new \DateTime()) {
         return null;
     } elseif ($matchingSerieToken->getToken() !== $serieToken->getToken()) {
         $this->removeSerie($serieToken->getUserId(), $serieToken->getSerie());
         return null;
     }
     // Generate new token in the serie
     $matchingSerieToken->setToken($this->generateRandom());
     $this->getMapper()->persist($matchingSerieToken);
     return $matchingSerieToken;
 }
 /**
  * @param SerieTokenInterface $serieToken
  * @return SetCookie
  */
 public function writeSerie(Response $response, SerieTokenInterface $serieToken)
 {
     $serieRepresentation = $serieToken->getUserId() . ':' . $serieToken->getSerie() . ':' . $serieToken->getToken();
     $this->setCookie($response, new SetCookie(self::COOKIE_NAME, $serieRepresentation, $serieToken->getExpiresAt()->getTimestamp(), '/'));
 }