Completed
Push — master ( deb54b...06ec1a )
by Дмитрий
01:56
created

src/OAuth1/Provider/Px500.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\Common\Http\Client\Client;
10
use SocialConnect\Provider\AccessTokenInterface;
11
use SocialConnect\Provider\Exception\InvalidResponse;
12
use SocialConnect\OAuth1\AbstractProvider;
13
use SocialConnect\Common\Entity\User;
14
use SocialConnect\Common\Hydrator\ObjectMap;
15
16
class Px500 extends AbstractProvider
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function getBaseUri()
22
    {
23
        return 'https://api.500px.com/v1/';
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function getAuthorizeUri()
30
    {
31
        return 'https://api.500px.com/v1/oauth/authorize';
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function getRequestTokenUri()
38
    {
39
        return 'https://api.500px.com/v1/oauth/request_token';
40
    }
41
42
    /**
43
     * @return string
44
     */
45
    public function getRequestTokenAccessUri()
46
    {
47
        return 'https://api.500px.com/v1/oauth/access_token';
48
    }
49
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function getName()
55
    {
56
        return 'px500';
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function getIdentity(AccessTokenInterface $accessToken)
63
    {
64
        $this->consumerToken = $accessToken;
0 ignored issues
show
Documentation Bug introduced by Dmitry Patsura
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...
65
66
        $parameters = [
67
            'oauth_consumer_key' => $this->consumer->getKey(),
68
            'oauth_token' => $accessToken->getToken()
69
        ];
70
71
        $response = $this->oauthRequest(
72
            $this->getBaseUri() . 'users',
73
            Client::GET,
74
            $parameters
75
        );
76
77
        if (!$response->isSuccess()) {
78
            throw new InvalidResponse(
79
                'API response with error code',
80
                $response
81
            );
82
        }
83
84
        $result = $response->json();
85
        if (!$result) {
86
            throw new InvalidResponse(
87
                'API response is not a valid JSON object',
88
                $response->getBody()
89
            );
90
        }
91
92
        if (!isset($result->user) || !$result->user) {
93
            throw new InvalidResponse(
94
                'API response without user inside JSON',
95
                $response->getBody()
96
            );
97
        }
98
99
        $hydrator = new ObjectMap(
100
            [
101
                'id' => 'id',
102
                'name' => 'name',
103
            ]
104
        );
105
106
        return $hydrator->hydrate(new User(), $result->user);
107
    }
108
}
109