Passed
Push — master ( bdcf08...aa5f9e )
by Manuele
02:26
created

OrbitronDevResourceOwner   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 131
ccs 0
cts 54
cp 0
rs 10
c 0
b 0
f 0
wmc 23

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getId() 0 3 2
A getEmail() 0 3 2
A getUsername() 0 3 2
A getSurname() 0 3 2
A getFirstName() 0 3 2
A getBirthday() 0 3 2
A getSubscription() 0 3 2
B getActiveAddress() 0 17 5
A getAddresses() 0 3 2
A toArray() 0 3 1
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
97
        if (count($this->getAddresses()) == 1) {
98
            foreach ($this->getAddresses() as $address) {
99
                return $address;
100
            }
101
        }
102
103
        if (is_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
    public function getAddresses()
116
    {
117
        return $this->response['addresses'] ?: null;
118
    }
119
120
    /**
121
     * Return the subscription
122
     *
123
     * @return string|null
124
     */
125
    public function getSubscription()
126
    {
127
        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
    public function toArray()
136
    {
137
        return $this->response;
138
    }
139
}
140