SalesforceResourceOwner   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 0
dl 0
loc 106
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getId() 0 4 1
A getFirstName() 0 4 1
A getLastName() 0 4 1
A getEmail() 0 4 1
A getTitle() 0 4 1
A getResponseData() 0 18 4
A toArray() 0 4 1
1
<?php namespace Stevenmaguire\OAuth2\Client\Provider;
2
3
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
4
5
class SalesforceResourceOwner implements ResourceOwnerInterface
6
{
7
    /**
8
     * Raw response
9
     *
10
     * @var array
11
     */
12
    protected $response;
13
14
    /**
15
     * Creates new resource owner.
16
     *
17
     * @param array  $response
18
     */
19 2
    public function __construct(array $response = array())
20
    {
21 2
        $this->response = $response;
22 2
    }
23
24
    /**
25
     * Get user id
26
     *
27
     * @return string|null
28
     */
29 2
    public function getId()
30
    {
31 2
        return $this->getResponseData('user_id');
32
    }
33
34
    /**
35
     * Get user first name
36
     *
37
     * @return string|null
38
     */
39 2
    public function getFirstName()
40
    {
41 2
        return $this->getResponseData('first_name');
42
    }
43
44
    /**
45
     * Get user last name
46
     *
47
     * @return string|null
48
     */
49 2
    public function getLastName()
50
    {
51 2
        return $this->getResponseData('last_name');
52
    }
53
54
    /**
55
     * Get user email
56
     *
57
     * @return string|null
58
     */
59 2
    public function getEmail()
60
    {
61 2
        return $this->getResponseData('email');
62
    }
63
64
    /**
65
     * Get user title
66
     *
67
     * @return string|null
68
     */
69 2
    public function getTitle()
70
    {
71 2
        return $this->getResponseData('custom_attributes.title');
72
    }
73
74
    /**
75
     * Attempts to pull value from array using dot notation.
76
     *
77
     * @param string $path
78
     * @param string $default
79
     *
80
     * @return mixed
81
     */
82 2
    protected function getResponseData($path, $default = null)
83
    {
84 2
        $array = $this->response;
85
86 2
        if (!empty($path)) {
87 2
            $keys = explode('.', $path);
88
89 2
            foreach ($keys as $key) {
90 2
                if (isset($array[$key])) {
91 2
                    $array = $array[$key];
92 1
                } else {
93 2
                    return $default;
94
                }
95 1
            }
96 1
        }
97
98 2
        return $array;
99
    }
100
101
    /**
102
     * Return all of the owner details available as an array.
103
     *
104
     * @return array
105
     */
106 2
    public function toArray()
107
    {
108 2
        return $this->response;
109
    }
110
}
111