Completed
Branch 2.x (03096d)
by Julián
08:36
created

Redis   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 85
rs 10
c 1
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A open() 0 6 1
A close() 0 4 1
A read() 0 8 1
A write() 0 7 1
A destroy() 0 6 1
A gc() 0 4 1
1
<?php
2
3
/*
4
 * sessionware (https://github.com/juliangut/sessionware).
5
 * PSR7 session management middleware.
6
 *
7
 * @license BSD-3-Clause
8
 * @link https://github.com/juliangut/sessionware
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
declare(strict_types=1);
13
14
namespace Jgut\Sessionware\Handler;
15
16
/**
17
 * Redis session handler.
18
 */
19
class Redis implements Handler
20
{
21
    use HandlerTrait;
22
23
    /**
24
     * @var \Redis
25
     */
26
    protected $driver;
27
28
    /**
29
     * Redis session handler constructor.
30
     *
31
     * @param \Redis $driver
32
     */
33
    public function __construct(\Redis $driver)
34
    {
35
        $this->driver = $driver;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     *
41
     * @throws \RuntimeException
42
     *
43
     * @SuppressWarnings(PMD.UnusedFormalParameter)
44
     */
45
    public function open($savePath, $sessionName)
46
    {
47
        $this->testConfiguration();
48
49
        return true;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function close()
56
    {
57
        return true;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function read($sessionId)
64
    {
65
        $sessionData = $this->driver->get($sessionId);
66
67
        $this->driver->expire($sessionId, $this->configuration->getLifetime());
68
69
        return $sessionData;
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function write($sessionId, $sessionData)
76
    {
77
        $this->driver->set($sessionId, $sessionData);
78
        $this->driver->expire($sessionId, $this->configuration->getLifetime());
79
80
        return true;
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function destroy($sessionId)
87
    {
88
        $this->driver->del($sessionId);
89
90
        return true;
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     *
96
     * @SuppressWarnings(PMD.ShortMethodName)
97
     * @SuppressWarnings(PMD.UnusedFormalParameter)
98
     */
99
    public function gc($maxLifetime)
100
    {
101
        return true;
102
    }
103
}
104