Passed
Push — master ( def884...c10f7d )
by Dāvis
10:53
created

Twitter::__construct()   A

Complexity

Conditions 6
Paths 24

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 15
nc 24
nop 2
dl 0
loc 26
rs 9.2222
c 0
b 0
f 0
1
<?php
2
3
namespace Sludio\HelperBundle\Oauth\Client\Provider\Twitter;
4
5
use Abraham\TwitterOAuth\TwitterOAuth;
6
use GuzzleHttp\Client as HttpClient;
7
use League\OAuth2\Client\Grant\GrantFactory;
8
use League\OAuth2\Client\Provider\AbstractProvider;
9
use League\OAuth2\Client\Token\AccessToken;
10
use League\OAuth2\Client\Tool\RequestFactory;
11
use Psr\Http\Message\ResponseInterface;
12
13
class Twitter extends AbstractProvider
14
{
15
    const URL_REQUEST_TOKEN = 'oauth/request_token';
16
    const URL_AUTHORIZE = 'oauth/authorize';
17
    const URL_ACCESS_TOKEN = 'oauth/access_token';
18
    public $twitter;
19
20
    /**
21
     * Constructs an OAuth 2.0 service provider.
22
     *
23
     * @param array $options       An array of options to set on this provider.
24
     *                             Options include `clientId`, `clientSecret`, `redirectUri`, and `state`.
25
     *                             Individual providers may introduce more options, as needed.
26
     * @param array $collaborators An array of collaborators that may be used to
27
     *                             override this provider's default behavior. Collaborators include
28
     *                             `grantFactory`, `requestFactory`, and `httpClient`.
29
     *                             Individual providers may introduce more collaborators, as needed.
30
     */
31
    public function __construct(array $options = [], array $collaborators = [])
32
    {
33
        parent::__construct($options, $collaborators);
34
        foreach ($options as $option => $value) {
35
            if (property_exists($this, $option)) {
36
                $this->{$option} = $value;
37
            }
38
        }
39
40
        if (empty($collaborators['grantFactory'])) {
41
            $collaborators['grantFactory'] = new GrantFactory();
42
        }
43
        $this->setGrantFactory($collaborators['grantFactory']);
44
45
        if (empty($collaborators['requestFactory'])) {
46
            $collaborators['requestFactory'] = new RequestFactory();
47
        }
48
        $this->setRequestFactory($collaborators['requestFactory']);
49
50
        if (empty($collaborators['httpClient'])) {
51
            $client_options = $this->getAllowedClientOptions($options);
52
53
            $collaborators['httpClient'] = new HttpClient(array_intersect_key($options, array_flip($client_options)));
54
        }
55
        $this->setHttpClient($collaborators['httpClient']);
56
        $this->twitter = new TwitterOAuth($this->getClientId(), $this->getClientSecret());
57
    }
58
59
    public function getClientId()
60
    {
61
        return $this->clientId;
62
    }
63
64
    public function getClientSecret()
65
    {
66
        return $this->clientSecret;
67
    }
68
69
    public function getBaseAuthorizationUrl()
70
    {
71
    }
72
73
    public function getBaseAccessTokenUrl(array $params = null)
74
    {
75
    }
76
77
    public function getDefaultScopes()
78
    {
79
        return [];
80
    }
81
82
    public function getResourceOwnerDetailsUrl(AccessToken $token)
83
    {
84
    }
85
86
    public function getRedirectUri()
87
    {
88
        return $this->redirectUri;
89
    }
90
91
    protected function createResourceOwner(array $response, AccessToken $token = null)
92
    {
93
    }
94
95
    protected function checkResponse(ResponseInterface $response, $data)
96
    {
97
    }
98
99
    public function setState($state = null)
100
    {
101
        $this->state = $state;
102
    }
103
}
104