Completed
Push — dev-master ( 3d2c20...b7e24f )
by Derek Stephen
08:18 queued 03:13
created

HalEntity   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 5
dl 0
loc 32
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 24 1
1
<?php
2
3
namespace Bone\Http\Middleware;
4
5
use League\Route\Dispatcher;
6
use Psr\Http\Message\ResponseInterface;
7
use Psr\Http\Message\ServerRequestInterface;
8
use Psr\Http\Server\MiddlewareInterface;
9
use Psr\Http\Server\RequestHandlerInterface;
10
11
class HalEntity implements MiddlewareInterface
12
{
13
    /**
14
     * @param ServerRequestInterface $request
15
     * @param RequestHandlerInterface $handler
16
     * @return ResponseInterface
17
     */
18
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
19
    {
20
        $id = (int) $request->getQueryParams()['id'];
0 ignored issues
show
Unused Code introduced by
$id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
21
        $uri = $request->getUri();
22
23
        $hal = [
24
            '_links' => [
25
                'self' => [
26
                    'href' => $uri->getScheme() . '://' . $uri->getHost() . $uri->getPath(),
27
                ]
28
            ],
29
        ];
30
31
        $response = $handler->handle($request);
32
33
        $data = json_decode($response->getBody()->getContents(), true);
34
        $data = array_merge($hal, $data);
35
36
        $body = $response->getBody();
37
        $body->rewind();
38
        $body->write(json_encode($data));
39
40
        return $response->withBody($body);
41
    }
42
}