Completed
Pull Request — master (#14)
by Márk
05:00
created

AuthenticationPlugin::handleRequest()   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.4285
cc 1
eloc 3
nc 1
nop 3
crap 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