DraugiemUser   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 131
rs 10
c 0
b 0
f 0
wmc 10

9 Methods

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