Passed
Push — develop ( 63f05f...0005e4 )
by Mathieu
01:40
created

Session::getInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
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 5
    protected function init()
13
    {
14 5
        if (self::$container === null) {
15 2
            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 2
                case 'native':
17 1
                    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 1
                    break;
19 1
                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 1
                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 1
                case 'none':
26
                    break;
27
                default:
28 1
                    throw new Exception("Unknown session type " . $this->type);
29
            }
30
        }
31 4
    }
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 1
    public function getInstance()
38
    {
39 1
        $this->init();
40 1
        return self::$container;
41
    }
42
43 1
    public function getId()
44
    {
45 1
        $this->init();
46 1
        return self::$container->getId();
47
    }
48 1
    public function regenerate()
49
    {
50 1
        $this->init();
51 1
        return self::$container->regenerate();
52
    }
53
54 5
    public function read($key)
55
    {
56 5
        $this->init();
57 4
        return self::$container->read($key);
58
    }
59
60 4
    public function write($key, $data)
61
    {
62 4
        $this->init();
63 4
        return self::$container->write($key, $data);
64
    }
65
66 4
    public function destroy($key)
67
    {
68 4
        $this->init();
69 4
        return self::$container->destroy($key);
70
    }
71
72 1
    public function close()
73
    {
74 1
        $this->init();
75 1
        return self::$container->close();
76
    }
77
}
78