Completed
Pull Request — master (#7)
by Franz
04:42
created

PathPrefixingHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 11 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Northwoods\Broker;
5
6
use Psr\Http\Message\ResponseInterface;
7
use Psr\Http\Message\ServerRequestInterface;
8
use Psr\Http\Server\RequestHandlerInterface;
9
10
class PathPrefixingHandler implements RequestHandlerInterface
11
{
12
    /** @var RequestHandlerInterface */
13
    private $wrapped;
14
15
    /** @var string */
16
    private $prefix;
17
18 4
    public function __construct(RequestHandlerInterface $wrapped, $prefix)
19
    {
20 4
        $this->wrapped = $wrapped;
21 4
        $this->prefix = $prefix;
22 4
    }
23
24
    /**
25
     * Handle the request and return a response.
26
     */
27 1
    public function handle(ServerRequestInterface $request): ResponseInterface
28
    {
29 1
        $uri = $request->getUri();
30 1
        return $this->wrapped->handle(
31 1
            $request->withUri(
32 1
                $uri->withPath(
33 1
                    $this->prefix . $uri->getPath()
34
                )
35
            )
36
        );
37
    }
38
}
39