PermessiSingletonUtility   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 84.62%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 30
c 1
b 0
f 0
dl 0
loc 58
ccs 22
cts 26
cp 0.8462
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A instance() 0 16 5
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
    private static $modulo;
16
    private static $operatore;
17
    private static $ruolo;
18
19 32
    public static function instance($em, $modulo, $operatore, $ruolo)
20
    {
21 32
        static $inst = null;
22 32
        if ($inst === null) {
23
            self::$modulo = $modulo;
24
            self::$operatore = $operatore;
25
            self::$ruolo = $ruolo;
26
            $inst = new PermessiSingletonUtility($em, $modulo, $operatore, $ruolo);
27
        }
28 32
        if ($modulo != self::$modulo || $operatore != self::$operatore || $ruolo != self::$ruolo) {
29 25
            self::$modulo = $modulo;
30 25
            self::$operatore = $operatore;
31 25
            self::$ruolo = $ruolo;
32 25
            $inst = new PermessiSingletonUtility($em, $modulo, $operatore, $ruolo);
33
        }
34 32
        return $inst;
35
    }
36
37
    /**
38
     * Private construct so nobody else can instantiate it
39
     *
40
     */
41 25
    private function __construct($em, $modulo, $operatore, $ruolo)
42
    {
43
        $q = $em
44 25
                ->getRepository('FiCoreBundle:Permessi')
45 25
                ->findOneBy(array('operatori_id' => $operatore, 'modulo' => $modulo));
46
47 25
        if (!$q) {
48
            $q = $em
49 25
                    ->getRepository('FiCoreBundle:Permessi')
50 25
                    ->findOneBy(array('ruoli_id' => $ruolo, 'modulo' => $modulo, 'operatori_id' => null));
51 25
            if (!$q) {
52
                $q = $em
53 16
                        ->getRepository('FiCoreBundle:Permessi')
54 16
                        ->findOneBy(array('ruoli_id' => null, 'modulo' => $modulo, 'operatori_id' => null));
55
            }
56
        }
57
58 25
        self::$PermessiTabelle = $q;
59 25
    }
60
61
    /**
62
     * Call this method to get singleton
63
     *
64
     * @return \Fi\CoreBundle\Entity\Permessi
65
     */
66 32
    public static function getPermessi()
67
    {
68 32
        return self::$PermessiTabelle;
69
    }
70
}
71