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

Twitter::parseAccessTokenResponse()   B

Complexity

Conditions 6
Paths 4

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 25
rs 8.439
cc 6
eloc 17
nc 4
nop 1
1
<?php
2
3
namespace OAuth\OAuth1\Service;
4
5
use OAuth\OAuth1\Signature\SignatureInterface;
6
use OAuth\Common\Http\Uri\Uri;
7
use OAuth\Common\Consumer\CredentialsInterface;
8
use OAuth\Common\Http\Uri\UriInterface;
9
use OAuth\Common\Storage\TokenStorageInterface;
10
use OAuth\Common\Http\Client\ClientInterface;
11
use OAuth\Common\Exception\Exception;
12
13
class Twitter extends AbstractService
14
{
15
    const ENDPOINT_AUTHENTICATE = "https://api.twitter.com/oauth/authenticate";
16
    const ENDPOINT_AUTHORIZE    = "https://api.twitter.com/oauth/authorize";
17
18
    protected $authorizationEndpoint   = self::ENDPOINT_AUTHENTICATE;
19
20
    public function __construct(
21
        CredentialsInterface $credentials,
22
        ClientInterface $httpClient,
23
        TokenStorageInterface $storage,
24
        SignatureInterface $signature,
25
        UriInterface $baseApiUri = null
26
    ) {
27
        parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri);
28
29
        if (null === $baseApiUri) {
30
            $this->baseApiUri = new Uri('https://api.twitter.com/1.1/');
31
        }
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function getRequestTokenEndpoint()
38
    {
39
        return new Uri('https://api.twitter.com/oauth/request_token');
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getAuthorizationEndpoint()
46
    {
47
        if ($this->authorizationEndpoint != self::ENDPOINT_AUTHENTICATE
48
        && $this->authorizationEndpoint != self::ENDPOINT_AUTHORIZE) {
49
            $this->authorizationEndpoint = self::ENDPOINT_AUTHENTICATE;
50
        }
51
        return new Uri($this->authorizationEndpoint);
52
    }
53
54
    /**
55
     * @param string $authorizationEndpoint
0 ignored issues
show
Documentation introduced by
There is no parameter named $authorizationEndpoint. Did you maybe mean $endpoint?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
56
     *
57
     * @throws Exception
58
     */
59
    public function setAuthorizationEndpoint($endpoint)
60
    {
61
        if ($endpoint != self::ENDPOINT_AUTHENTICATE && $endpoint != self::ENDPOINT_AUTHORIZE) {
62
            throw new Exception(
63
                sprintf("'%s' is not a correct Twitter authorization endpoint.", $endpoint)
64
            );
65
        }
66
        $this->authorizationEndpoint = $endpoint;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function getAccessTokenEndpoint()
73
    {
74
        return new Uri('https://api.twitter.com/oauth/access_token');
75
    }
76
77
}
78