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

AppAuth::getHeaders()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Konsulting\JustGivingApiSdk\Support\Auth;
4
5
class AppAuth implements AuthValue
6
{
7
    /**
8
     * The application ID.
9
     *
10
     * @see https://developer.justgiving.com/apidocs/documentation#AppId
11
     * @var string
12
     */
13
    protected $appId;
14
15
    /**
16
     * The secret key associated with the App ID. Required if JustGiving have set up a secret key for the app.
17
     *
18
     * @var string
19
     */
20
    protected $secretKey;
21
22
    /**
23
     * AppAuth constructor.
24
     *
25
     * @param string $appId
26
     * @param string $secretKey
27
     */
28
    public function __construct($appId, $secretKey = null)
29
    {
30
        $this->appId = $appId;
31
        $this->secretKey = $secretKey;
32
    }
33
34
    /**
35
     * Get the authentication headers.
36
     *
37
     * @return array
38
     */
39 2
    public function getHeaders()
40
    {
41 2
        $headers = ['x-api-key' => $this->appId];
42
43 2
        if ($this->secretKey !== null) {
44 1
            $headers['x-application-key'] = $this->secretKey;
45
        }
46
47 2
        return $headers;
48
    }
49
}
50