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

CreateController   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 18
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 7 1
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.create",
17
 *   path="/api/v1/entry",
18
 *   methods={"POST"},
19
 *   middlewares={
20
 *     "App\Middleware\RequestBodyValidationMiddleware",
21
 *   },
22
 * )
23
 *
24
 * @OpenApi\Operation(
25
 *   tags={"Entry"},
26
 *   summary="Create an entry",
27
 *   requestBody=@OpenApi\RequestBody(
28
 *     content={
29
 *       "application/json": @OpenApi\MediaType(
30
 *         schema=@OpenApi\Schema(
31
 *           type="object",
32
 *           required={"name"},
33
 *           properties={
34
 *             "name"=@OpenApi\SchemaReference(
35
 *               class="App\Entity\Entry",
36
 *               property="name",
37
 *             ),
38
 *           },
39
 *         ),
40
 *       ),
41
 *     },
42
 *   ),
43
 *   responses={
44
 *     201: @OpenApi\ResponseReference(
45
 *       class="App\Http\ResponseFactory",
46
 *       method="emptyOk",
47
 *     ),
48
 *     "default": @OpenApi\ResponseReference(
49
 *       class="App\Http\ResponseFactory",
50
 *       method="error",
51
 *     ),
52
 *   },
53
 * )
54
 */
55
final class CreateController implements RequestHandlerInterface
56
{
57
    use ContainerAwareTrait;
58
59
    /**
60
     * {@inheritDoc}
61
     *
62
     * @param ServerRequestInterface $request
63
     *
64
     * @return ResponseInterface
65
     */
66 1
    public function handle(ServerRequestInterface $request) : ResponseInterface
67
    {
68 1
        $service = $this->container->get('service.entry');
69
70 1
        $service->create($request->getParsedBody());
71
72 1
        return (new ResponseFactory)->emptyOk(201);
73
    }
74
}
75