Passed
Push — master ( 2a39ec...3b6c56 )
by Andrea
03:42
created

GestionePermessi::cancellare()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
cc 4
nc 5
nop 1
crap 4
1
<?php
2
3
namespace Fi\CoreBundle\DependencyInjection;
4
5
use Symfony\Component\DependencyInjection\ContainerInterface as Container;
6
use Fi\CoreBundle\Utils\PermessiSingletonUtility;
7
8
/*
9
 * Se c'è l'accoppiata UTENTE + MODULO allora vale quel permesso
10
 * Se c'è l'accoppiata RUOLO + MODULO allora vale quel permesso
11
 * Altrimenti solo MODULO
12
 * Se non trovo informazioni di sorta, il modulo è chiuso
13
 */
14
15
class GestionePermessi
16
{
17
18
    protected $modulo;
19
    protected $crud;
20
    private $container;
21
22 36
    public function __construct(Container $container)
23
    {
24 36
        $this->container = $container;
25 36
    }
26
27 32
    private function presente($lettera)
28
    {
29 32
        if (stripos($this->crud, $lettera) !== false) {
30 26
            return true;
31
        } else {
32 17
            return false;
33
        }
34
    }
35
36 33
    public function leggere($parametri = array())
37
    {
38 33
        if (!$this->container->get('security.token_storage')->getToken()) {
39 1
            return null;
40
        }
41 32
        if (isset($parametri['modulo'])) {
42 32
            $this->modulo = $parametri['modulo'];
43
        }
44
45 32
        $this->setCrud();
46
47 32
        return $this->presente('R') || ($this->isSuperAdmin()); //SuperAdmin
48
    }
49
50 32
    public function cancellare($parametri = array())
51
    {
52 32
        if (!$this->container->get('security.token_storage')->getToken()) {
53 1
            return null;
54
        }
55 31
        if (isset($parametri['modulo'])) {
56 31
            $this->modulo = $parametri['modulo'];
57
        }
58 31
        $this->setCrud();
59
60 31
        return $this->presente('D') || ($this->isSuperAdmin()); //SuperAdmin
61
    }
62
63 32
    public function creare($parametri = array())
64
    {
65 32
        if (!$this->container->get('security.token_storage')->getToken()) {
66 1
            return null;
67
        }
68 31
        if (isset($parametri['modulo'])) {
69 31
            $this->modulo = $parametri['modulo'];
70
        }
71 31
        $this->setCrud();
72
73 31
        return $this->presente('C') || ($this->isSuperAdmin()); //SuperAdmin
74
    }
75
76 32
    public function aggiornare($parametri = array())
77
    {
78 32
        if (!$this->container->get('security.token_storage')->getToken()) {
79 1
            return null;
80
        }
81
82 31
        if (isset($parametri['modulo'])) {
83 31
            $this->modulo = $parametri['modulo'];
84
        }
85 31
        $this->setCrud();
86
87 31
        return $this->presente('U') || ($this->isSuperAdmin()); //SuperAdmin
88
    }
89
90 17
    private function isSuperAdmin()
91
    {
92 17
        $utente = $this->container->get('security.token_storage')->getToken()->getUser()->getId();
93 17
        $q = $this->container->get('doctrine')
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 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...
94 17
                ->getRepository('FiCoreBundle:Operatori')
95 17
                ->find($utente);
96
97 17
        $isSuperAdmin = false;
98 17
        if ($q) {
99 17
            if ($q->getRuoli()) {
100 4
                $isSuperAdmin = $q->getRuoli()->isSuperadmin();
101
            }
102
        }
103 17
        return $isSuperAdmin;
104
    }
105
106
    public function sulmenu($parametri = array())
107
    {
108
        if (isset($parametri['modulo'])) {
109
            $this->modulo = $parametri['modulo'];
110
        }
111
        $permesso = $this->leggere($parametri) ||
112
                $this->cancellare($parametri) ||
113
                $this->creare($parametri) ||
114
                $this->aggiornare($parametri);
115
116
        if ($permesso) {
117
            return true;
118
        }
119
120
        return false;
121
    }
122
123 32
    public function setCrud($parametri = array())
124
    {
125 32
        if (isset($parametri['modulo'])) {
126
            $this->modulo = $parametri['modulo'];
127
        }
128
129 32
        $utentecorrente = $this->utentecorrente();
130 32
        $q = PermessiSingletonUtility::instance(
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 14 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...
131 32
            $this->container->get('doctrine'),
132 32
            $this->modulo,
133 32
            $utentecorrente["id"],
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal id 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...
134 32
            $utentecorrente['ruolo_id']
135 32
        )->getPermessi();
136
137 32
        if ($q) {
138 26
            $this->crud = $q->getCrud();
139 26
            return;
140
        }
141
142 16
        $this->crud = '';
143 16
    }
144
145 35
    public function utentecorrente()
146
    {
147 35
        $utentecorrente = array();
148
149 35
        if (!$this->container->get('security.token_storage')->getToken()) {
150 1
            $utentecorrente['nome'] = 'Utente non registrato';
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...
151 1
            $utentecorrente['id'] = 0;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 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 1
            $utentecorrente['ruolo_id'] = 0;
153
154 1
            return $utentecorrente;
155
        }
156
157 34
        $utente = $this->container->get('security.token_storage')->getToken()->getUser()->getId();
158 34
        $q = $this->container->get('doctrine')
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 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 34
                ->getRepository('FiCoreBundle:Operatori')
160 34
                ->find($utente);
161
162 34
        $utentecorrente['username'] = $utente;
163 34
        $utentecorrente['codice'] = $utente;
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...
164
165 34
        if (!$q) {
166
            $utentecorrente['nome'] = 'Utente non registrato';
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...
167
            $utentecorrente['id'] = 0;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 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
            $utentecorrente['ruolo_id'] = 0;
169
170
            return $utentecorrente;
171
        }
172
173 34
        $utentecorrente['nome'] = $q->getOperatore();
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...
174 34
        $utentecorrente['id'] = $q->getId();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 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...
175 34
        $utentecorrente['ruolo_id'] = ($q->getRuoli() ? $q->getRuoli()->getId() : 0);
176
177 34
        return $utentecorrente;
178
    }
179
180 19
    public function impostaPermessi($parametri = array())
181
    {
182 19
        $risposta = array();
183
184 19
        $risposta['permessiedit'] = $this->aggiornare($parametri);
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...
185 19
        $risposta['permessidelete'] = $this->cancellare($parametri);
186 19
        $risposta['permessicreate'] = $this->creare($parametri);
187 19
        $risposta['permessiread'] = $this->leggere($parametri);
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...
188
189 19
        return $risposta;
190
    }
191
}
192