Completed
Push — master ( 3e25b9...556647 )
by Márk
11s
created

RequestMatcherPlugin::handleRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 3
crap 2
1
<?php
2
3
namespace Http\Client\Common\Plugin;
4
5
use Http\Client\Common\Plugin;
6
use Http\Message\RequestMatcher;
7
use Psr\Http\Message\RequestInterface;
8
9
/**
10
 * Apply a delegated plugin based on a request match.
11
 *
12
 * @author Márk Sági-Kazár <[email protected]>
13
 */
14
final class RequestMatcherPlugin implements Plugin
15
{
16
    /**
17
     * @var RequestMatcher
18
     */
19
    private $requestMatcher;
20
21
    /**
22
     * @var Plugin
23
     */
24
    private $delegatedPlugin;
25
26
    /**
27
     * @param RequestMatcher $requestMatcher
28
     * @param Plugin         $delegatedPlugin
29
     */
30 4
    public function __construct(RequestMatcher $requestMatcher, Plugin $delegatedPlugin)
31
    {
32 4
        $this->requestMatcher = $requestMatcher;
33 4
        $this->delegatedPlugin = $delegatedPlugin;
34 4
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 2
    public function handleRequest(RequestInterface $request, callable $next, callable $first)
40
    {
41 2
        if ($this->requestMatcher->matches($request)) {
42 1
            return $this->delegatedPlugin->handleRequest($request, $next, $first);
43
        }
44
45 1
        return $next($request);
46
    }
47
}
48