CRUDController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 27.12 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 95.45%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 6
dl 16
loc 59
ccs 21
cts 22
cp 0.9545
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createAction() 0 25 4
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 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