Passed
Push — master ( 8f091f...afd23e )
by Andrea
27:57 queued 25:00
created

PermessiManager::canCreate()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 4
nop 1
dl 0
loc 14
ccs 9
cts 9
cp 1
crap 4
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Cdf\BiCoreBundle\Service\Permessi;
10
11
use Cdf\BiCoreBundle\Entity\Permessi;
12
use Doctrine\Common\Persistence\ObjectManager;
13
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
14
15
class PermessiManager
16
{
17 18
    public function __construct(ObjectManager $em, TokenStorageInterface $user)
18
    {
19 18
        $this->em = $em;
0 ignored issues
show
Bug Best Practice introduced by
The property em does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
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...
20 18
        $this->user = $user->getToken()->getUser();
0 ignored issues
show
Bug Best Practice introduced by
The property user does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
21 18
    }
22 13
    public function canRead($modulo)
23
    {
24 13
        $permessi = $this->em->getRepository(Permessi::class)->findPermessoModuloOperatore($modulo, $this->user);
25 13
        $canread = false;
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...
26 13
        if ($permessi) {
27 4
            if (stripos(strtoupper($permessi->getCrud()), 'R') !== false) {
28 4
                $canread = true;
29
            }
30
        } else {
31 13
            if ($this->user->isSuperadmin()) {
32 11
                $canread = true;
33
            }
34
        }
35 13
        return $canread;
36
    }
37 12
    public function canCreate($modulo)
38
    {
39 12
        $permessi = $this->em->getRepository(Permessi::class)->findPermessoModuloOperatore($modulo, $this->user);
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 12
        $cancreate = false;
41 12
        if ($permessi) {
42 4
            if (stripos(strtoupper($permessi->getCrud()), 'C') !== false) {
43 4
                $cancreate = true;
44
            }
45
        } else {
46 9
            if ($this->user->isSuperadmin()) {
47 8
                $cancreate = true;
48
            }
49
        }
50 12
        return $cancreate;
51
    }
52 15
    public function canUpdate($modulo)
53
    {
54 15
        $permessi = $this->em->getRepository(Permessi::class)->findPermessoModuloOperatore($modulo, $this->user);
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...
55 15
        $canupdate = false;
56 15
        if ($permessi) {
57 4
            if (stripos(strtoupper($permessi->getCrud()), 'U') !== false) {
58 4
                $canupdate = true;
59
            }
60
        } else {
61 12
            if ($this->user->isSuperadmin()) {
62 10
                $canupdate = true;
63
            }
64
        }
65 15
        return $canupdate;
66
    }
67 12
    public function canDelete($modulo)
68
    {
69 12
        $permessi = $this->em->getRepository(Permessi::class)->findPermessoModuloOperatore($modulo, $this->user);
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...
70 12
        $candelete = false;
71 12
        if ($permessi) {
72 4
            if (stripos(strtoupper($permessi->getCrud()), 'D') !== false) {
73 4
                $candelete = true;
74
            }
75
        } else {
76 9
            if ($this->user->isSuperadmin()) {
77 8
                $candelete = true;
78
            }
79
        }
80 12
        return $candelete;
81
    }
82 11
    public function toJson($modulo)
83
    {
84
        return array(
85 11
            "read" => $this->canRead($modulo),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal read 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...
86 11
            "create" => $this->canCreate($modulo),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal create 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...
87 11
            "delete" => $this->canDelete($modulo),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal delete 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...
88 11
            "update" => $this->canUpdate($modulo)
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal update 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...
89
        );
90
    }
91
}
92