Vimeo   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Test Coverage

Coverage 70.83%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 78
rs 10
c 0
b 0
f 0
ccs 17
cts 24
cp 0.7083
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getBaseUri() 0 3 1
A getRequestTokenUri() 0 3 1
A getAuthorizeUri() 0 3 1
A getName() 0 3 1
A parseToken() 0 26 4
A getIdentity() 0 3 1
1
<?php
2
/**
3
 * SocialConnect project
4
 * @author: Patsura Dmitry https://github.com/ovr <[email protected]>
5
 */
6
declare(strict_types=1);
7
8
namespace SocialConnect\OAuth2\Provider;
9
10
use SocialConnect\Common\ArrayHydrator;
11
use SocialConnect\Provider\AccessTokenInterface;
12
use SocialConnect\Provider\Exception\InvalidAccessToken;
13
use SocialConnect\OAuth2\AccessToken;
14
use SocialConnect\Common\Entity\User;
15
16
class Vimeo extends \SocialConnect\OAuth2\AbstractProvider
17
{
18
    const NAME = 'vimeo';
19
20
    /**
21
     * @var User|null
22
     */
23
    protected $user;
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 1
    public function getBaseUri()
29
    {
30 1
        return 'https://api.vimeo.com/';
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 2
    public function getAuthorizeUri()
37
    {
38 2
        return 'https://api.vimeo.com/oauth/authorize';
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 2
    public function getRequestTokenUri()
45
    {
46 2
        return 'https://api.vimeo.com/oauth/access_token';
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 3
    public function getName()
53
    {
54 3
        return self::NAME;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60 4
    public function parseToken(string $body)
61
    {
62 4
        if (empty($body)) {
63 1
            throw new InvalidAccessToken('Provider response with empty body');
64
        }
65
66 3
        $response = json_decode($body, true);
67 3
        if ($response) {
68 1
            $token = new AccessToken($response);
69
70
            // Vimeo return User on get Access Token Request (looks like to protect round trips)
71 1
            if (isset($response['user'])) {
72
                $hydrator = new ArrayHydrator([
73
                    'name' => 'fullname',
74
                ]);
75
76
                $this->user = $hydrator->hydrate(new User(), $response['user']);
77
                $this->user->id = str_replace('/users/', '', $this['user']['uri']);
78
79
                $token->setUserId((string) $this->user->id);
80
            }
81
82 1
            return $token;
83
        }
84
85 2
        throw new InvalidAccessToken('AccessToken is not a valid JSON');
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function getIdentity(AccessTokenInterface $accessToken)
92
    {
93
        return $this->user;
94
    }
95
}
96