Completed
Push — master ( a178a2...762452 )
by Дмитрий
03:58
created

Twitter::getIdentity()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 39
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 23
nc 3
nop 1
1
<?php
2
/**
3
 * SocialConnect project
4
 * @author: Patsura Dmitry https://github.com/ovr <[email protected]>
5
 */
6
7
namespace SocialConnect\OAuth1\Provider;
8
9
use SocialConnect\Provider\AccessTokenInterface;
10
use SocialConnect\Provider\Exception\InvalidResponse;
11
use SocialConnect\Common\Entity\User;
12
use SocialConnect\Common\Http\Client\Client;
13
use SocialConnect\Common\Hydrator\ObjectMap;
14
15
class Twitter extends \SocialConnect\OAuth1\AbstractProvider
16
{
17
    public function getBaseUri()
18
    {
19
        return 'https://api.twitter.com/1.1/';
20
    }
21
22
    public function getAuthorizeUri()
23
    {
24
        return 'https://api.twitter.com/oauth/authenticate';
25
    }
26
27
    public function getRequestTokenUri()
28
    {
29
        return 'https://api.twitter.com/oauth/request_token';
30
    }
31
32
    public function getRequestTokenAccessUri()
33
    {
34
        return 'https://api.twitter.com/oauth/access_token';
35
    }
36
37
    public function getName()
38
    {
39
        return 'twitter';
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getIdentity(AccessTokenInterface $accessToken)
46
    {
47
        $this->consumerToken = $accessToken;
0 ignored issues
show
Documentation Bug introduced by
It seems like $accessToken of type object<SocialConnect\Pro...r\AccessTokenInterface> is incompatible with the declared type object<SocialConnect\OAuth1\Token> of property $consumerToken.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
48
49
        $parameters = $this->requestTokenParams;
50
        $parameters['user_id'] = $accessToken->getUserId();
51
52
        $response = $this->oauthRequest(
53
            $this->getBaseUri() . 'users/lookup.json',
54
            Client::GET,
55
            $parameters,
56
            $this->requestTokenHeaders
57
        );
58
59
        if (!$response->isSuccess()) {
60
            throw new InvalidResponse(
61
                'API response with error code',
62
                $response
63
            );
64
        }
65
66
        $result = $response->json();
67
        if (!$result) {
68
            throw new InvalidResponse(
69
                'API response is not a valid JSON object',
70
                $response->getBody()
71
            );
72
        }
73
74
        $hydrator = new ObjectMap(
75
            [
76
                'id' => 'id',
77
                'name' => 'fullname',
78
                'screen_name' => 'username'
79
            ]
80
        );
81
82
        return $hydrator->hydrate(new User(), $result[0]);
83
    }
84
}
85