Passed
Push — master ( cc5012...08c5ef )
by Andrea
20:25 queued 48s
created

MenuApplicazioneController::deleteAction()   B

Complexity

Conditions 3
Paths 9

Size

Total Lines 32
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 0
cts 22
cp 0
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 22
nc 9
nop 1
crap 12
1
<?php
2
3
namespace Fi\CoreBundle\Controller;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\HttpFoundation\Response;
7
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
8
9
/**
10
 * MenuApplicazione controller.
11
 */
12
class MenuApplicazioneController extends FiCoreController
13
{
14
15
    /**
16
     * Creates a new table entity.
17
     */
18
    public function createAction(Request $request)
19
    {
20
        $this->setup($request);
21
        $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...
22
        $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...
23
        $controller = $this->getController();
24
25
        if (!self::$canCreate) {
26
            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...
27
        }
28
29
        $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...
30
        $classbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Entity\\' . $controller;
31
        $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...
32
33
        $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...
34
        $formType = $formbundle . 'Type';
35
36
        $form = $this->createForm(
37
            $formType,
38
            $entity,
39
            array('attr' => array(
40
                'id' => 'formdati' . $controller,
41
                ),
42
                'action' => $this->generateUrl($controller . '_create'),
43
                )
44
        );
45
46
        $form->submit($request->request->get($form->getName()));
47
48
        if ($form->isValid()) {
49
            $em = $this->getDoctrine()->getManager();
50
            $em->persist($entity);
51
            $em->flush();
52
            $em->getConfiguration()->getResultCacheImpl()->delete("menu");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal menu 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...
53
54
            $continua = (int) $request->get('continua');
55
            if ($continua === 0) {
56
                return new Response('OK');
57
            } else {
58
                return $this->redirect($this->generateUrl($controller . '_edit', array('id' => $entity->getId())));
59
            }
60
        }
61
62
        return $this->render(
63
            $nomebundle . ':' . $controller . ':new.html.twig',
64
            array(
65
                    'nomecontroller' => $controller,
66
                    'entity' => $entity,
67
                    'form' => $form->createView(),
68
                        )
69
        );
70
    }
71
72
    /**
73
     * Edits an existing table entity.
74
     */
75
    public function updateAction(Request $request, $id)
76
    {
77
        /* @var $em \Doctrine\ORM\EntityManager */
78
        $this->setup($request);
79
        $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...
80
        $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...
81
        $controller = $this->getController();
82
83
        if (!self::$canUpdate) {
84
            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...
85
        }
86
87
        $nomebundle = $namespace . $bundle . 'Bundle';
88
        $formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller;
89
        $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...
90
91
        $repoStorico = $this->container->get('Storicomodifiche_repository');
92
93
        $em = $this->getDoctrine()->getManager();
94
95
        $entity = $em->getRepository($nomebundle . ':' . $controller)->find($id);
96
97
        if (!$entity) {
98
            throw $this->createNotFoundException('Unable to find ' . $controller . ' entity.');
99
        }
100
101
        $deleteForm = $this->createDeleteForm($id);
102
103
        $editForm = $this->createForm(
104
            $formType,
105
            $entity,
106
            array('attr' => array(
107
                'id' => 'formdati' . $controller,
108
                ),
109
                'action' => $this->generateUrl($controller . '_update', array('id' => $entity->getId())),
110
                )
111
        );
112
113
        $editForm->submit($request->request->get($editForm->getName()));
114
115
        if ($editForm->isValid()) {
116
            $originalData = $em->getUnitOfWork()->getOriginalEntityData($entity);
117
118
            $em->persist($entity);
119
            $em->flush();
120
            $em->getConfiguration()->getResultCacheImpl()->delete("menu");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal menu 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...
121
122
            $newData = $em->getUnitOfWork()->getOriginalEntityData($entity);
123
            $changes = $repoStorico->isRecordChanged($nomebundle, $controller, $originalData, $newData);
124
125
            if ($changes) {
126
                $repoStorico->saveHistory($controller, $changes, $id, $this->getUser());
127
            }
128
129
            $continua = (int) $request->get('continua');
130
            if ($continua === 0) {
131
                return new Response('OK');
132
            } else {
133
                return $this->redirect($this->generateUrl($controller . '_edit', array('id' => $id)));
134
            }
135
        }
136
137
        return $this->render(
138
            $nomebundle . ':' . $controller . ':edit.html.twig',
139
            array(
140
                    'entity' => $entity,
141
                    'edit_form' => $editForm->createView(),
142
                    'delete_form' => $deleteForm->createView(),
143
                    'nomecontroller' => $controller,
144
                        )
145
        );
146
    }
147
148
    /**
149
     * Deletes a table entity.
150
     */
151
    public function deleteAction(Request $request)
152
    {
153
        /* @var $em \Doctrine\ORM\EntityManager */
154
        $this->setup($request);
155
        if (!self::$canDelete) {
156
            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...
157
        }
158
        $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...
159
        $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...
160
        $controller = $this->getController();
161
162
        $nomebundle = $namespace . $bundle . 'Bundle';
163
164
        try {
165
            $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...
166
            $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...
167
            $ids = explode(',', $request->get('id'));
168
            $qb->delete($nomebundle . ':' . $controller, 'u')
169
                    ->andWhere('u.id IN (:ids)')
170
                    ->setParameter('ids', $ids);
171
172
            $query = $qb->getQuery();
173
            $query->execute();
174
            $em->getConfiguration()->getResultCacheImpl()->delete("menu");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal menu 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...
175
        } catch (\Exception $e) {
176
            $response = new Response();
177
            $response->setStatusCode('200');
178
179
            return new Response('404');
180
        }
181
182
        return new Response('OK');
183
    }
184
}
185