Passed
Push — feature/api-versions ( 00c9fc...d9c41a )
by Robin
25:41 queued 16:25
created

BearerAuth   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 44.44%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 47
ccs 4
cts 9
cp 0.4444
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getHeaders() 0 8 1
1
<?php
2
3
namespace Konsulting\JustGivingApiSdk\Support\Auth;
4
5
class BearerAuth implements AuthValue
6
{
7
    /**
8
     * The application ID (also known as API key).
9
     *
10
     * @see https://developer.justgiving.com/apidocs/documentation#AppId
11
     * @var string
12
     */
13
    protected $appId;
14
15
    /**
16
     * The bearer token obtained via oAuth.
17
     *
18
     * @see https://justgivingdeveloper.zendesk.com/hc/en-us/articles/207071499-Getting-a-bearer-token
19
     * @var string
20
     */
21
    protected $token;
22
23
    /**
24
     * The secret key provided by JustGiving (this currently has to be requested manually).
25
     *
26
     * @see https://justgivingdeveloper.zendesk.com/hc/en-us/articles/115002238925-How-do-I-get-a-secret-key-
27
     * @var string
28
     */
29
    protected $secretKey;
30
31
    public function __construct($appId, $secretKey, $token)
32
    {
33
        $this->appId = $appId;
34
        $this->token = $token;
35
        $this->secretKey = $secretKey;
36
    }
37
38
    /**
39
     * Get the authentication headers.
40
     *
41
     * @return array
42
     */
43 1
    public function getHeaders()
44
    {
45
        return [
46 1
            'Authorization'     => 'Bearer ' . $this->token,
47 1
            'x-api-key'         => $this->appId,
48 1
            'x-application-key' => $this->secretKey,
49
        ];
50
    }
51
}
52