Passed
Push — heiglandreas-patch-1 ( 8f4377...c6f183 )
by Andreas
03:53
created

Google::getIdentity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1.0005

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 1
eloc 11
c 2
b 1
f 0
nc 1
nop 1
dl 0
loc 17
ccs 11
cts 12
cp 0.9167
crap 1.0005
rs 9.9
1
<?php
2
/**
3
 * SocialConnect project
4
 * @author: Patsura Dmitry https://github.com/ovr <[email protected]>
5
 * @author Alexander Fedyashov <[email protected]>
6
 */
7
declare(strict_types=1);
8
9
namespace SocialConnect\OpenIDConnect\Provider;
10
11
use SocialConnect\Common\ArrayHydrator;
12
use SocialConnect\Provider\AccessTokenInterface;
13
use SocialConnect\OpenIDConnect\AbstractProvider;
14
use SocialConnect\Common\Entity\User;
15
16
class Google extends AbstractProvider
17
{
18
    const NAME = 'google';
19
20
    /**
21
     * {@inheritdoc}
22
     */
23 1
    public function getOpenIdUrl()
24
    {
25 1
        return 'https://accounts.google.com/.well-known/openid-configuration';
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 2
    public function getBaseUri()
32
    {
33 2
        return 'https://www.googleapis.com/';
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 1
    public function getAuthorizeUri()
40
    {
41 1
        return 'https://accounts.google.com/o/oauth2/auth';
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 1
    public function getRequestTokenUri()
48
    {
49 1
        return 'https://accounts.google.com/o/oauth2/token';
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 1
    public function getName()
56
    {
57 1
        return self::NAME;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 1
    public function getIdentity(AccessTokenInterface $accessToken)
64
    {
65 1
        $response = $this->request('GET', 'oauth2/v1/userinfo', [], $accessToken);
66
67 1
        $hydrator = new ArrayHydrator([
68 1
            'id' => 'id',
69 1
            'given_name' => 'firstname',
70 1
            'family_name' => 'lastname',
71 1
            'email' => 'email',
72 1
            'verified_email' => 'emailVerified',
73 1
            'name' => 'fullname',
74
            'gender' => static function ($value, User $user) {
75
                $user->setSex($value);
0 ignored issues
show
Deprecated Code introduced by
The function SocialConnect\Common\Entity\User::setSex() has been deprecated: Use setGender instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

75
                /** @scrutinizer ignore-deprecated */ $user->setSex($value);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
76 1
            },
77
        ]);
78
79 1
        return $hydrator->hydrate(new User(), $response);
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function getScopeInline()
86
    {
87
        return implode(' ', $this->scope);
88
    }
89
}
90