Completed
Pull Request — master (#3)
by Risan Bagja
02:02 queued 34s
created

CredentialsFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 30
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B createTemporaryCredentialsFromResponse() 0 24 4
1
<?php
2
3
namespace Risan\OAuth1\Credentials;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Risan\OAuth1\Credentials\CredentialsFactoryInterface;
7
8
class CredentialsFactory implements CredentialsFactoryInterface
9
{
10
    /**
11
     * {@inheritDoc}
12
     */
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