email) { $emails = $this->fetchUserEmails($token); $emails = json_decode($emails); $email = null; foreach ($emails as $email) { if ($email->primary) { $email = $email->email; break; } } $user->email = $email; } return $user; } protected function fetchUserEmails(AccessToken $token) { $url = "https://api.github.com/user/emails?access_token={$token}"; try { $client = $this->getHttpClient(); $client->setBaseUrl($url); if ($this->headers) { $client->setDefaultOption('headers', $this->headers); } $request = $client->get()->send(); $response = $request->getBody(); } catch (BadResponseException $e) { // @codeCoverageIgnoreStart $raw_response = explode("\n", $e->getResponse()); throw new IDPException(end($raw_response)); // @codeCoverageIgnoreEnd } return $response; } }