HalEntity   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 13
c 1
b 0
f 0
dl 0
loc 29
ccs 10
cts 10
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 22 1
1
<?php
2
3
namespace Bone\Http\Middleware;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Psr\Http\Message\ServerRequestInterface;
7
use Psr\Http\Server\MiddlewareInterface;
8
use Psr\Http\Server\RequestHandlerInterface;
9
10
class HalEntity implements MiddlewareInterface
11
{
12
    /**
13
     * @param ServerRequestInterface $request
14
     * @param RequestHandlerInterface $handler
15
     * @return ResponseInterface
16
     */
17 1
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
18
    {
19 1
        $uri = $request->getUri();
20
21
        $hal = [
22
            '_links' => [
23
                'self' => [
24 1
                    'href' => $uri->getScheme() . '://' . $uri->getHost() . $uri->getPath(),
25
                ]
26
            ],
27
        ];
28
29 1
        $response = $handler->handle($request);
30
31 1
        $data = \json_decode($response->getBody()->getContents(), true);
32 1
        $data = \array_merge($hal, $data);
33
34 1
        $body = $response->getBody();
35 1
        $body->rewind();
36 1
        $body->write(\json_encode($data));
37
38 1
        return $response->withBody($body);
39
    }
40
}