Passed
Push — master ( 308857...bdcf08 )
by Manuele
02:16
created

OrbitronDevResourceOwner::getAddresses()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 6
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
    public function __construct(array $response = [])
22
    {
23
        $this->response = $response;
24
    }
25
26
    /**
27
     * Returns the identifier of the authorized resource owner.
28
     *
29
     * @return int|null
30
     */
31
    public function getId()
32
    {
33
        return (int)$this->response['id'] ?: null;
34
    }
35
36
    /**
37
     * Return the username
38
     *
39
     * @return string|null
40
     */
41
    public function getUsername()
42
    {
43
        return $this->response['username'] ?: null;
44
    }
45
46
    /**
47
     * Return the email
48
     *
49
     * @return string|null
50
     */
51
    public function getEmail()
52
    {
53
        return $this->response['email'] ?: null;
54
    }
55
56
    /**
57
     * Return the first name
58
     *
59
     * @return string|null
60
     */
61
    public function getFirstName()
62
    {
63
        return $this->response['name'] ?: null;
64
    }
65
66
    /**
67
     * Return the surname
68
     *
69
     * @return string|null
70
     */
71
    public function getSurname()
72
    {
73
        return $this->response['surname'] ?: null;
74
    }
75
76
    /**
77
     * Return the birthday
78
     *
79
     * @return \DateTime|null
80
     */
81
    public function getBirthday()
82
    {
83
        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
    public function getActiveAddress()
92
    {
93
        if (is_null($this->getAddresses())) {
94
            return null;
95
        }
96
        if (is_null($this->response['active_address'])) {
97
            return null;
98
        }
99
100
        return $this->getAddresses()[$this->response['active_address']];
101
    }
102
103
    /**
104
     * Return the surname
105
     *
106
     * @return array|null
107
     */
108
    public function getAddresses()
109
    {
110
        return $this->response['addresses'] ?: null;
111
    }
112
113
    /**
114
     * Return the subscription
115
     *
116
     * @return string|null
117
     */
118
    public function getSubscription()
119
    {
120
        return $this->response['subscription_type'] ?: null;
121
    }
122
123
    /**
124
     * Return all of the owner details available as an array.
125
     *
126
     * @return array
127
     */
128
    public function toArray()
129
    {
130
        return $this->response;
131
    }
132
}
133