Passed
Push — master ( ea64e0...b9bf1e )
by Andrea
11:15
created

PermessiSingletonUtility::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 12
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 12
nc 3
nop 4
crap 12
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
16
    /**
17
     * Call this method to get singleton
18
     *
19
     * @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...
20
     */
21 16
    public static function instance($em, $modulo, $operatore, $ruolo)
22
    {
23 16
        static $inst = null;
24 16
        if ($inst === null) {
25
            $inst = new PermessiSingletonUtility($em, $modulo, $operatore, $ruolo);
26
        }
27 16
        return $inst;
28
    }
29
30
    /**
31
     * Private construct so nobody else can instantiate it
32
     *
33
     */
34
    private function __construct($em, $modulo, $operatore, $ruolo)
35
    {
36
        $q = $em
37
                ->getRepository('FiCoreBundle:Permessi')
38
                ->findOneBy(array('operatori_id' => $operatore, 'modulo' => $modulo));
39
40
        if (!$q) {
41
            $q = $em
42
                    ->getRepository('FiCoreBundle:Permessi')
43
                    ->findOneBy(array('ruoli_id' => $ruolo, 'modulo' => $modulo, 'operatori_id' => null));
44
            if (!$q) {
45
                $q = $em
46
                        ->getRepository('FiCoreBundle:Permessi')
47
                        ->findOneBy(array('ruoli_id' => null, 'modulo' => $modulo, 'operatori_id' => null));
48
            }
49
        }
50
51
        self::$PermessiTabelle = $q;
52
    }
53
54 16
    public static function getPermessi()
55
    {
56 16
        return self::$PermessiTabelle;
57
    }
58
}
59