Completed
Push — master ( 4b9800...3f5c16 )
by Beñat
01:44
created

GetFileController::byIdAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 2
1
<?php
2
3
/*
4
 * This file is part of the BenGorFile package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace BenGorFile\FileBundle\Controller\Api;
14
15
use BenGorFile\File\Application\Query\FileOfIdQuery;
16
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
17
use Symfony\Component\HttpFoundation\JsonResponse;
18
19
/**
20
 * @author Beñat Espiña <[email protected]>
21
 */
22
class GetFileController extends Controller
23
{
24
    public function byIdAction($id, $fileClass)
25
    {
26
        $file = $this->get('bengor_file.' . $fileClass . '.by_id_query')->__invoke(
27
            new FileOfIdQuery($id)
28
        );
29
30
        if (!$file) {
31
            return new JsonResponse([
32
                'error' => 'Does not exist any file with the given "%s" id',
33
            ], 404);
34
        }
35
36
        return new JsonResponse($file);
37
    }
38
}
39