RemoveController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 9
dl 0
loc 48
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 3
B defaultAction() 0 24 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Rest\ServerBundle\Controller\Resource;
5
6
use Innmind\Rest\Server\{
7
    Response\HeaderBuilder\RemoveBuilder,
8
    Gateway,
9
    Identity\Identity
10
};
11
use Innmind\Http\{
12
    Message\Response,
13
    Message\StatusCode\StatusCode,
14
    Message\ReasonPhrase\ReasonPhrase,
15
    Headers\Headers
16
};
17
use Innmind\Filesystem\Stream\StringStream;
18
use Innmind\Immutable\MapInterface;
19
use Symfony\Component\HttpFoundation\Request;
20
21
final class RemoveController
22
{
23
    private $gateways;
24
    private $buildHeader;
25
26 4
    public function __construct(
27
        MapInterface $gateways,
28
        RemoveBuilder $headerBuilder
29
    ) {
30
        if (
31 4
            (string) $gateways->keyType() !== 'string' ||
32 4
            (string) $gateways->valueType() !== Gateway::class
33
        ) {
34 2
            throw new \TypeError(sprintf(
35 2
                'Argument 1 must be of type MapInterface<string, %s>',
36 2
                Gateway::class
37
            ));
38
        }
39
40 2
        $this->gateways = $gateways;
41 2
        $this->buildHeader = $headerBuilder;
42 2
    }
43
44 2
    public function defaultAction(Request $request, $identity): Response
45
    {
46 2
        $definition = $request->attributes->get('_innmind_resource_definition');
47 2
        $request = $request->attributes->get('_innmind_request');
48
49
        $remover = $this
50 2
            ->gateways
51 2
            ->get((string) $definition->gateway())
52 2
            ->resourceRemover();
53 2
        $remover(
54 2
            $definition,
55 2
            $identity = new Identity($identity)
56
        );
57
58 2
        return new Response\Response(
59 2
            $code = new StatusCode(StatusCode::codes()->get('NO_CONTENT')),
60 2
            new ReasonPhrase(ReasonPhrase::defaults()->get($code->value())),
61 2
            $request->protocolVersion(),
62 2
            new Headers(
63 2
                ($this->buildHeader)($request, $definition, $identity)
64
            ),
65 2
            new StringStream('')
66
        );
67
    }
68
}
69