Conditions | 4 |
Paths | 5 |
Total Lines | 24 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
13 | public function createTemporaryCredentialsFromResponse(ResponseInterface $response) |
||
14 | { |
||
15 | $contents = $response->getBody()->getContents(); |
||
16 | |||
17 | parse_str($contents, $responseParameters); |
||
18 | |||
19 | $requiredParames = [ |
||
20 | 'oauth_token', |
||
21 | 'oauth_token_secret', |
||
22 | 'oauth_callback_confirmed', |
||
23 | ]; |
||
24 | |||
25 | foreach ($requiredParames as $param) { |
||
26 | if (! isset($responseParameters[$param])) { |
||
27 | throw new CredentialsException("Unable to parse temporary credentials response. Missing parameter: {$param}."); |
||
28 | } |
||
29 | } |
||
30 | |||
31 | if ($responseParameters['oauth_callback_confirmed'] !== 'true') { |
||
32 | throw new CredentialsException('Unable to parse temporary credentials response. Callback URI is not valid.'); |
||
33 | } |
||
34 | |||
35 | return new TemporaryCredentials($responseParameters['oauth_token'], $responseParameters['oauth_token_secret']); |
||
36 | } |
||
37 | } |
||
38 |