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