Microsoft::getIdentity()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 8.125

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 15
nc 5
nop 1
dl 0
loc 25
ccs 6
cts 12
cp 0.5
crap 8.125
rs 9.4555
c 1
b 0
f 0
1
<?php
2
/**
3
 * SocialConnect project
4
 * @author: Patsura Dmitry https://github.com/ovr <[email protected]>
5
 * @author: Andreas Heigl https://github.com/heiglandreas <[email protected]>
6
 */
7
declare(strict_types=1);
8
9
namespace SocialConnect\OAuth2\Provider;
10
11
use SocialConnect\Common\ArrayHydrator;
12
use SocialConnect\Provider\AccessTokenInterface;
13
use SocialConnect\Common\Entity\User;
14
15
class Microsoft extends \SocialConnect\OAuth2\AbstractProvider
16
{
17
    const NAME = 'microsoft';
18
19
    /**
20
     * {@inheritdoc}
21
     */
22 4
    public function getBaseUri()
23
    {
24 4
        return 'https://apis.live.net/v5.0/';
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 2
    public function getAuthorizeUri()
31
    {
32 2
        return 'https://login.live.com/oauth20_authorize.srf';
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 2
    public function getRequestTokenUri()
39
    {
40 2
        return 'https://login.live.com/oauth20_token.srf';
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 3
    public function getName()
47
    {
48 3
        return self::NAME;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 3
    public function getIdentity(AccessTokenInterface $accessToken)
55
    {
56 3
        $response = $this->request('GET', 'me', [], $accessToken);
57
58 1
        $hydrator = new ArrayHydrator([
59
            'id' => 'id',
60
            'first_name' => 'firstname',
61
            'last_name' => 'lastname',
62
            'name' => 'fullname',
63
        ]);
64
65
        /** @var User $user */
66 1
        $user = $hydrator->hydrate(new User(), $response);
67
68 1
        if ($response['emails']) {
69
            if ($response['emails']['preferred']) {
70
                $user->email = $response['emails']['preferred'];
71
            } elseif ($response['emails']['account']) {
72
                $user->email = $response['emails']['account'];
73
            } elseif ($response['emails']['personal']) {
74
                $user->email = $response['emails']['personal'];
75
            }
76
        }
77
78 1
        return $user;
79
    }
80
}
81