Passed
Push — discord-provider ( 0e4f76 )
by AD
03:05
created

Steein   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 79
ccs 0
cts 42
cp 0
rs 10
c 1
b 0
f 0
wmc 11

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getRequestTokenUri() 0 3 1
A prepareRequest() 0 4 2
A getAuthorizeUri() 0 3 1
A getName() 0 3 1
A getBaseUri() 0 3 1
A getScopeInline() 0 3 1
A getIdentity() 0 22 4
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\Common\Entity\User;
13
14
class Steein extends \SocialConnect\OAuth2\AbstractProvider
15
{
16
    const NAME = 'steein';
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function getBaseUri()
22
    {
23
        return 'https://www.steein.ru/';
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function getAuthorizeUri()
30
    {
31
        return 'https://www.steein.ru/oauth/authorize';
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function getRequestTokenUri()
38
    {
39
        return 'https://www.steein.ru/oauth/token';
40
    }
41
42
    /**
43
     * @return string
44
     */
45
    public function getName()
46
    {
47
        return self::NAME;
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getScopeInline()
54
    {
55
        return implode(' ', $this->scope);
56
    }
57
58
    /**
59
     * {@inheritDoc}
60
     */
61
    public function prepareRequest(string $method, string $uri, array &$headers, array &$query, AccessTokenInterface $accessToken = null): void
62
    {
63
        if ($accessToken) {
64
            $headers['Authorization'] = "Bearer {$accessToken->getToken()}";
65
        }
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function getIdentity(AccessTokenInterface $accessToken)
72
    {
73
        $response = $this->request('GET', 'api/v2.0/users/show', [], $accessToken);
74
75
        $hydrator = new ArrayHydrator([
76
            'displayName' => 'fullname',
77
        ]);
78
79
        /** @var User $user */
80
        $user = $hydrator->hydrate(new User(), $response);
81
82
        if ($response['name']) {
83
            if ($response['name']['first_name']) {
84
                $user->firstname = $response['name']['first_name'];
85
            }
86
87
            if ($response['name']['last_name']) {
88
                $user->lastname = $response['name']['last_name'];
89
            }
90
        }
91
92
        return $user;
93
    }
94
}
95