Completed
Push — master ( bda8d5...d74c6d )
by Дмитрий
03:32 queued 01:52
created

Vimeo::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * SocialConnect project
4
 * @author: Patsura Dmitry https://github.com/ovr <[email protected]>
5
 */
6
7
namespace SocialConnect\OAuth2\Provider;
8
9
use SocialConnect\Provider\AccessTokenInterface;
10
use SocialConnect\Provider\Exception\InvalidAccessToken;
11
use SocialConnect\OAuth2\AccessToken;
12
use SocialConnect\Common\Entity\User;
13
use SocialConnect\Common\Hydrator\ObjectMap;
14
15
class Vimeo extends \SocialConnect\OAuth2\AbstractProvider
16
{
17
    const NAME = 'vimeo';
18
19
    /**
20
     * @var User|null
21
     */
22
    protected $user;
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 1
    public function getBaseUri()
28
    {
29 1
        return 'https://api.vimeo.com/';
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 2
    public function getAuthorizeUri()
36
    {
37 2
        return 'https://api.vimeo.com/oauth/authorize';
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 2
    public function getRequestTokenUri()
44
    {
45 2
        return 'https://api.vimeo.com/oauth/access_token';
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 3
    public function getName()
52
    {
53 3
        return self::NAME;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 3
    public function parseToken($body)
60
    {
61 3
        $response = json_decode($body, true);
62 3
        if ($response) {
63 1
            $token = new AccessToken($response);
64
65
            // Vimeo return User on get Access Token Request (looks like to protect round trips)
66 1
            if (isset($response['user'])) {
67
                $hydrator = new ObjectMap(
68
                    [
69
                        'name' => 'fullname',
70
                    ]
71
                );
72
73
                $this->user = $hydrator->hydrate(new User(), (object) $response['user']);
74
                $this->user->id = str_replace('/users/', '', $this->user->uri);
0 ignored issues
show
Bug introduced by
The property uri does not seem to exist on SocialConnect\Common\Entity\User.
Loading history...
75
76
                $token->setUid($this->user->id);
77
            }
78
79 1
            return $token;
80
        }
81
82 2
        throw new InvalidAccessToken('AccessToken is not a valid JSON');
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function getIdentity(AccessTokenInterface $accessToken)
89
    {
90
        return $this->user;
91
    }
92
}
93