Completed
Branch develop (bc30b7)
by Alexandre
01:48
created

JiraResourceOwner::toArray()   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 Mrjoops\OAuth2\Client\Provider;
4
5
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
6
use League\OAuth2\Client\Tool\ArrayAccessorTrait;
7
8
class JiraResourceOwner implements ResourceOwnerInterface
9
{
10
    use ArrayAccessorTrait;
11
12
    /**
13
     * Raw response
14
     *
15
     * @var array
16
     */
17
    protected $response;
18
19
    /**
20
     * Creates new resource owner.
21
     *
22
     * @param array  $response
23
     */
24
    public function __construct(array $response = [])
25
    {
26
        $this->response = $response;
27
    }
28
29
    /**
30
     * Get resource owner avatar url
31
     *
32
     * @return string|null
33
     */
34
    public function getAvatarUrl()
35
    {
36
        return $this->getValueByKey($this->response, '0.avatarUrl');
37
    }
38
39
    /**
40
     * Get resource owner id
41
     *
42
     * @return string|null
43
     */
44
    public function getId()
45
    {
46
        return $this->getValueByKey($this->response, '0.id');
47
    }
48
49
    /**
50
     * Get resource owner name
51
     *
52
     * @return string|null
53
     */
54
    public function getName()
55
    {
56
        return $this->getValueByKey($this->response, '0.name');
57
    }
58
59
    /**
60
     * Get resource owner scopes
61
     *
62
     * @return array|null
63
     */
64
    public function getScopes()
65
    {
66
        return $this->getValueByKey($this->response, '0.scopes');
67
    }
68
69
    /**
70
     * Get resource owner url
71
     *
72
     * @return string|null
73
     */
74
    public function getUrl()
75
    {
76
        return ($cloudId = $this->getId()) ? 'https://api.atlassian.com/ex/jira/'.$cloudId.'/' : null;
77
    }
78
79
    /**
80
     * Return all of the owner details available as an array.
81
     *
82
     * @return array
83
     */
84
    public function toArray()
85
    {
86
        return current($this->response);
87
    }
88
}
89