AbstractAdapter::prepareId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
/**
4
 * Bluz Framework Component
5
 *
6
 * @copyright Bluz PHP Team
7
 * @link      https://github.com/bluzphp/framework
8
 */
9
10
declare(strict_types=1);
11
12
namespace Bluz\Session\Adapter;
13
14
/**
15
 * Abstract session handler
16
 *
17
 * @package Bluz\Session\Adapter
18
 */
19
abstract class AbstractAdapter
20
{
21
    /**
22
     * @var mixed instance of Redis or Cache or some other
23
     */
24
    protected $handler = null;
25
26
    /**
27
     * @var string prefix for session store
28
     */
29
    protected $prefix = 'PHPSESSID:';
30
31
    /**
32
     * @var integer TTL of session
33
     */
34
    protected $ttl = 1800;
35
36
    /**
37
     * Prepare Id - add prefix
38
     *
39
     * @param  string $id
40
     *
41
     * @return string
42
     */
43
    protected function prepareId($id): string
44
    {
45
        return $this->prefix . $id;
46
    }
47
48
    /**
49
     * Initialize session
50
     *
51
     * @param  string $savePath
52
     * @param  string $sessionName
53
     *
54
     * @return bool
55
     */
56
    public function open($savePath, $sessionName): bool
0 ignored issues
show
Unused Code introduced by
The parameter $savePath is not used and could be removed. ( Ignorable by Annotation )

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

56
    public function open(/** @scrutinizer ignore-unused */ $savePath, $sessionName): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
57
    {
58
        $this->prefix = $sessionName . ':';
59
        $this->ttl = (int)ini_get('session.gc_maxlifetime');
60
61
        // No more action necessary because connection is injected
62
        // in constructor and arguments are not applicable.
63
64
        return true;
65
    }
66
67
    /**
68
     * Close the session
69
     *
70
     * @return bool
71
     */
72
    public function close(): bool
73
    {
74
        $this->handler = null;
75
        unset($this->handler);
76
        return true;
77
    }
78
79
    /**
80
     * Cleanup old sessions
81
     *
82
     * @param integer $maxLifetime
83
     *
84
     * @return bool
85
     */
86
    public function gc($maxLifetime): bool
0 ignored issues
show
Unused Code introduced by
The parameter $maxLifetime is not used and could be removed. ( Ignorable by Annotation )

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

86
    public function gc(/** @scrutinizer ignore-unused */ $maxLifetime): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
87
    {
88
        // no action necessary because using EXPIRE
89
        return true;
90
    }
91
}
92