GithubResourceOwner::getNickname()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace League\OAuth2\Client\Provider;
4
5
use League\OAuth2\Client\Tool\ArrayAccessorTrait;
6
7
class GithubResourceOwner implements ResourceOwnerInterface
8
{
9
    use ArrayAccessorTrait;
10
11
    /**
12
     * Domain
13
     *
14
     * @var string
15
     */
16
    protected $domain;
17
18
    /**
19
     * Raw response
20
     *
21
     * @var array
22
     */
23
    protected $response;
24
25
    /**
26
     * Creates new resource owner.
27
     *
28
     * @param array  $response
29
     */
30 12
    public function __construct(array $response = array())
31
    {
32 12
        $this->response = $response;
33 12
    }
34
35
    /**
36
     * Get resource owner id
37
     *
38
     * @return string|null
39
     */
40 3
    public function getId()
41
    {
42 3
        return $this->getValueByKey($this->response, 'id');
43
    }
44
45
    /**
46
     * Get resource owner email
47
     *
48
     * @return string|null
49
     */
50 3
    public function getEmail()
51
    {
52 3
        return $this->getValueByKey($this->response, 'email');
53
    }
54
55
    /**
56
     * Get resource owner name
57
     *
58
     * @return string|null
59
     */
60 3
    public function getName()
61
    {
62 3
        return $this->getValueByKey($this->response, 'name');
63
    }
64
65
    /**
66
     * Get resource owner nickname
67
     *
68
     * @return string|null
69
     */
70 12
    public function getNickname()
71
    {
72 12
        return $this->getValueByKey($this->response, 'login');
73
    }
74
75
    /**
76
     * Get resource owner url
77
     *
78
     * @return string|null
79
     */
80 12
    public function getUrl()
81
    {
82 12
        $urlParts = array_filter([$this->domain, $this->getNickname()]);
83
84 12
        return count($urlParts) ? implode('/', $urlParts) : null;
85
    }
86
87
    /**
88
     * Set resource owner domain
89
     *
90
     * @param  string $domain
91
     *
92
     * @return ResourceOwner
93
     */
94 6
    public function setDomain($domain)
95
    {
96 6
        $this->domain = $domain;
97
98 6
        return $this;
99
    }
100
101
    /**
102
     * Return all of the owner details available as an array.
103
     *
104
     * @return array
105
     */
106 3
    public function toArray()
107
    {
108 3
        return $this->response;
109
    }
110
}
111