Passed
Push — master ( 632266...23e296 )
by Andrea
16:19
created

FiCrudController   A

Complexity

Total Complexity 33

Size/Duplication

Total Lines 411
Duplicated Lines 0 %

Test Coverage

Coverage 88.65%

Importance

Changes 0
Metric Value
wmc 33
dl 0
loc 411
ccs 203
cts 229
cp 0.8865
rs 9.3999
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
B newAction() 0 34 2
B setup() 0 17 5
B aggiornaAction() 0 28 3
A getBundle() 0 3 1
A getController() 0 3 1
A getNamespace() 0 3 1
A getAction() 0 3 1
B updateAction() 0 68 6
B editAction() 0 46 3
B indexAction() 0 46 2
A createDeleteForm() 0 5 1
B deleteAction() 0 31 3
B createAction() 0 49 4
1
<?php
2
3
namespace Fi\CoreBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
9
10
class FiCrudController extends Controller
11
{
12
13
    public static $namespace;
14
    public static $bundle;
15
    public static $controller;
16
    public static $action;
17
    public static $parametrigriglia;
18
    public static $canRead;
19
    public static $canDelete;
20
    public static $canCreate;
21
    public static $canUpdate;
22
23 30
    protected function setup(Request $request)
24
    {
25 30
        $matches = array();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
26 30
        $controllo = new \ReflectionClass(get_class($this));
27
28 30
        preg_match('/(.*)\\\(.*)Bundle\\\Controller\\\(.*)Controller/', $controllo->name, $matches);
29
30 30
        self::$namespace = $matches[1];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
31 30
        self::$bundle = $matches[2];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
32 30
        self::$controller = $matches[3];
33 30
        self::$action = substr($request->attributes->get('_controller'), strrpos($request->attributes->get('_controller'), ':') + 1);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
34
        
35 30
        $gestionepermessi = $this->get('ficorebundle.gestionepermessi');
36 30
        self::$canRead = ($gestionepermessi->leggere(array('modulo' => self::$controller)) ? 1 : 0);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
37 30
        self::$canDelete = ($gestionepermessi->cancellare(array('modulo' => self::$controller)) ? 1 : 0);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
38 30
        self::$canCreate = ($gestionepermessi->creare(array('modulo' => self::$controller)) ? 1 : 0);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
39 30
        self::$canUpdate = ($gestionepermessi->aggiornare(array('modulo' => self::$controller)) ? 1 : 0);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
40 30
    }
41
42
    /**
43
     * Lists all tables entities.
44
     */
45 19
    public function indexAction(Request $request)
46
    {
47
        /* @var $em \Doctrine\ORM\EntityManager */
48 19
        $this->setup($request);
49 19
        $namespace = $this->getNamespace();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
50 19
        $bundle = $this->getBundle();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
51 19
        $controller = $this->getController();
52
53 19
        if (!self::$canRead) {
54 15
            throw new AccessDeniedException("Non si hanno i permessi per visualizzare questo contenuto");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Non si hanno i permessi ...izzare questo contenuto does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
55
        }
56
57 4
        $container = $this->container;
58
59 4
        $idpassato = $request->get('id');
60
61 4
        $nomebundle = $namespace . $bundle . 'Bundle';
62
63 4
        $repotabelle = $this->get('OpzioniTabella_repository');
64
65 4
        $paricevuti = array('nomebundle' => $nomebundle, 'nometabella' => $controller, 'container' => $container);
66
67 4
        $testatagriglia = Griglia::testataPerGriglia($paricevuti);
68
69 4
        $testatagriglia['multisearch'] = 1;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 19 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
70 4
        $testatagriglia['showconfig'] = 1;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 20 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
71 4
        $testatagriglia['overlayopen'] = 1;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 19 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
72 4
        $testatagriglia['showadd'] = self::$canCreate;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 23 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
73 4
        $testatagriglia['showedit'] = self::$canUpdate;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 22 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
74 4
        $testatagriglia['showdel'] = self::$canDelete;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 23 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
75 4
        $testatagriglia["filterToolbar_searchOnEnter"] = true;
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal filterToolbar_searchOnEnter does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
76 4
        $testatagriglia["filterToolbar_searchOperators"] = true;
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal filterToolbar_searchOperators does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
77
78 4
        $testatagriglia['parametritesta'] = json_encode($paricevuti);
79
80 4
        $this->setParametriGriglia(array('request' => $request));
0 ignored issues
show
introduced by
The method setParametriGriglia() does not exist on Fi\CoreBundle\Controller\FiCrudController. Maybe you want to declare this class abstract? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

80
        $this->/** @scrutinizer ignore-call */ 
81
               setParametriGriglia(array('request' => $request));
Loading history...
81 4
        $testatagriglia['parametrigriglia'] = json_encode(self::$parametrigriglia);
82
83 4
        $testata = $repotabelle->editTestataFormTabelle($testatagriglia, $controller, $container);
84 4
        return $this->render(
85 4
            $nomebundle . ':' . $controller . ':index.html.twig',
86
            array(
87 4
                    'nomecontroller' => $controller,
88 4
                    'testata' => $testata,
89 4
                    'canread' => self::$canRead,
90 4
                    'idpassato' => $idpassato,
91
                        )
92 4
        );
93
    }
94
95
    /**
96
     * Creates a new table entity.
97
     */
98 17
    public function createAction(Request $request)
99
    {
100 17
        $this->setup($request);
101 17
        $namespace = $this->getNamespace();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
102 17
        $bundle = $this->getBundle();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
103 17
        $controller = $this->getController();
104
105 17
        if (!self::$canCreate) {
106 15
            throw new AccessDeniedException("Non si hanno i permessi per creare questo contenuto");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Non si hanno i permessi ...creare questo contenuto does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
107
        }
108
109 6
        $nomebundle = $namespace . $bundle . 'Bundle';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
110 6
        $classbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Entity\\' . $controller;
111 6
        $formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
112
113 6
        $entity = new $classbundle();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
114 6
        $formType = $formbundle . 'Type';
115
116 6
        $form = $this->createForm(
117 6
            $formType,
118 6
            $entity,
119
            array('attr' => array(
120 6
                'id' => 'formdati' . $controller,
121 6
                ),
122 6
                'action' => $this->generateUrl($controller . '_create'),
123
                )
124 6
        );
125
126 6
        $form->submit($request->request->get($form->getName()));
127
128 6
        if ($form->isValid()) {
129 2
            $em = $this->getDoctrine()->getManager();
130 2
            $em->persist($entity);
131 2
            $em->flush();
132
133 2
            $continua = $request->get('continua');
134 2
            if ($continua == 0) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $continua of type null|mixed to 0; this is ambiguous as not only 0 == 0 is true, but null == 0 is true, too. Consider using a strict comparison ===.
Loading history...
135 2
                return new Response('OK');
136
            } else {
137
                return $this->redirect($this->generateUrl($controller . '_edit', array('id' => $entity->getId())));
138
            }
139
        }
140
141 4
        return $this->render(
142 4
            $nomebundle . ':' . $controller . ':new.html.twig',
143
            array(
144 4
                    'nomecontroller' => $controller,
145 4
                    'entity' => $entity,
146 4
                    'form' => $form->createView(),
147
                        )
148 4
        );
149
    }
150
151
    /**
152
     * Displays a form to create a new table entity.
153
     */
154 2
    public function newAction(Request $request)
155
    {
156 2
        $this->setup($request);
157 2
        $namespace = $this->getNamespace();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
158 2
        $bundle = $this->getBundle();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
159 2
        $controller = $this->getController();
160
161 2
        if (!self::$canCreate) {
162
            throw new AccessDeniedException("Non si hanno i permessi per creare questo contenuto");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Non si hanno i permessi ...creare questo contenuto does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
163
        }
164
165 2
        $nomebundle = $namespace . $bundle . 'Bundle';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
166 2
        $classbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Entity\\' . $controller;
167 2
        $formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
168 2
        $formType = $formbundle . 'Type';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
169
170 2
        $entity = new $classbundle();
171
172 2
        $form = $this->createForm(
173 2
            $formType,
174 2
            $entity,
175
            array('attr' => array(
176 2
                'id' => 'formdati' . $controller,
177 2
                ),
178 2
                'action' => $this->generateUrl($controller . '_create'),
179
                )
180 2
        );
181
182 2
        return $this->render(
183 2
            $nomebundle . ':' . $controller . ':new.html.twig',
184
            array(
185 2
                    'nomecontroller' => $controller,
186 2
                    'entity' => $entity,
187 2
                    'form' => $form->createView(),
188
                        )
189 2
        );
190
    }
191
192
    /**
193
     * Displays a form to edit an existing table entity.
194
     */
195 17
    public function editAction(Request $request, $id)
196
    {
197
        /* @var $em \Doctrine\ORM\EntityManager */
198 17
        $this->setup($request);
199 17
        $namespace = $this->getNamespace();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
200 17
        $bundle = $this->getBundle();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
201 17
        $controller = $this->getController();
202
203 17
        if (!self::$canUpdate) {
204 15
            throw new AccessDeniedException("Non si hanno i permessi per modificare questo contenuto");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Non si hanno i permessi ...ficare questo contenuto does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
205
        }
206
207 6
        $nomebundle = $namespace . $bundle . 'Bundle';
208 6
        $formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller;
209 6
        $formType = $formbundle . 'Type';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
210
211 6
        $elencomodifiche = $this->elencoModifiche($controller, $id);
0 ignored issues
show
introduced by
The method elencoModifiche() does not exist on Fi\CoreBundle\Controller\FiCrudController. Maybe you want to declare this class abstract? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

211
        /** @scrutinizer ignore-call */ 
212
        $elencomodifiche = $this->elencoModifiche($controller, $id);
Loading history...
212
213 6
        $em = $this->getDoctrine()->getManager();
214
215 6
        $entity = $em->getRepository($nomebundle . ':' . $controller)->find($id);
216
217 6
        if (!$entity) {
218
            throw $this->createNotFoundException('Unable to find ' . $controller . ' entity.');
219
        }
220
221 6
        $editForm = $this->createForm(
222 6
            $formType,
223 6
            $entity,
224
            array('attr' => array(
225 6
                'id' => 'formdati' . $controller,
226 6
                ),
227 6
                'action' => $this->generateUrl($controller . '_update', array('id' => $entity->getId())),
228
                )
229 6
        );
230
231 6
        $deleteForm = $this->createDeleteForm($id);
232
233 6
        return $this->render(
234 6
            $nomebundle . ':' . $controller . ':edit.html.twig',
235
            array(
236 6
                    'entity' => $entity,
237 6
                    'nomecontroller' => $controller,
238 6
                    'edit_form' => $editForm->createView(),
239 6
                    'delete_form' => $deleteForm->createView(),
240 6
                    'elencomodifiche' => $elencomodifiche,
241
                        )
242 6
        );
243
    }
244
245
    /**
246
     * Edits an existing table entity.
247
     */
248 17
    public function updateAction(Request $request, $id)
249
    {
250
        /* @var $em \Doctrine\ORM\EntityManager */
251 17
        $this->setup($request);
252 17
        $namespace = $this->getNamespace();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
253 17
        $bundle = $this->getBundle();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
254 17
        $controller = $this->getController();
255
256 17
        if (!self::$canUpdate) {
257 15
            throw new AccessDeniedException("Non si hanno i permessi per aggiornare questo contenuto");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Non si hanno i permessi ...ornare questo contenuto does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
258
        }
259
260 6
        $nomebundle = $namespace . $bundle . 'Bundle';
261 6
        $formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller;
262 6
        $formType = $formbundle . 'Type';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
263
264 6
        $repoStorico = $this->container->get('Storicomodifiche_repository');
265
266 6
        $em = $this->getDoctrine()->getManager();
267
268 6
        $entity = $em->getRepository($nomebundle . ':' . $controller)->find($id);
269
270 6
        if (!$entity) {
271
            throw $this->createNotFoundException('Unable to find ' . $controller . ' entity.');
272
        }
273
274 6
        $deleteForm = $this->createDeleteForm($id);
275
276 6
        $editForm = $this->createForm(
277 6
            $formType,
278 6
            $entity,
279
            array('attr' => array(
280 6
                'id' => 'formdati' . $controller,
281 6
                ),
282 6
                'action' => $this->generateUrl($controller . '_update', array('id' => $entity->getId())),
283
                )
284 6
        );
285
286 6
        $editForm->submit($request->request->get($editForm->getName()));
287
288 6
        if ($editForm->isValid()) {
289 2
            $originalData = $em->getUnitOfWork()->getOriginalEntityData($entity);
290
291 2
            $em->persist($entity);
292 2
            $em->flush();
293
294 2
            $newData = $em->getUnitOfWork()->getOriginalEntityData($entity);
295 2
            $changes = $repoStorico->isRecordChanged($nomebundle, $controller, $originalData, $newData);
296
297 2
            if ($changes) {
298 1
                $repoStorico->saveHistory($controller, $changes, $id, $this->getUser());
299 1
            }
300
301 2
            $continua = $request->get('continua');
302 2
            if ($continua == 0) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $continua of type null|mixed to 0; this is ambiguous as not only 0 == 0 is true, but null == 0 is true, too. Consider using a strict comparison ===.
Loading history...
303 2
                return new Response('OK');
304
            } else {
305
                return $this->redirect($this->generateUrl($controller . '_edit', array('id' => $id)));
306
            }
307
        }
308
309 4
        return $this->render(
310 4
            $nomebundle . ':' . $controller . ':edit.html.twig',
311
            array(
312 4
                    'entity' => $entity,
313 4
                    'edit_form' => $editForm->createView(),
314 4
                    'delete_form' => $deleteForm->createView(),
315 4
                    'nomecontroller' => $controller,
316
                        )
317 4
        );
318
    }
319
320
    /**
321
     * Edits an existing table entity.
322
     */
323
    public function aggiornaAction(Request $request)
324
    {
325
        /* @var $em \Doctrine\ORM\EntityManager */
326
        $this->setup($request);
327
        $namespace = $this->getNamespace();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
328
        $bundle = $this->getBundle();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
329
        $controller = $this->getController();
330
331
        if (!self::$canUpdate) {
332
            throw new AccessDeniedException("Non si hanno i permessi per aggiornare questo contenuto");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Non si hanno i permessi ...ornare questo contenuto does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
333
        }
334
335
        $nomebundle = $namespace . $bundle . 'Bundle';
336
337
        $id = $this->get('request')->request->get('id');
338
339
        $em = $this->getDoctrine()->getManager();
340
341
        $entity = $em->getRepository($nomebundle . ':' . $controller)->find($id);
342
343
        if (!$entity) {
344
            throw $this->createNotFoundException('Unable to find ' . $controller . ' entity.');
345
        }
346
347
        throw $this->createNotFoundException("Implementare a seconda dell'esigenza 'aggiornaAction' del controller "
348
                . $nomebundle
349
                . '/'
350
                . $controller);
351
    }
352
353
    /**
354
     * Deletes a table entity.
355
     */
356 17
    public function deleteAction(Request $request)
357
    {
358
        /* @var $em \Doctrine\ORM\EntityManager */
359 17
        $this->setup($request);
360 17
        if (!self::$canDelete) {
361 15
            throw new AccessDeniedException("Non si hanno i permessi per aggiornare questo contenuto");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Non si hanno i permessi ...ornare questo contenuto does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
362
        }
363 6
        $namespace = $this->getNamespace();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
364 6
        $bundle = $this->getBundle();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
365 6
        $controller = $this->getController();
366
367 6
        $nomebundle = $namespace . $bundle . 'Bundle';
368
369
        try {
370 6
            $em = $this->getDoctrine()->getManager();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
371 6
            $qb = $em->createQueryBuilder();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
372 6
            $ids = explode(',', $request->get('id'));
373 6
            $qb->delete($nomebundle . ':' . $controller, 'u')
374 6
                    ->andWhere('u.id IN (:ids)')
375 6
                    ->setParameter('ids', $ids);
376
377 6
            $query = $qb->getQuery();
378 6
            $query->execute();
379 6
        } catch (\Exception $e) {
380
            $response = new Response();
381
            $response->setStatusCode('200');
382
383
            return new Response('404');
384
        }
385
386 6
        return new Response('OK');
387
    }
388
389
    /**
390
     * Creates a form to delete a table entity by id.
391
     *
392
     * @param mixed $id The entity id
393
     *
394
     * @return \Symfony\Component\Form\Form The form
395
     */
396 4
    protected function createDeleteForm($id)
397
    {
398 4
        return $this->createFormBuilder(array('id' => $id))
399 4
                        ->add('id', get_class(new \Symfony\Component\Form\Extension\Core\Type\HiddenType()))
400 4
                        ->getForm();
401
    }
402
403 30
    protected function getNamespace()
404
    {
405 30
        return self::$namespace;
406
    }
407
408 30
    protected function getBundle()
409
    {
410 30
        return self::$bundle;
411
    }
412
413 30
    protected function getController()
414
    {
415 30
        return self::$controller;
416
    }
417
418
    protected function getAction()
419
    {
420
        return self::$action;
421
    }
422
}
423