Completed
Pull Request — master (#472)
by
unknown
02:39
created

Yahoo   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 8
c 3
b 0
f 1
lcom 1
cbo 6
dl 0
loc 93
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 2
A getRequestTokenEndpoint() 0 4 1
A getAuthorizationEndpoint() 0 4 1
A getAccessTokenEndpoint() 0 4 1
B refreshAccessToken() 0 25 1
A parseAccessTokenResponse() 0 20 2
1
<?php
2
3
namespace OAuth\OAuth1\Service;
4
5
use OAuth\OAuth1\Signature\SignatureInterface;
6
use OAuth\OAuth1\Token\StdOAuth1Token;
7
use OAuth\Common\Http\Uri\Uri;
8
use OAuth\Common\Consumer\CredentialsInterface;
9
use OAuth\Common\Http\Uri\UriInterface;
10
use OAuth\Common\Storage\TokenStorageInterface;
11
use OAuth\Common\Http\Client\ClientInterface;
12
use OAuth\OAuth1\Token\TokenInterface;
13
14
class Yahoo extends AbstractService
15
{
16
    public function __construct(
17
        CredentialsInterface $credentials,
18
        ClientInterface $httpClient,
19
        TokenStorageInterface $storage,
20
        SignatureInterface $signature,
21
        UriInterface $baseApiUri = null
22
    ) {
23
        parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri);
24
25
        if (null === $baseApiUri) {
26
            $this->baseApiUri = new Uri('https://social.yahooapis.com/v1/');
27
        }
28
    }
29
30
    /**
31
     * {@inheritDoc}
32
     */
33
    public function getRequestTokenEndpoint()
34
    {
35
        return new Uri('https://api.login.yahoo.com/oauth/v2/get_request_token');
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getAuthorizationEndpoint()
42
    {
43
        return new Uri('https://api.login.yahoo.com/oauth/v2/request_auth');
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function getAccessTokenEndpoint()
50
    {
51
        return new Uri('https://api.login.yahoo.com/oauth/v2/get_token');
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function refreshAccessToken(TokenInterface $token)
58
    {
59
        $extraParams = $token->getExtraParams();
60
        $bodyParams = array('oauth_session_handle' => $extraParams['oauth_session_handle']);
61
62
        $authorizationHeader = array(
63
            'Authorization' => $this->buildAuthorizationHeaderForAPIRequest(
64
                'POST',
65
                $this->getAccessTokenEndpoint(),
66
                $this->storage->retrieveAccessToken($this->service()),
0 ignored issues
show
Compatibility introduced by
$this->storage->retrieve...Token($this->service()) of type object<OAuth\Common\Token\TokenInterface> is not a sub-type of object<OAuth\OAuth1\Token\TokenInterface>. It seems like you assume a child interface of the interface OAuth\Common\Token\TokenInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
67
                $bodyParams
68
            )
69
        );
70
71
72
        
73
        $headers = array_merge($authorizationHeader, $this->getExtraOAuthHeaders(), array());
74
75
        $responseBody = $this->httpClient->retrieveResponse($this->getAccessTokenEndpoint(), $bodyParams, $headers);
76
77
        $token = $this->parseAccessTokenResponse($responseBody);
78
        $this->storage->storeAccessToken($this->service(), $token);
79
80
        return $token;
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    protected function parseAccessTokenResponse($responseBody)
87
    {
88
        $data = $this->validateTokenResponse($responseBody);
89
        
90
        $token = new StdOAuth1Token();
91
92
        $token->setAccessToken($data['oauth_token']);
93
        $token->setAccessTokenSecret($data['oauth_token_secret']);
94
95
        if (isset($data['oauth_expires_in'])) {
96
            $token->setLifetime($data['oauth_expires_in']);
97
        } else {
98
            $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
99
        }
100
101
        unset($data['oauth_token'], $data['oauth_token_secret']);
102
        $token->setExtraParams($data);
103
104
        return $token;
105
    }
106
}
107