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

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