Completed
Push — master ( ae2ac3...9482a8 )
by Woody
10s
created

GoogleUser::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace League\OAuth2\Client\Provider;
4
5
class GoogleUser implements ResourceOwnerInterface
6
{
7
    /**
8
     * @var array
9
     */
10
    protected $response;
11
12
    /**
13
     * @param array $response
14
     */
15
    public function __construct(array $response)
16
    {
17
        $this->response = $response;
18
    }
19
20
    public function getId()
21
    {
22
        return $this->response['sub'];
23
    }
24
25
    /**
26
     * Get preferred display name.
27
     *
28
     * @return string
29
     */
30
    public function getName()
31
    {
32
        return $this->response['name'];
33
    }
34
35
    /**
36
     * Get preferred first name.
37
     *
38
     * @return string
39
     */
40
    public function getFirstName()
41
    {
42
        return $this->response['given_name'];
43
    }
44
45
    /**
46
     * Get preferred last name.
47
     *
48
     * @return string
49
     */
50
    public function getLastName()
51
    {
52
        return $this->response['family_name'];
53
    }
54
55
    /**
56
     * Get locale.
57
     *
58
     * @return string|null
59
     */
60
    public function getLocale()
61
    {
62
        if (array_key_exists('locale', $this->response)) {
63
            return $this->response['locale'];
64
        }
65
        return null;
66
    }
67
68
    /**
69
     * Get email address.
70
     *
71
     * @return string|null
72
     */
73
    public function getEmail()
74
    {
75
        if (array_key_exists('email', $this->response)) {
76
            return $this->response['email'];
77
        }
78
        return null;
79
    }
80
81
    /**
82
     * Get hosted domain.
83
     *
84
     * @return string|null
85
     */
86
    public function getHostedDomain()
87
    {
88
        if (array_key_exists('hd', $this->response)) {
89
            return $this->response['hd'];
90
        }
91
        return null;
92
    }
93
94
    /**
95
     * Get avatar image URL.
96
     *
97
     * @return string|null
98
     */
99
    public function getAvatar()
100
    {
101
        if (array_key_exists('picture', $this->response)) {
102
            return $this->response['picture'];
103
        }
104
        return null;
105
    }
106
107
    /**
108
     * Get user data as an array.
109
     *
110
     * @return array
111
     */
112
    public function toArray()
113
    {
114
        return $this->response;
115
    }
116
}
117