Passed
Push — master ( 1e250a...632266 )
by Andrea
22:07
created

GestionePermessi   B

Complexity

Total Complexity 36

Size/Duplication

Total Lines 175
Duplicated Lines 0 %

Test Coverage

Coverage 84.11%

Importance

Changes 0
Metric Value
wmc 36
dl 0
loc 175
ccs 90
cts 107
cp 0.8411
rs 8.8
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
B sulmenu() 0 15 6
A __construct() 0 3 1
B utentecorrente() 0 33 4
A impostaPermessi() 0 10 1
A aggiornare() 0 12 4
A leggere() 0 12 4
A creare() 0 11 4
A cancellare() 0 11 4
A presente() 0 6 2
A setCrud() 0 20 3
A isSuperAdmin() 0 14 3
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 18
    public function __construct(Container $container)
23
    {
24 18
        $this->container = $container;
25 18
    }
26
27 16
    private function presente($lettera)
28
    {
29 16
        if (stripos($this->crud, $lettera) !== false) {
30 15
            return true;
31
        } else {
32 2
            return false;
33
        }
34
    }
35
36 17
    public function leggere($parametri = array())
37
    {
38 17
        if (!$this->container->get('security.token_storage')->getToken()) {
39 1
            return null;
40
        }
41 16
        if (isset($parametri['modulo'])) {
42 16
            $this->modulo = $parametri['modulo'];
43 16
        }
44
45 16
        $this->setCrud();
46
47 16
        return $this->presente('R') || ($this->isSuperAdmin()); //SuperAdmin
48
    }
49
50 16
    public function cancellare($parametri = array())
51
    {
52 16
        if (!$this->container->get('security.token_storage')->getToken()) {
53 1
            return null;
54
        }
55 15
        if (isset($parametri['modulo'])) {
56 15
            $this->modulo = $parametri['modulo'];
57 15
        }
58 15
        $this->setCrud();
59
60 15
        return $this->presente('D') || ($this->isSuperAdmin()); //SuperAdmin
61
    }
62
63 16
    public function creare($parametri = array())
64
    {
65 16
        if (!$this->container->get('security.token_storage')->getToken()) {
66 1
            return null;
67
        }
68 15
        if (isset($parametri['modulo'])) {
69 15
            $this->modulo = $parametri['modulo'];
70 15
        }
71 15
        $this->setCrud();
72
73 15
        return $this->presente('C') || ($this->isSuperAdmin()); //SuperAdmin
74
    }
75
76 16
    public function aggiornare($parametri = array())
77
    {
78 16
        if (!$this->container->get('security.token_storage')->getToken()) {
79 1
            return null;
80
        }
81
82 15
        if (isset($parametri['modulo'])) {
83 15
            $this->modulo = $parametri['modulo'];
84 15
        }
85 15
        $this->setCrud();
86
87 15
        return $this->presente('U') || ($this->isSuperAdmin()); //SuperAdmin
88
    }
89
90 2
    private function isSuperAdmin()
91
    {
92 2
        $utente = $this->container->get('security.token_storage')->getToken()->getUser()->getId();
93 2
        $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 2
                ->getRepository('FiCoreBundle:Operatori')
95 2
                ->find($utente);
96
97 2
        $isSuperAdmin = false;
98 2
        if ($q) {
99 2
            if ($q->getRuoli()) {
100 2
                $isSuperAdmin = $q->getRuoli()->isSuperadmin();
101 2
            }
102 2
        }
103 2
        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 16
    public function setCrud($parametri = array())
124
    {
125 16
        if (isset($parametri['modulo'])) {
126
            $this->modulo = $parametri['modulo'];
127
        }
128
129 16
        $utentecorrente = $this->utentecorrente();
130 16
        $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 16
            $this->container->get('doctrine'),
132 16
            $this->modulo,
133 16
            $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 16
            $utentecorrente['ruolo_id']
135 16
        )->getPermessi();
136
137 16
        if ($q) {
138 15
            $this->crud = $q->getCrud();
139 15
            return;
140
        }
141
142 1
        $this->crud = '';
143 1
    }
144
145 17
    public function utentecorrente()
146
    {
147 17
        $utentecorrente = array();
148
149 17
        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 16
        $utente = $this->container->get('security.token_storage')->getToken()->getUser()->getId();
158 16
        $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 16
                ->getRepository('FiCoreBundle:Operatori')
160 16
                ->find($utente);
161
162 16
        $utentecorrente['username'] = $utente;
163 16
        $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 16
        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 16
        $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 16
        $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 16
        $utentecorrente['ruolo_id'] = ($q->getRuoli() ? $q->getRuoli()->getId() : 0);
176
177 16
        return $utentecorrente;
178
    }
179
180 16
    public function impostaPermessi($parametri = array())
181
    {
182 16
        $risposta = array();
183
184 16
        $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 16
        $risposta['permessidelete'] = $this->cancellare($parametri);
186 16
        $risposta['permessicreate'] = $this->creare($parametri);
187 16
        $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 16
        return $risposta;
190
    }
191
}
192