Completed
Push — master ( d4a912...134347 )
by
unknown
04:55
created

CRUDController::downloadAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 1.0046

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 5
cts 6
cp 0.8333
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
crap 1.0046
1
<?php
2
3
namespace MediaMonks\SonataMediaBundle\Controller;
4
5
use MediaMonks\SonataMediaBundle\Handler\DownloadParameterBag;
6
use MediaMonks\SonataMediaBundle\Handler\ImageParameterBag;
7
use Sonata\AdminBundle\Controller\CRUDController as BaseCRUDController;
8
use Symfony\Component\HttpFoundation\RedirectResponse;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\StreamedResponse;
11
12
class CRUDController extends BaseCRUDController
13
{
14
    /**
15
     * @return \Symfony\Component\HttpFoundation\Response
16
     */
17 10
    public function createAction()
18
    {
19 10
        if (!$this->getRequest()->get('provider') && $this->getRequest()->isMethod('get')) {
20 1
            return $this->render(
21 1
                '@MediaMonksSonataMedia/CRUD/select_provider.html.twig',
22
                [
23 1
                    'providers' => $this->get('mediamonks.sonata_media.provider.pool')->getProviders(),
24 1
                    'base_template' => $this->getBaseTemplate(),
25 1
                    'admin' => $this->admin,
26 1
                    'action' => 'create',
27
                ]
28
            );
29
        }
30
31 9
        return parent::createAction();
32
    }
33
34
    /**
35
     * @param Request $request
36
     * @param $id
37
     * @return StreamedResponse
38
     */
39 1 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...
40
    {
41 1
        $object = $this->admin->getObject($id);
42
43 1
        $this->admin->checkAccess('show', $object);
44
45 1
        return $this->get('mediamonks.sonata_media.utility.download')->getStreamedResponse(
46
            $object,
47 1
            new DownloadParameterBag($request->query->all())
48
        );
49
    }
50
51
    /**
52
     * @param Request $request
53
     * @param int $id
54
     * @return RedirectResponse
55
     */
56 3 View Code Duplication
    public function imageAction(Request $request, $id, $width, $height)
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...
57
    {
58 3
        $object = $this->admin->getObject($id);
59
60 3
        $this->admin->checkAccess('show', $object);
61
62 3
        return $this->get('mediamonks.sonata_media.utility.image')->getRedirectResponse(
63
            $object,
64 3
            new ImageParameterBag($width, $height, $request->query->all())
65
        );
66
    }
67
}
68