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

Google::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
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;
0 ignored issues
show
Bug introduced by
The type SocialConnect\Common\Entity\User was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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 1
    public function getBaseUri()
32
    {
33 1
        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
    public function getIdentity(AccessTokenInterface $accessToken)
64
    {
65
        $response = $this->request('GET', 'oauth2/v1/userinfo', [], $accessToken);
66
67
        $hydrator = new ArrayHydrator([
68
            'id' => 'id',
69
            'given_name' => 'firstname',
70
            'family_name' => 'lastname',
71
            'email' => 'email',
72
            'verified_email' => 'emailVerified',
73
            'name' => 'fullname',
74
            'gender' => static function ($value, User $user) {
75
                $user->setSex($value);
76
            },
77
        ]);
78
79
        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