Completed
Push — master ( 660487...67b4aa )
by
unknown
06:25
created

MediaAdminController::getMediaById()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace MediaMonks\SonataMediaBundle\Controller;
4
5
use MediaMonks\SonataMediaBundle\Model\MediaInterface;
6
use Sonata\AdminBundle\Controller\CRUDController;
7
use Symfony\Component\HttpFoundation\RedirectResponse;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\StreamedResponse;
10
11
class MediaAdminController extends CRUDController
12
{
13
    /**
14
     * @return \Symfony\Component\HttpFoundation\Response
15
     */
16
    public function createAction()
17
    {
18
        if (!$this->getRequest()->get('provider') && $this->getRequest()->isMethod('get')) {
19
            return $this->render(
20
                '@MediaMonksSonataMedia/MediaAdmin/select_provider.html.twig',
21
                [
22
                    'providers' => $this->get('mediamonks.sonata_media.provider.pool')->getProviders(),
23
                    'base_template' => $this->getBaseTemplate(),
24
                    'admin' => $this->admin,
25
                    'action' => 'create',
26
                ]
27
            );
28
        }
29
30
        return parent::createAction();
31
    }
32
33
    /**
34
     * @param Request $request
35
     * @param $id
36
     * @return StreamedResponse
37
     */
38 View Code Duplication
    public function downloadAction(Request $request, $id)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        $object = $this->admin->getObject($id);
41
42
        $this->admin->checkAccess('show', $object);
43
44
        return $this->get('mediamonks.sonata_media.utility.download')->getStreamedResponse($object);
45
    }
46
47
    /**
48
     * @param Request $request
49
     * @param int $id
50
     * @return RedirectResponse
51
     */
52 View Code Duplication
    public function imageAction(Request $request, $id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        $object = $this->admin->getObject($id);
55
56
        $this->admin->checkAccess('show', $object);
57
58
        return $this->get('mediamonks.sonata_media.utility.image')->getRedirectResponse($object, $request);
59
    }
60
}
61