Completed
Pull Request — master (#79)
by
unknown
06:54
created

GoogleUser::getFirstName()   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|null
39
     */
40
    public function getFirstName()
41
    {
42
        return $this->getResponseValue('given_name');
43
    }
44
45
    /**
46
     * Get preferred last name.
47
     *
48
     * @return string|null
49
     */
50
    public function getLastName()
51
    {
52
        return $this->getResponseValue('family_name');
53
    }
54
55
    /**
56
     * Get locale.
57
     *
58
     * @return string|null
59
     */
60
    public function getLocale()
61
    {
62
        return $this->getResponseValue('locale');
63
    }
64
65
    /**
66
     * Get email address.
67
     *
68
     * @return string|null
69
     */
70
    public function getEmail()
71
    {
72
        return $this->getResponseValue('email');
73
    }
74
75
    /**
76
     * Get hosted domain.
77
     *
78
     * @return string|null
79
     */
80
    public function getHostedDomain()
81
    {
82
        return $this->getResponseValue('hd');
83
    }
84
85
    /**
86
     * Get avatar image URL.
87
     *
88
     * @return string|null
89
     */
90
    public function getAvatar()
91
    {
92
        return $this->getResponseValue('picture');
93
    }
94
95
    /**
96
     * Get user data as an array.
97
     *
98
     * @return array
99
     */
100
    public function toArray()
101
    {
102
        return $this->response;
103
    }
104
105
    private function getResponseValue($key)
106
    {
107
        if (array_key_exists($key, $this->response)) {
108
            return $this->response[$key];
109
        }
110
        return null;
111
    }
112
}
113