TabelleSingletonUtility::instance()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.3244

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 10
c 3
b 1
f 0
dl 0
loc 14
ccs 8
cts 11
cp 0.7272
rs 9.9332
cc 4
nc 4
nop 3
crap 4.3244
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