Completed
Push — master ( ad69a5...d98011 )
by Дмитрий
03:25
created

Provider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
lcom 1
cbo 7
dl 0
loc 74
rs 10
c 1
b 1
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getBaseUri() 0 4 1
A getAuthorizeUri() 0 4 1
A getRequestTokenUri() 0 4 1
A getName() 0 4 1
A getIdentity() 0 48 1
1
<?php
2
/**
3
 * SocialConnect project
4
 * @author: Patsura Dmitry https://github.com/ovr <[email protected]>
5
 */
6
7
namespace SocialConnect\Github;
8
9
use SocialConnect\Auth\Provider\OAuth2\AccessToken;
10
use SocialConnect\Common\Entity\User;
11
use SocialConnect\Common\Hydrator\ObjectMap;
12
13
class Provider extends \SocialConnect\Auth\Provider\OAuth2\AbstractProvider
14
{
15
    public function getBaseUri()
16
    {
17
        return 'https://api.github.com/';
18
    }
19
20
    public function getAuthorizeUri()
21
    {
22
        return 'https://github.com/login/oauth/authorize';
23
    }
24
25
    public function getRequestTokenUri()
26
    {
27
        return 'https://github.com/login/oauth/access_token';
28
    }
29
30
    public function getName()
31
    {
32
        return 'github';
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function getIdentity(AccessToken $accessToken)
39
    {
40
        $response = $this->service->getHttpClient()->request(
41
            $this->getBaseUri() . 'user',
42
            [
43
                'access_token' => $accessToken->getToken()
44
            ]
45
        );
46
47
        $body = $response->getBody();
48
        $result = json_decode($body);
49
50
51
        $hydrator = new ObjectMap(array(
52
            'id' => 'id',
53
            'url' => 'api_url',
54
            'html_url' => 'url',
55
            'followers_url' => 'followers_url',
56
            'following_url' => 'following_url',
57
            'gists_url' => 'gists_url',
58
            'starred_url' => 'starred_url',
59
            'subscriptions_url' => 'subscriptions_url',
60
            'organizations_url' => 'organizations_url',
61
            'repos_url' => 'repos_url',
62
            'events_url' => 'events_url',
63
            'received_events_url' => 'received_events_url',
64
            'type' => 'type',
65
            'site_admin' => 'site_admin',
66
            'name' => 'name',
67
            'company' => 'company',
68
            'blog' => 'blog',
69
            'location' => 'location',
70
            'login' => 'login',
71
            'avatar_url' => 'avatar_url',
72
            'gravatar_id' => 'gravatar_id',
73
            'hireable' => 'hireable',
74
            'bio' => 'bio',
75
            'public_repos' => 'public_repos',
76
            'public_gists' => 'public_gists',
77
            'followers' => 'followers',
78
            'following' => 'following',
79
            'created_at' => 'created_at',
80
            'updated_at' => 'updated_at',
81
            'email' => 'email',
82
        ));
83
84
        return $hydrator->hydrate(new User(), $result);
85
    }
86
}
87