Completed
Push — master ( 2ff726...1b8ace )
by Andrea
09:31
created

FfprincipaleController::indexAction()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 60
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 40
CRAP Score 4.0016

Importance

Changes 0
Metric Value
dl 0
loc 60
ccs 40
cts 42
cp 0.9524
rs 8.9618
c 0
b 0
f 0
cc 4
eloc 42
nc 8
nop 1
crap 4.0016

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 Fi\CoreBundle\Controller;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Fi\CoreBundle\DependencyInjection\GestionePermessi;
7
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
8
9
/**
10
 * Ffprincipale controller.
11
 */
12
class FfprincipaleController extends FiCoreController
13
{
14
15
    /**
16
     * Lists all tables entities.
17
     */
18
    /* @var $em \Doctrine\ORM\EntityManager */
19 1
    public function indexAction(Request $request)
20
    {
21 1
        $this->setup($request);
22 1
        $namespace = $this->getNamespace();
23 1
        $bundle = $this->getBundle();
24 1
        $controller = $this->getController();
25 1
        $container = $this->container;
26
27 1
        $gestionepermessi = $this->get("ficorebundle.gestionepermessi");
28 1
        $canRead = ($gestionepermessi->leggere(array('modulo' => $controller)) ? 1 : 0);
29
30 1
        $nomebundle = $namespace . $bundle . 'Bundle';
31
32 1
        $em = $container->get('doctrine')->getManager();
33 1
        $entities = $em->getRepository($nomebundle . ':' . $controller)->findAll();
34
35 1
        $paricevuti = array('nomebundle' => $nomebundle, 'nometabella' => $controller, 'container' => $container);
36
37 1
        $testatagriglia = Griglia::testataPerGriglia($paricevuti);
38
39 1
        $testatagriglia['multisearch'] = 1;
40 1
        $testatagriglia['showconfig'] = 1;
41 1
        $testatagriglia['showexcel'] = 1;
42 1
        $testatagriglia['showimportexcel'] = 1;
43 1
        $testatagriglia['larghezzagriglia'] = 700;
44 1
        $testatagriglia['overlayopen'] = 1;
45
46 1
        $testatagriglia['parametritesta'] = json_encode($paricevuti);
47
48 1
        $this->setParametriGriglia(array('request' => $request));
49
50 1
        $testatagriglia['parametrigriglia'] = json_encode(self::$parametrigriglia);
51
52
        /* @var $qb \Doctrine\ORM\QueryBuilder */
53 1
        $qb = $em->createQueryBuilder();
54 1
        $qb->select(array('a'));
55 1
        $qb->from('FiCoreBundle:OpzioniTabella', 'a');
56 1
        $qb->leftJoin('a.tabelle', 't');
57 1
        $qb->where('t.nometabella = :tabella');
58 1
        $qb->andWhere("t.nomecampo is null or t.nomecampo = ''");
59 1
        $qb->setParameter('tabella', $controller);
60 1
        $opzioni = $qb->getQuery()->getResult();
61 1
        foreach ($opzioni as $opzione) {
62
            $testatagriglia[$opzione->getParametro()] = $opzione->getValore();
63 1
        }
64
65 1
        $testata = json_encode($testatagriglia);
66
        $twigparms = array(
67 1
            'entities' => $entities,
68 1
            'nomecontroller' => $controller,
69 1
            'testata' => $testata,
70 1
            'canread' => $canRead,
71 1
        );
72
73 1
        if (!$canRead) {
74
            throw new AccessDeniedException("Non si hanno i permessi per visualizzare questo contenuto");
75
        } else {
76 1
            return $this->render($nomebundle . ':' . $controller . ':index.html.twig', $twigparms);
77
        }
78
    }
79
}
80