Completed
Push — master ( 7db90d...b62044 )
by
unknown
05:58
created

CRUDController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 40 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 55.56%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 6
dl 20
loc 50
ccs 10
cts 18
cp 0.5556
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createAction() 0 16 3
A downloadAction() 8 8 1
A imageAction() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace MediaMonks\SonataMediaBundle\Controller;
4
5
use MediaMonks\SonataMediaBundle\ParameterBag\DownloadParameterBag;
6
use MediaMonks\SonataMediaBundle\ParameterBag\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 3
    public function createAction()
18
    {
19 3
        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 1
            );
29
        }
30
31 2
        return parent::createAction();
32
    }
33
34
    /**
35
     * @param Request $request
36
     * @param $id
37
     * @return StreamedResponse
38
     */
39 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...
40
    {
41
        $object = $this->admin->getObject($id);
42
43
        $this->admin->checkAccess('show', $object);
44
45
        return $this->get('mediamonks.sonata_media.utility.download')->getStreamedResponse($object, new DownloadParameterBag($request->query->all()));
46
    }
47
48
    /**
49
     * @param Request $request
50
     * @param int $id
51
     * @return RedirectResponse
52
     */
53 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...
54
    {
55
        $object = $this->admin->getObject($id);
56
57
        $this->admin->checkAccess('show', $object);
58
59
        return $this->get('mediamonks.sonata_media.utility.image')->getRedirectResponse($object, new ImageParameterBag($width, $height, $request->query->all()));
60
    }
61
}
62