Completed
Pull Request — master (#5)
by
unknown
03:27
created

LinkedInResourceOwner::getField()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 1
crap 2
1
<?php namespace League\OAuth2\Client\Provider;
2
3
/**
4
 * @property array $response
5
 * @property string $uid
6
 */
7
class LinkedInResourceOwner extends GenericResourceOwner
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
20
     */
21 6
    public function __construct(array $response = array())
22
    {
23 6
        $this->response = $response;
24 6
    }
25
26
    /**
27
     * Get user email
28
     *
29
     * @return string|null
30
     */
31 6
    public function getEmail()
32
    {
33 6
        return $this->getField('emailAddress');
34
    }
35
36
    /**
37
     * Get user firstname
38
     *
39
     * @return string|null
40
     */
41 6
    public function getFirstName()
42
    {
43 6
        return $this->getField('firstName');
44
    }
45
46
    /**
47
     * Get user imageurl
48
     *
49
     * @return string|null
50
     */
51 6
    public function getImageurl()
52
    {
53 6
        return $this->getField('pictureUrl');
54
    }
55
56
    /**
57
     * Get user lastname
58
     *
59
     * @return string|null
60
     */
61 6
    public function getLastName()
62
    {
63 6
        return $this->getField('lastName');
64
    }
65
66
    /**
67
     * Get user userId
68
     *
69
     * @return string|null
70
     */
71 6
    public function getId()
72
    {
73 6
        return $this->getField('id');
74
    }
75
76
    /**
77
     * Get user location
78
     *
79
     * @return string|null
80
     */
81 6
    public function getLocation()
82
    {
83 6
        if (isset($this->response['location']['name'])) {
84 6
            return $this->response['location']['name'];
85
        }
86
        return null;
87
    }
88
89
    /**
90
     * Get user description
91
     *
92
     * @return string|null
93
     */
94 6
    public function getDescription()
95
    {
96 6
        return $this->getField('headline');
97
    }
98
99
    /**
100
     * Get user url
101
     *
102
     * @return string|null
103
     */
104 6
    public function getUrl()
105
    {
106 6
        return $this->getField('publicProfileUrl');
107
    }
108
109
    /**
110
     * Return all of the owner details available as an array.
111
     *
112
     * @return array
113
     */
114 6
    public function toArray()
115
    {
116 6
        return $this->response;
117
    }
118
119
    /**
120
     * Returns a field from the response data.
121
     *
122
     * @param string $key
123
     *
124
     * @return mixed|null
125
     */
126 6
    private function getField($key)
127
    {
128 6
        return isset($this->response[$key]) ? $this->response[$key] : null;
129
    }
130
}
131