Passed
Push — master ( 3948f8...d3c224 )
by Dāvis
07:09
created

DraugiemUser::getLastName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sludio\HelperBundle\Oauth\Client\Provider\Draugiem;
4
5
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
6
use Sludio\HelperBundle\Oauth\Component\SocialUserInterface;
7
8
class DraugiemUser implements ResourceOwnerInterface, SocialUserInterface
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $response;
14
15
    protected $userData;
16
17
    /**
18
     * @var integer
19
     */
20
    protected $id;
21
22
    /**
23
     * @var string
24
     */
25
    protected $email;
26
27
    /**
28
     * @var string
29
     */
30
    protected $firstName;
31
32
    /**
33
     * @var string
34
     */
35
    protected $lastName;
36
37
    /**
38
     * @var string
39
     */
40
    protected $username;
41
42
    /**
43
     * @var bool
44
     */
45
    protected $returnsEmail = false;
46
47
    /**
48
     * @return bool
49
     */
50
    public function returnsEmail()
51
    {
52
        return $this->returnsEmail;
53
    }
54
55
    /**
56
     * @param  array $response
57
     */
58
    public function __construct(array $response)
59
    {
60
        $this->response = $response;
61
        $this->userData = reset($this->response['users']);
62
63
        $this->id = (int)$this->response['uid'];
64
65
        $this->firstName = $this->getField('name');
66
67
        $this->lastName = $this->getField('surname');
68
69
        $this->username = preg_replace('/[^a-z\d]/i', '', $this->getField('url'));
70
    }
71
72
    /**
73
     * Returns a field from the Graph node data.
74
     *
75
     * @param string $key
76
     *
77
     * @return mixed|null
78
     */
79
    private function getField($key)
80
    {
81
        return isset($this->userData[$key]) ? $this->userData[$key] : null;
82
    }
83
84
    /**
85
     * Returns all the data obtained about the user.
86
     *
87
     * @return array
88
     */
89
    public function toArray()
90
    {
91
        return $this->response;
92
    }
93
94
    /**
95
     * Get the value of Id
96
     *
97
     * @return integer
98
     */
99
    public function getId()
100
    {
101
        return $this->id;
102
    }
103
104
    /**
105
     * Get the value of Email
106
     *
107
     * @return string
108
     */
109
    public function getEmail()
110
    {
111
        return $this->email;
112
    }
113
114
    /**
115
     * Get the value of First Name
116
     *
117
     * @return string
118
     */
119
    public function getFirstName()
120
    {
121
        return $this->firstName;
122
    }
123
124
    /**
125
     * Get the value of Last Name
126
     *
127
     * @return string
128
     */
129
    public function getLastName()
130
    {
131
        return $this->lastName;
132
    }
133
134
    /**
135
     * Get the value of Username
136
     *
137
     * @return string
138
     */
139
    public function getUsername()
140
    {
141
        return $this->username;
142
    }
143
}
144