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

PermessiController::index()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 74
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 55
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 44
nc 2
nop 2
dl 0
loc 74
ccs 55
cts 56
cp 0.9821
crap 2
rs 9.216
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 Cdf\BiCoreBundle\Utils\Entity\EntityUtils;
6
use Cdf\BiCoreBundle\Utils\Tabella\ParametriTabella;
7
use Symfony\Component\Asset\Packages;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
11
12
/**
13
 * Permessi controller.
14
 */
15
class PermessiController extends FiController
16
{
17
    /**
18
     * Lists all tables entities.
19
     */
20 1
    public function index(Request $request, Packages $assetsmanager): Response
21
    {
22 1
        $bundle = $this->getBundle();
23 1
        $controller = $this->getController();
24 1
        $idpassato = $request->get('id');
25
26 1
        if (!$this->getPermessi()->canRead($this->getController())) {
27
            throw new AccessDeniedException('Non si hanno i permessi per visualizzare questo contenuto');
28
        }
29 1
        $crudtemplate = $this->getCrudTemplate($bundle, $controller, $this->getThisFunctionName());
30
31 1
        $entityclassnotation = $this->getEntityClassName();
32 1
        $entityclass = $this->getEntityClassName();
33
34 1
        $formclass = str_replace('Entity', 'Form', $entityclass);
35
36 1
        $modellocolonne = [
37 1
            [
38 1
                'nomecampo' => '__bicorebundle_Permessi.modulo',
39 1
                'nometabella' => '__bicorebundle_Permessi',
40 1
                'etichetta' => 'Funzionalità',
41 1
            ],
42 1
            [
43 1
                'nomecampo' => '__bicorebundle_Permessi.__bicorebundle_Operatori.username',
44 1
                'escluso' => false,
45 1
            ], /*
46 1
                  $controller . ".operatori" => array(
47 1
                  "nometabella" => "__bicorebundle_Permessi",
48 1
                  "nomecampo" => "operatori",
49 1
                  "etichetta" => "Operatore",
50 1
                  ), */
51 1
        ];
52
53 1
        $colonneordinamento = ['__bicorebundle_Permessi.id' => 'DESC'];
54 1
        $filtri = [];
55
        /* $filtri = array(array("nomecampo" => "__bicorebundle_Permessi.ruoli.superadmin",
56
          "operatore" => "=",
57
          "valore" => true
58
          ));
59
        $filtri = array(
60
            array('nomecampo' => '__bicorebundle_Permessi.__bicorebundle_Operatori.__bicorebundle_Ruoli.user',
61
                'operatore' => '=',
62
                'valore' => true,
63
            ),
64
        );*/
65 1
        $prefiltri = [];
66 1
        $entityutils = new EntityUtils($this->em);
67 1
        $tablenamefromentity = $entityutils->getTableFromEntity($entityclass);
68 1
        $parametritabella = ['em' => ParametriTabella::setParameter('default'),
69 1
            'tablename' => ParametriTabella::setParameter($tablenamefromentity),
70 1
            'nomecontroller' => ParametriTabella::setParameter($controller),
71 1
            'bundle' => ParametriTabella::setParameter($bundle),
72 1
            'entityname' => ParametriTabella::setParameter($entityclassnotation),
73 1
            'entityclass' => ParametriTabella::setParameter($entityclass),
74 1
            'formclass' => ParametriTabella::setParameter($formclass),
75 1
            'modellocolonne' => ParametriTabella::setParameter(json_encode($modellocolonne)),
76 1
            'permessi' => ParametriTabella::setParameter(json_encode($this->getPermessi()->toJson($controller))),
77 1
            'urltabella' => ParametriTabella::setParameter($assetsmanager->getUrl('') . $controller . '/' . 'tabella'),
78 1
            'baseurl' => ParametriTabella::setParameter($assetsmanager->getUrl('')),
79 1
            'idpassato' => ParametriTabella::setParameter($idpassato),
80 1
            'titolotabella' => ParametriTabella::setParameter('Elenco ' . $controller),
81 1
            'multiselezione' => ParametriTabella::setParameter('1'),
82 1
            'editinline' => ParametriTabella::setParameter('0'),
83 1
            'paginacorrente' => ParametriTabella::setParameter('1'),
84 1
            'paginetotali' => ParametriTabella::setParameter(''),
85 1
            'righetotali' => ParametriTabella::setParameter('0'),
86 1
            'righeperpagina' => ParametriTabella::setParameter('15'),
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