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

PermessiSingletonUtility   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 28.57%

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 46
ccs 6
cts 21
cp 0.2857
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A instance() 0 7 2
A getPermessi() 0 3 1
A __construct() 0 18 3
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