Passed
Push — master ( 03e013...bd5966 )
by Anatoly
01:18 queued 14s
created

DeleteController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 24
c 1
b 0
f 0
ccs 7
cts 7
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 13 2
1
<?php declare(strict_types=1);
2
3
namespace App\Controller\Entry;
4
5
/**
6
 * Import classes
7
 */
8
use App\ContainerAwareTrait;
9
use App\Http\ResponseFactory;
10
use Psr\Http\Message\ResponseInterface;
11
use Psr\Http\Message\ServerRequestInterface;
12
use Psr\Http\Server\RequestHandlerInterface;
13
14
/**
15
 * @Route(
16
 *   name="api.entry.delete",
17
 *   path="/api/v1/entry/{id<\d+>}",
18
 *   methods={"DELETE"},
19
 * )
20
 *
21
 * @OpenApi\Operation(
22
 *   tags={"Entry"},
23
 *   summary="Delete an entry",
24
 *   responses={
25
 *     200: @OpenApi\ResponseReference(
26
 *       class="App\Http\ResponseFactory",
27
 *       method="emptyOk",
28
 *     ),
29
 *     "default": @OpenApi\ResponseReference(
30
 *       class="App\Http\ResponseFactory",
31
 *       method="error",
32
 *     ),
33
 *   },
34
 * )
35
 */
36
final class DeleteController implements RequestHandlerInterface
37
{
38
    use ContainerAwareTrait;
39
40
    /**
41
     * {@inheritDoc}
42
     *
43
     * @param ServerRequestInterface $request
44
     *
45
     * @return ResponseInterface
46
     */
47 2
    public function handle(ServerRequestInterface $request) : ResponseInterface
48
    {
49 2
        $id = (int) $request->getAttribute('id');
50
51 2
        $service = $this->container->get('service.entry');
52
53 2
        if (!$service->existsById($id)) {
54 1
            return (new ResponseFactory)->error('The requested entry was not found.', [], 404);
55
        }
56
57 1
        $service->deleteById($id, $request->getParsedBody());
58
59 1
        return (new ResponseFactory)->emptyOk(200);
60
    }
61
}
62