Test Failed
Push — feature/api-versions ( a57f4c...a08e88 )
by Robin
02:32
created

BasicAuth::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Konsulting\JustGivingApiSdk\Support\Auth;
4
5
class BasicAuth 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 username of the JustGiving user being authenticated.
17
     *
18
     * @var string
19
     */
20
    protected $username;
21
22
    /**
23
     * The password of the JustGiving user being authenticated.
24
     *
25
     * @var string
26
     */
27
    protected $password;
28
29 9
    public function __construct($appId, $username, $password)
30
    {
31 9
        $this->username = $username;
32 9
        $this->password = $password;
33 9
        $this->appId = $appId;
34 9
    }
35
36
    /**
37
     * Get the authentication headers.
38
     *
39
     * @return array
40
     */
41 9
    public function getHeaders()
42
    {
43
        return [
44 9
            'Authorization' => 'Basic ' . base64_encode($this->username . ":" . $this->password),
45 9
            'x-api-key'     => $this->appId,
46
        ];
47
    }
48
}
49