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

EntryReadController::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
nc 1
nop 1
dl 0
loc 5
c 1
b 0
f 0
cc 1
ccs 0
cts 3
cp 0
crap 2
rs 10
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