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

PermessiSingletonUtility::instance()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5.9256

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 10
cts 15
cp 0.6667
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 12
nc 4
nop 4
crap 5.9256
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 Fi\CoreBundle\Utils;
10
11
final class PermessiSingletonUtility
12
{
13
14
    private static $PermessiTabelle;
15
    private static $modulo;
16
    private static $operatore;
17
    private static $ruolo;
18
19
    /**
20
     * Call this method to get singleton
21
     *
22
     * @return UserFactory
0 ignored issues
show
Bug introduced by
The type Fi\CoreBundle\Utils\UserFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
     */
24 16
    public static function instance($em, $modulo, $operatore, $ruolo)
25
    {
26 16
        static $inst = null;
27 16
        if ($inst === null) {
28
            self::$modulo = $modulo;
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...
29
            self::$operatore = $operatore;
30
            self::$ruolo = $ruolo;
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...
31
            $inst = new PermessiSingletonUtility($em, $modulo, $operatore, $ruolo);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 12 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 16
        if ($modulo != self::$modulo || $operatore != self::$operatore || $ruolo != self::$ruolo) {
34 8
            self::$modulo = $modulo;
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...
35 8
            self::$operatore = $operatore;
36 8
            self::$ruolo = $ruolo;
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...
37 8
            $inst = new PermessiSingletonUtility($em, $modulo, $operatore, $ruolo);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 12 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...
38 8
        }
39 16
        return $inst;
40
    }
41
42
    /**
43
     * Private construct so nobody else can instantiate it
44
     *
45
     */
46 8
    private function __construct($em, $modulo, $operatore, $ruolo)
47
    {
48
        $q = $em
49 8
                ->getRepository('FiCoreBundle:Permessi')
50 8
                ->findOneBy(array('operatori_id' => $operatore, 'modulo' => $modulo));
51
52 8
        if (!$q) {
53
            $q = $em
54 8
                    ->getRepository('FiCoreBundle:Permessi')
55 8
                    ->findOneBy(array('ruoli_id' => $ruolo, 'modulo' => $modulo, 'operatori_id' => null));
56 8
            if (!$q) {
57
                $q = $em
58 1
                        ->getRepository('FiCoreBundle:Permessi')
59 1
                        ->findOneBy(array('ruoli_id' => null, 'modulo' => $modulo, 'operatori_id' => null));
60 1
            }
61 8
        }
62
63 8
        self::$PermessiTabelle = $q;
64 8
    }
65
66 16
    public static function getPermessi()
67
    {
68 16
        return self::$PermessiTabelle;
69
    }
70
}
71