/**
  * Create a cookie for trusted computer.
  *
  * @param Request $request
  * @param mixed   $user
  *
  *
  * @return Cookie
  */
 public function createTrustedCookie(Request $request, $user)
 {
     $tokenList = $request->cookies->get($this->cookieName, null);
     // Generate new token
     $token = $this->tokenGenerator->generateToken(32);
     $tokenList .= ($tokenList !== null ? ';' : '') . $token;
     $validUntil = $this->getDateTimeNow()->add(new \DateInterval('PT' . $this->cookieLifetime . 'S'));
     // Add token to user entity
     $this->trustedComputerManager->addTrustedComputer($user, $token, $validUntil);
     $domain = null;
     $requestHost = $request->getHost();
     if ($requestHost !== 'localhost') {
         $domain = '.' . $requestHost;
     }
     // Create cookie
     return new Cookie($this->cookieName, $tokenList, $validUntil, '/', $domain, $this->cookieSecure);
 }