RequestConditional   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 28
ccs 6
cts 6
cp 1
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A authenticate() 0 7 2
1
<?php
2
3
namespace Http\Message\Authentication;
4
5
use Http\Message\Authentication;
6
use Http\Message\RequestMatcher;
7
use Psr\Http\Message\RequestInterface;
8
9
/**
10
 * Authenticate a PSR-7 Request if the request is matching the given request matcher.
11
 *
12
 * @author Márk Sági-Kazár <[email protected]>
13
 */
14
final class RequestConditional implements Authentication
15
{
16
    /**
17
     * @var RequestMatcher
18
     */
19
    private $requestMatcher;
20
21
    /**
22
     * @var Authentication
23
     */
24
    private $authentication;
25
26
    public function __construct(RequestMatcher $requestMatcher, Authentication $authentication)
27
    {
28
        $this->requestMatcher = $requestMatcher;
29
        $this->authentication = $authentication;
30 4
    }
31
32 4
    /**
33 4
     * {@inheritdoc}
34 4
     */
35
    public function authenticate(RequestInterface $request)
36
    {
37
        if ($this->requestMatcher->matches($request)) {
38
            return $this->authentication->authenticate($request);
39 2
        }
40
41 2
        return $request;
42 1
    }
43
}
44