Passed
Push — master ( 451010...cd9467 )
by
unknown
07:02 queued 12s
created

MenuapplicazioneController::index()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 73
Code Lines 58

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 62
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 58
nc 3
nop 2
dl 0
loc 73
ccs 62
cts 63
cp 0.9841
crap 3
rs 8.9163
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Cdf\BiCoreBundle\Controller;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\HttpFoundation\Response;
7
use Symfony\Component\Asset\Packages;
8
use Cdf\BiCoreBundle\Utils\Entity\EntityUtils;
9
use Cdf\BiCoreBundle\Utils\Tabella\ParametriTabella;
10
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
11
12
/**
13
 * Menuapplicazione controller.
14
 */
15
class MenuapplicazioneController extends FiController
16
{
17
18
    /**
19
     * Lists all tables entities.
20
     */
21 1
    public function index(Request $request, Packages $assetsmanager): Response
22
    {
23 1
        $bundle = $this->getBundle();
24 1
        $controller = $this->getController();
25 1
        $idpassato = $request->get('id');
26
27 1
        if (!$this->getPermessi()->canRead($this->getController())) {
28
            throw new AccessDeniedException('Non si hanno i permessi per visualizzare questo contenuto');
29
        }
30 1
        $crudtemplate = $this->getCrudTemplate($bundle, $controller, $this->getThisFunctionName());
31
32 1
        $entityclassnotation = $this->getEntityClassName();
33 1
        $entityclass = $this->getEntityClassName();
34
35 1
        $formclass = str_replace('Entity', 'Form', $entityclass);
36
37 1
        $query = $this->em->createQueryBuilder()
38 1
                ->select('o')
39 1
                ->from('BiCoreBundle:Menuapplicazione', 'o')
40 1
                ->getQuery()
41 1
        ;
42 1
        $menuobj = $query->getResult();
43 1
        $menus = [];
44 1
        foreach ($menuobj as $menu) {
45 1
            $menus[$menu->getId()] = $menu->getNome();
46
        }
47
48 1
        $modellocolonne = array(
49 1
            array('nometabella' => $controller,
50 1
                'nomecampo' => "__bicorebundle_Menuapplicazione.id",
51 1
                'etichetta' => 'Id',
52 1
                'ordine' => 0,
53 1
                'larghezza' => 10,
54 1
                'escluso' => true),
55 1
            array('nometabella' => $controller, 'nomecampo' =>
56 1
                "__bicorebundle_Menuapplicazione.padre", 'etichetta' => 'Padre',
57 1
                'ordine' => 10, 'larghezza' => 10, 'escluso' => false,
58 1
                'decodifiche' => $menus,
59 1
            ),
60 1
        );
61
62 1
        $filtri = [];
63 1
        $prefiltri = [];
64 1
        $entityutils = new EntityUtils($this->em);
65 1
        $tablenamefromentity = $entityutils->getTableFromEntity($entityclass);
66 1
        $colonneordinamento = [$tablenamefromentity . '.id' => 'DESC'];
67 1
        $parametritabella = ['em' => ParametriTabella::setParameter('default'),
68 1
            'tablename' => ParametriTabella::setParameter($tablenamefromentity),
69 1
            'nomecontroller' => ParametriTabella::setParameter($controller),
70 1
            'bundle' => ParametriTabella::setParameter($bundle),
71 1
            'entityname' => ParametriTabella::setParameter($entityclassnotation),
72 1
            'entityclass' => ParametriTabella::setParameter($entityclass),
73 1
            'formclass' => ParametriTabella::setParameter($formclass),
74 1
            'modellocolonne' => ParametriTabella::setParameter(json_encode($modellocolonne)),
75 1
            'permessi' => ParametriTabella::setParameter(json_encode($this->getPermessi()->toJson($controller))),
76 1
            'urltabella' => ParametriTabella::setParameter($assetsmanager->getUrl('') . $controller . '/' . 'tabella'),
77 1
            'baseurl' => ParametriTabella::setParameter($assetsmanager->getUrl('')),
78 1
            'idpassato' => ParametriTabella::setParameter($idpassato),
79 1
            'titolotabella' => ParametriTabella::setParameter('Elenco ' . $controller),
80 1
            'multiselezione' => ParametriTabella::setParameter('0'),
81 1
            'editinline' => ParametriTabella::setParameter('0'),
82 1
            'paginacorrente' => ParametriTabella::setParameter('1'),
83 1
            'paginetotali' => ParametriTabella::setParameter(''),
84 1
            'righetotali' => ParametriTabella::setParameter('0'),
85 1
            'righeperpagina' => ParametriTabella::setParameter('15'),
86 1
            'estraituttirecords' => ParametriTabella::setParameter('0'),
87 1
            'colonneordinamento' => ParametriTabella::setParameter(json_encode($colonneordinamento)),
88 1
            'filtri' => ParametriTabella::setParameter(json_encode($filtri)),
89 1
            'prefiltri' => ParametriTabella::setParameter(json_encode($prefiltri)),
90 1
            'traduzionefiltri' => ParametriTabella::setParameter(''),
91 1
        ];
92
93 1
        return $this->render($crudtemplate, ['parametritabella' => $parametritabella]);
94
    }
95
}
96