Passed
Push — master ( 8eea92...da79af )
by Dāvis
03:03
created

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