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

BasicAuth   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 24
wmc 2
lcom 1
cbo 2
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A authenticate() 0 6 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