Passed
Push — master ( d1b72a...68b5a8 )
by Anatoly
01:04 queued 11s
created

EntryReadController   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 17
c 1
b 0
f 0
ccs 0
cts 3
cp 0
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 5 1
1
<?php declare(strict_types=1);
2
3
namespace App\Bundle\Example\Controller;
4
5
/**
6
 * Import classes
7
 */
8
use App\ContainerAwareTrait;
9
use Arus\Http\Response\ResponseFactoryAwareTrait;
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_v1_entry_read",
17
 *   path="/api/v1/entry/{entryId<@uuid>}",
18
 *   methods={"GET"},
19
 *   summary="Reads an existing entry",
20
 *   tags={"entry"},
21
 * )
22
 *
23
 * @OpenApi\Operation(
24
 *   responses={
25
 *     200: @OpenApi\Response(
26
 *       description="OK",
27
 *       content={
28
 *         "application/json": @OpenApi\MediaType(
29
 *           schema=@OpenApi\Schema(
30
 *             type="object",
31
 *             properties={
32
 *               "data": @OpenApi\SchemaReference(
33
 *                 class="App\Bundle\Example\Service\EntrySerializer",
34
 *                 method="serialize",
35
 *               ),
36
 *             },
37
 *           ),
38
 *         ),
39
 *       },
40
 *     ),
41
 *   },
42
 * )
43
 */
44
final class EntryReadController implements RequestHandlerInterface
45
{
46
    use ContainerAwareTrait;
47
    use ResponseFactoryAwareTrait;
48
49
    /**
50
     * {@inheritDoc}
51
     *
52
     * @param ServerRequestInterface $request
53
     *
54
     * @return ResponseInterface
55
     */
56
    public function handle(ServerRequestInterface $request) : ResponseInterface
57
    {
58
        $entry = $this->container->get('entryManager')->findById($request->getAttribute('entryId'));
59
60
        return $this->ok($this->container->get('entrySerializer')->serialize($entry));
61
    }
62
}
63