Completed
Push — develop ( f7e243...a4fd62 )
by Mathieu
01:40
created

Session::init()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 17
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 29.4373

Importance

Changes 0
Metric Value
cc 6
eloc 15
nc 6
nop 0
dl 0
loc 17
ccs 2
cts 15
cp 0.1333
crap 29.4373
rs 9.2222
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
namespace Suricate;
3
4
use Exception;
5
6
class Session extends Service implements Interfaces\ISession
7
{
8
    protected $parametersList = ['type'];
9
    private static $container;
10
11
    
12 1
    protected function init()
13
    {
14 1
        if (self::$container === null) {
15
            switch ($this->type) {
0 ignored issues
show
Bug Best Practice introduced by
The property type does not exist on Suricate\Session. Since you implemented __get, consider adding a @property annotation.
Loading history...
16
                case 'native':
17
                    self::$container = Suricate::SessionNative(true);
0 ignored issues
show
Bug introduced by
The method SessionNative() does not exist on Suricate\Suricate. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

17
                    /** @scrutinizer ignore-call */ 
18
                    self::$container = Suricate::SessionNative(true);
Loading history...
18
                    break;
19
                case 'cookie':
20
                    self::$container = Suricate::SessionCookie(true);
0 ignored issues
show
Bug introduced by
The method SessionCookie() does not exist on Suricate\Suricate. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
                    /** @scrutinizer ignore-call */ 
21
                    self::$container = Suricate::SessionCookie(true);
Loading history...
21
                    break;
22
                case 'memcache':
23
                    self::$container = Suricate::SessionMemcache(true);
0 ignored issues
show
Bug introduced by
The method SessionMemcache() does not exist on Suricate\Suricate. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
                    /** @scrutinizer ignore-call */ 
24
                    self::$container = Suricate::SessionMemcache(true);
Loading history...
24
                    break;
25
                case 'none':
26
                    break;
27
                default:
28
                    throw new Exception("Unknown session type " . $this->type);
29
            }
30
        }
31 1
    }
32
    
33
    /**
34
     * Get instance of session driver used
35
     * @return Sessiondriver instance
0 ignored issues
show
Bug introduced by
The type Suricate\Sessiondriver 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...
36
     */
37
    public function getInstance()
38
    {
39
        $this->init();
40
        return self::$container;
41
    }
42
43
    public function getId()
44
    {
45
        $this->init();
46
        return self::$container->getId();
47
    }
48
    public function regenerate()
49
    {
50
        $this->init();
51
        return self::$container->regenerate();
52
    }
53
54
    public function read($key)
55
    {
56
        $this->init();
57
        return self::$container->read($key);
58
    }
59
60
    public function write($key, $data)
61
    {
62
        $this->init();
63
        return self::$container->write($key, $data);
64
    }
65
66
    public function destroy($key)
67
    {
68
        $this->init();
69
        return self::$container->destroy($key);
70
    }
71
72
    public function close()
73
    {
74
        $this->init();
75
        return self::$container->close();
76
    }
77
}
78