MediaQueryController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A view() 0 6 2
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damax\Media\Bridge\Symfony\Bundle\Controller\Api;
6
7
use Damax\Common\Bridge\Symfony\Bundle\Annotation\Serialize;
8
use Damax\Media\Application\Dto\MediaDto;
9
use Damax\Media\Application\Exception\MediaNotFound;
10
use Damax\Media\Application\Query\FetchMedia;
11
use League\Tactician\CommandBus as QueryBus;
12
use Nelmio\ApiDocBundle\Annotation\Model;
13
use Swagger\Annotations as OpenApi;
14
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
15
use Symfony\Component\Routing\Annotation\Route;
16
17
/**
18
 * @Route("/media")
19
 */
20
final class MediaQueryController
21
{
22
    private $queryBus;
23
24
    public function __construct(QueryBus $queryBus)
25
    {
26
        $this->queryBus = $queryBus;
27
    }
28
29
    /**
30
     * @OpenApi\Get(
31
     *     tags={"media"},
32
     *     summary="Get media.",
33
     *     security={
34
     *         {"Bearer"=""}
35
     *     },
36
     *     @OpenApi\Response(
37
     *         response=200,
38
     *         description="Media info.",
39
     *         @OpenApi\Schema(ref=@Model(type=MediaDto::class))
40
     *     ),
41
     *     @OpenApi\Response(
42
     *         response=404,
43
     *         description="Media not found."
44
     *     )
45
     * )
46
     *
47
     * @Route("/{id}", methods={"GET"}, name="media_view")
48
     * @Serialize()
49
     *
50
     * @throws NotFoundHttpException
51
     */
52
    public function view(string $id): MediaDto
53
    {
54
        try {
55
            return $this->queryBus->handle(new FetchMedia($id));
56
        } catch (MediaNotFound $e) {
57
            throw new NotFoundHttpException();
58
        }
59
    }
60
}
61