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

RequestMatch::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
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