Passed
Push — master ( 9555ef...a5a811 )
by Manuele
01:31
created

OrbitronDevResourceOwner::getEmail()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace OrbitronDev\OAuth2\Client\Provider;
4
5
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
6
7
class OrbitronDevResourceOwner implements ResourceOwnerInterface
8
{
9
    /**
10
     * Raw response.
11
     *
12
     * @var array
13
     */
14
    protected $response;
15
16
    /**
17
     * Creates new resource owner.
18
     *
19
     * @param array $response Data received from the server about the user
20
     */
21 2
    public function __construct(array $response = [])
22
    {
23 2
        $this->response = $response;
24 2
    }
25
26
    /**
27
     * Returns the identifier of the authorized resource owner.
28
     *
29
     * @return int|null
30
     */
31 2
    public function getId()
32
    {
33 2
        return (int) $this->response['id'] ?: null;
34
    }
35
36
    /**
37
     * Return the username.
38
     *
39
     * @return string|null
40
     */
41 2
    public function getUsername()
42
    {
43 2
        return $this->response['username'] ?: null;
44
    }
45
46
    /**
47
     * Return the email.
48
     *
49
     * @return string|null
50
     */
51 2
    public function getEmail()
52
    {
53 2
        return $this->response['email'] ?: null;
54
    }
55
56
    /**
57
     * Return the first name.
58
     *
59
     * @return string|null
60
     */
61 2
    public function getFirstName()
62
    {
63 2
        return $this->response['name'] ?: null;
64
    }
65
66
    /**
67
     * Return the surname.
68
     *
69
     * @return string|null
70
     */
71 2
    public function getSurname()
72
    {
73 2
        return $this->response['surname'] ?: null;
74
    }
75
76
    /**
77
     * Return the birthday.
78
     *
79
     * @return \DateTime|null
80
     */
81 2
    public function getBirthday()
82
    {
83 2
        return $this->response['birthday'] ? (new \DateTime())->setTimestamp($this->response['birthday']) : null;
84
    }
85
86
    /**
87
     * Return the surname.
88
     *
89
     * @return array|null
90
     */
91 2
    public function getActiveAddress()
92
    {
93 2
        if (null === $this->getAddresses()) {
94
            return null;
95
        }
96
97 2
        if (1 === count($this->getAddresses())) {
98 2
            foreach ($this->getAddresses() as $address) {
99 2
                return $address;
100
            }
101
        }
102
103
        if (null === $this->response['active_address']) {
104
            return null;
105
        }
106
107
        return $this->getAddresses()[$this->response['active_address']];
108
    }
109
110
    /**
111
     * Return the surname.
112
     *
113
     * @return array|null
114
     */
115 2
    public function getAddresses()
116
    {
117 2
        return $this->response['addresses'] ?: null;
118
    }
119
120
    /**
121
     * Return the subscription.
122
     *
123
     * @return string|null
124
     */
125 2
    public function getSubscription()
126
    {
127 2
        return $this->response['subscription_type'] ?: null;
128
    }
129
130
    /**
131
     * Return all of the owner details available as an array.
132
     *
133
     * @return array
134
     */
135 2
    public function toArray()
136
    {
137 2
        return $this->response;
138
    }
139
}
140