Completed
Pull Request — master (#14)
by Márk
03:42
created

AuthenticationPlugin   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handleRequest() 0 6 1
1
<?php
2
3
namespace Http\Client\Common\Plugin;
4
5
use Http\Client\Common\Plugin;
6
use Http\Message\Authentication;
7
use Psr\Http\Message\RequestInterface;
8
9
/**
10
 * Send an authenticated request.
11
 *
12
 * @author Joel Wurtz <[email protected]>
13
 *
14
 * TODO: make class final in version 2.0, once plugins does not extend it anymore.
15
 */
16
/*final*/ class AuthenticationPlugin implements Plugin
17
{
18
    /**
19
     * @var Authentication An authentication system
20
     */
21
    private $authentication;
22
23
    /**
24
     * @param Authentication $authentication
25
     */
26 3
    public function __construct(Authentication $authentication)
27
    {
28 3
        $this->authentication = $authentication;
29 3
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 1
    public function handleRequest(RequestInterface $request, callable $next, callable $first)
35
    {
36 1
        $request = $this->authentication->authenticate($request);
37
38 1
        return $next($request);
39
    }
40
}
41