Completed
Push — master ( f127c3...3ae385 )
by
unknown
06:02
created

CRUDController::createAction()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4.0058

Importance

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