Completed
Pull Request — master (#35)
by Márk
05:21
created

RequestMatch   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A authenticate() 0 8 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 RequestMatch implements Authentication
15
{
16
    /**
17
     * @var Authentication
18
     */
19
    private $authentication;
20
21
    /**
22
     * @var RequestMatcher
23
     */
24
    private $matcher;
25
26
    /**
27
     * @param Authentication $authentication
28
     * @param RequestMatcher $matcher
29
     */
30 4
    public function __construct(Authentication $authentication, RequestMatcher $matcher)
31
    {
32 4
        $this->authentication = $authentication;
33 4
        $this->matcher = $matcher;
34 4
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 2
    public function authenticate(RequestInterface $request)
40
    {
41 2
        if ($this->matcher->matches($request)) {
42 1
            return $this->authentication->authenticate($request);
43
        }
44
45 1
        return $request;
46
    }
47
}
48