Passed
Branch master (068d7d)
by Mathieu
01:51
created

Session::init()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 17
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 7.3329

Importance

Changes 0
Metric Value
cc 6
eloc 15
nc 6
nop 0
dl 0
loc 17
ccs 10
cts 15
cp 0.6667
crap 7.3329
rs 9.2222
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
namespace Suricate;
3
4
use Exception;
5
6
/**
7
 * @property string $type Session type
8
 */
9
class Session extends Service implements Interfaces\ISession
10
{
11
    protected $parametersList = ['type'];
12
    private static $container;
13
14 5
    protected function init()
15
    {
16 5
        if (self::$container === null) {
17 2
            switch ($this->type) {
18 2
                case 'native':
19 1
                    self::$container = Suricate::SessionNative(true);
20 1
                    break;
21 1
                case 'cookie':
22
                    self::$container = Suricate::SessionCookie(true);
23
                    break;
24 1
                case 'memcache':
25
                    self::$container = Suricate::SessionMemcache(true);
26
                    break;
27 1
                case 'none':
28
                    break;
29
                default:
30 1
                    throw new Exception("Unknown session type " . $this->type);
31
            }
32
        }
33 4
    }
34
    
35
    /**
36
     * Get instance of session driver used
37
     * @return Session driver instance
38
     */
39 1
    public function getInstance()
40
    {
41 1
        $this->init();
42 1
        return self::$container;
43
    }
44
45 1
    public function getId()
46
    {
47 1
        $this->init();
48 1
        return self::$container->getId();
49
    }
50 1
    public function regenerate()
51
    {
52 1
        $this->init();
53 1
        return self::$container->regenerate();
54
    }
55
56 5
    public function read($key)
57
    {
58 5
        $this->init();
59 4
        return self::$container->read($key);
60
    }
61
62 4
    public function write($key, $data)
63
    {
64 4
        $this->init();
65 4
        return self::$container->write($key, $data);
66
    }
67
68 4
    public function destroy($key)
69
    {
70 4
        $this->init();
71 4
        return self::$container->destroy($key);
72
    }
73
74 1
    public function close()
75
    {
76 1
        $this->init();
77 1
        return self::$container->close();
78
    }
79
}
80