Completed
Push — master ( ed56e2...1e250a )
by Andrea
63:35
created

FiCrudController::setup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 11
ccs 8
cts 8
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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 15
    protected function setup(Request $request)
24
    {
25 15
        $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 15
        $controllo = new \ReflectionClass(get_class($this));
27
28 15
        preg_match('/(.*)\\\(.*)Bundle\\\Controller\\\(.*)Controller/', $controllo->name, $matches);
29
30 15
        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 15
        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 15
        self::$controller = $matches[3];
33 15
        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 15
36 15
    /**
37 15
     * Lists all tables entities.
38 15
     */
39 15
    public function indexAction(Request $request)
40
    {
41 15
        /* @var $em \Doctrine\ORM\EntityManager */
42 1
        $this->setup($request);
43
        $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...
44 14
        $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...
45
        $controller = $this->getController();
46
47
        if (!self::$canRead) {
48
            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...
49 4
        }
50
51
        $container = $this->container;
52 4
53 4
        $idpassato = $request->get('id');
54 4
55 4
        $nomebundle = $namespace . $bundle . 'Bundle';
56
57 4
        $repotabelle = $this->get('OpzioniTabella_repository');
58
59
        $paricevuti = array('nomebundle' => $nomebundle, 'nometabella' => $controller, 'container' => $container);
60
61 4
        $testatagriglia = Griglia::testataPerGriglia($paricevuti);
62
63 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...
64
        $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...
65 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...
66
        $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...
67 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...
68
        $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...
69 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...
70
        $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...
71 4
72
        $testatagriglia['parametritesta'] = json_encode($paricevuti);
73 4
74 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

74
        $this->/** @scrutinizer ignore-call */ 
75
               setParametriGriglia(array('request' => $request));
Loading history...
75 4
        $testatagriglia['parametrigriglia'] = json_encode(self::$parametrigriglia);
76 4
77 4
        $testata = $repotabelle->editTestataFormTabelle($testatagriglia, $controller, $container);
78 4
        return $this->render(
79 4
            $nomebundle . ':' . $controller . ':index.html.twig',
80 4
            array(
81
                    'nomecontroller' => $controller,
82 4
                    'testata' => $testata,
83
                    'canread' => self::$canRead,
84 4
                    'idpassato' => $idpassato,
85 4
                        )
86
        );
87 4
    }
88 4
89 4
    /**
90
     * Creates a new table entity.
91 4
     */
92 4
    public function createAction(Request $request)
93 4
    {
94 4
        $this->setup($request);
95
        $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...
96
        $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...
97
        $controller = $this->getController();
98
99
        if (!self::$canCreate) {
100
            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...
101
        }
102 2
103
        $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...
104 2
        $classbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Entity\\' . $controller;
105 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...
106 2
107 2
        $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...
108
        $formType = $formbundle . 'Type';
109 2
110
        $form = $this->createForm(
111
            $formType,
112
            $entity,
113 2
            array('attr' => array(
114 2
                'id' => 'formdati' . $controller,
115 2
                ),
116
                'action' => $this->generateUrl($controller . '_create'),
117 2
                )
118 2
        );
119
120 2
        $form->submit($request->request->get($form->getName()));
121 2
122 2
        if ($form->isValid()) {
123
            $em = $this->getDoctrine()->getManager();
124 2
            $em->persist($entity);
125
            $em->flush();
126 2
127
            $continua = $request->get('continua');
128
            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...
129
                return new Response('OK');
130 2
            } else {
131
                return $this->redirect($this->generateUrl($controller . '_edit', array('id' => $entity->getId())));
132 2
            }
133 2
        }
134 2
135 2
        return $this->render(
136
            $nomebundle . ':' . $controller . ':new.html.twig',
137 2
            array(
138 2
                    'nomecontroller' => $controller,
139 2
                    'entity' => $entity,
140
                    'form' => $form->createView(),
141
                        )
142
        );
143
    }
144
145
    /**
146
     * Displays a form to create a new table entity.
147
     */
148
    public function newAction(Request $request)
149
    {
150
        $this->setup($request);
151
        $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...
152
        $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...
153
        $controller = $this->getController();
154
155
        if (!self::$canCreate) {
156
            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...
157
        }
158 2
159
        $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...
160 2
        $classbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Entity\\' . $controller;
161 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...
162 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...
163 2
164
        $entity = new $classbundle();
165 2
166
        $form = $this->createForm(
167
            $formType,
168
            $entity,
169 2
            array('attr' => array(
170 2
                'id' => 'formdati' . $controller,
171 2
                ),
172 2
                'action' => $this->generateUrl($controller . '_create'),
173
                )
174 2
        );
175
176 2
        return $this->render(
177 2
            $nomebundle . ':' . $controller . ':new.html.twig',
178 2
            array(
179
                    'nomecontroller' => $controller,
180 2
                    'entity' => $entity,
181
                    'form' => $form->createView(),
182 2
                        )
183
        );
184
    }
185
186 2
    /**
187 2
     * Displays a form to edit an existing table entity.
188
     */
189 2
    public function editAction(Request $request, $id)
190 2
    {
191 2
        /* @var $em \Doctrine\ORM\EntityManager */
192
        $this->setup($request);
193
        $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...
194
        $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...
195
        $controller = $this->getController();
196
197
        if (!self::$canUpdate) {
198
            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...
199 2
        }
200
201
        $nomebundle = $namespace . $bundle . 'Bundle';
202 2
        $formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller;
203 2
        $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...
204 2
205 2
        $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

205
        /** @scrutinizer ignore-call */ 
206
        $elencomodifiche = $this->elencoModifiche($controller, $id);
Loading history...
206
207 2
        $em = $this->getDoctrine()->getManager();
208
209
        $entity = $em->getRepository($nomebundle . ':' . $controller)->find($id);
210
211 2
        if (!$entity) {
212 2
            throw $this->createNotFoundException('Unable to find ' . $controller . ' entity.');
213 2
        }
214
215 2
        $editForm = $this->createForm(
216
            $formType,
217 2
            $entity,
218
            array('attr' => array(
219 2
                'id' => 'formdati' . $controller,
220
                ),
221 2
                'action' => $this->generateUrl($controller . '_update', array('id' => $entity->getId())),
222
                )
223
        );
224
225 2
        $deleteForm = $this->createDeleteForm($id);
226 2
227 2
        return $this->render(
228
            $nomebundle . ':' . $controller . ':edit.html.twig',
229 2
            array(
230
                    'entity' => $entity,
231 2
                    'nomecontroller' => $controller,
232
                    'edit_form' => $editForm->createView(),
233
                    'delete_form' => $deleteForm->createView(),
234
                    'elencomodifiche' => $elencomodifiche,
235 2
                        )
236
        );
237 2
    }
238 2
239
    /**
240 2
     * Edits an existing table entity.
241 2
     */
242 2
    public function updateAction(Request $request, $id)
243 2
    {
244 2
        /* @var $em \Doctrine\ORM\EntityManager */
245
        $this->setup($request);
246
        $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...
247
        $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...
248
        $controller = $this->getController();
249
250
        if (!self::$canUpdate) {
251
            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...
252 2
        }
253
254
        $nomebundle = $namespace . $bundle . 'Bundle';
255 2
        $formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller;
256 2
        $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...
257 2
258 2
        $repoStorico = $this->container->get('Storicomodifiche_repository');
259
260 2
        $em = $this->getDoctrine()->getManager();
261
262
        $entity = $em->getRepository($nomebundle . ':' . $controller)->find($id);
263
264 2
        if (!$entity) {
265 2
            throw $this->createNotFoundException('Unable to find ' . $controller . ' entity.');
266 2
        }
267
268 2
        $deleteForm = $this->createDeleteForm($id);
269
270 2
        $editForm = $this->createForm(
271
            $formType,
272 2
            $entity,
273
            array('attr' => array(
274 2
                'id' => 'formdati' . $controller,
275
                ),
276
                'action' => $this->generateUrl($controller . '_update', array('id' => $entity->getId())),
277
                )
278 2
        );
279
280 2
        $editForm->submit($request->request->get($editForm->getName()));
281 2
282 2
        if ($editForm->isValid()) {
283
            $originalData = $em->getUnitOfWork()->getOriginalEntityData($entity);
284 2
285
            $em->persist($entity);
286 2
            $em->flush();
287
288
            $newData = $em->getUnitOfWork()->getOriginalEntityData($entity);
289
            $changes = $repoStorico->isRecordChanged($nomebundle, $controller, $originalData, $newData);
290 2
291
            if ($changes) {
292 2
                $repoStorico->saveHistory($controller, $changes, $id, $this->getUser());
293 2
            }
294
295 2
            $continua = $request->get('continua');
296 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...
297
                return new Response('OK');
298 2
            } else {
299 2
                return $this->redirect($this->generateUrl($controller . '_edit', array('id' => $id)));
300
            }
301 2
        }
302 1
303
        return $this->render(
304
            $nomebundle . ':' . $controller . ':edit.html.twig',
305 2
            array(
306 2
                    'entity' => $entity,
307 2
                    'edit_form' => $editForm->createView(),
308
                    'delete_form' => $deleteForm->createView(),
309
                    'nomecontroller' => $controller,
310
                        )
311
        );
312
    }
313
314
    /**
315
     * Edits an existing table entity.
316
     */
317
    public function aggiornaAction(Request $request)
318
    {
319
        /* @var $em \Doctrine\ORM\EntityManager */
320
        $this->setup($request);
321
        $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...
322
        $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...
323
        $controller = $this->getController();
324
325
        if (!self::$canUpdate) {
326
            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...
327
        }
328
329
        $nomebundle = $namespace . $bundle . 'Bundle';
330
331
        $id = $this->get('request')->request->get('id');
332
333
        $em = $this->getDoctrine()->getManager();
334
335
        $entity = $em->getRepository($nomebundle . ':' . $controller)->find($id);
336
337
        if (!$entity) {
338
            throw $this->createNotFoundException('Unable to find ' . $controller . ' entity.');
339
        }
340
341
        throw $this->createNotFoundException("Implementare a seconda dell'esigenza 'aggiornaAction' del controller "
342
                . $nomebundle
343
                . '/'
344
                . $controller);
345
    }
346
347
    /**
348
     * Deletes a table entity.
349
     */
350
    public function deleteAction(Request $request)
351
    {
352
        /* @var $em \Doctrine\ORM\EntityManager */
353
        $this->setup($request);
354
        $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...
355
        $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...
356
        $controller = $this->getController();
357
358
        $nomebundle = $namespace . $bundle . 'Bundle';
359
360 2
        try {
361
            $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...
362
            $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...
363 2
            $ids = explode(',', $request->get('id'));
364 2
            $qb->delete($nomebundle . ':' . $controller, 'u')
365 2
                    ->andWhere('u.id IN (:ids)')
366 2
                    ->setParameter('ids', $ids);
367
368 2
            $query = $qb->getQuery();
369
            $query->execute();
370
        } catch (\Exception $e) {
371 2
            $response = new Response();
372 2
            $response->setStatusCode('200');
373 2
374 2
            return new Response('404');
375 2
        }
376 2
377
        return new Response('OK');
378 2
    }
379 2
380
    /**
381
     * Creates a form to delete a table entity by id.
382
     *
383
     * @param mixed $id The entity id
384
     *
385
     * @return \Symfony\Component\Form\Form The form
386
     */
387 2
    protected function createDeleteForm($id)
388
    {
389
        return $this->createFormBuilder(array('id' => $id))
390
                        ->add('id', get_class(new \Symfony\Component\Form\Extension\Core\Type\HiddenType()))
391
                        ->getForm();
392
    }
393
394
    protected function getNamespace()
395
    {
396
        return self::$namespace;
397
    }
398
399
    protected function getBundle()
400
    {
401
        return self::$bundle;
402
    }
403
404 14
    protected function getController()
405
    {
406 14
        return self::$controller;
407
    }
408
409 14
    protected function getAction()
410
    {
411 14
        return self::$action;
412
    }
413
}
414