TabelleSingletonUtility   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 7
eloc 18
c 3
b 1
f 0
dl 0
loc 45
ccs 15
cts 18
cp 0.8333
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A getTabelle() 0 3 1
A instance() 0 14 4
1
<?php
2
3
namespace Fi\CoreBundle\Utils;
4
5
final class TabelleSingletonUtility
6
{
7
8
    private static $queryTabelle;
9
    private static $nometabella;
10
    private static $operatore;
11
12 21
    public static function instance($em, $nometabella, $operatore)
13
    {
14 21
        static $inst = null;
15 21
        if ($inst === null) {
16
            self::$nometabella = $nometabella;
17
            self::$operatore = $operatore;
18
            $inst = new TabelleSingletonUtility($em, $nometabella, $operatore);
19
        }
20 21
        if ($nometabella != self::$nometabella || $operatore != self::$operatore) {
21 15
            self::$nometabella = $nometabella;
22 15
            self::$operatore = $operatore;
23 15
            $inst = new TabelleSingletonUtility($em, $nometabella, $operatore);
24
        }
25 21
        return $inst;
26
    }
27
28
    /**
29
     * Private construct so nobody else can instantiate it
30
     *
31
     */
32 15
    private function __construct($em, $nometabella, $operatore)
33
    {
34 15
        self::$queryTabelle = $em->getRepository('FiCoreBundle:Tabelle')->findBy(array('operatori_id' => $operatore, 'nometabella' => $nometabella));
35
36 15
        if (!self::$queryTabelle) {
37 15
            self::$queryTabelle = $em->getRepository('FiCoreBundle:Tabelle')->findBy(array('operatori_id' => null, 'nometabella' => $nometabella));
38
        }
39 15
    }
40
41
    /**
42
     * Call this method to get singleton
43
     *
44
     * @return \Fi\CoreBundle\Entity\Tabelle
45
     */
46
    
47 21
    public static function getTabelle()
48
    {
49 21
        return self::$queryTabelle;
50
    }
51
}
52