Completed
Pull Request — master (#3)
by Márk
02:31
created

BasicAuth::authenticate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Http\Message\Authentication;
4
5
use Http\Message\Authentication;
6
use Psr\Http\Message\RequestInterface;
7
8
/**
9
 * Authenticate a PSR-7 Request using Basic Auth.
10
 *
11
 * @author Márk Sági-Kazár <[email protected]>
12
 */
13
final class BasicAuth implements Authentication
14
{
15
    use UserPasswordPair;
16
17
    /**
18
     * @param string $username
19
     * @param string $password
20
     */
21 7
    public function __construct($username, $password)
22
    {
23 7
        $this->username = $username;
24 7
        $this->password = $password;
25 7
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 1
    public function authenticate(RequestInterface $request)
31
    {
32 1
        $header = sprintf('Basic %s', base64_encode(sprintf('%s:%s', $this->username, $this->password)));
33
34 1
        return $request->withHeader('Authorization', $header);
35
    }
36
}
37