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

Memory::read()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 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
 * In-memory session handler.
18
 */
19
class Memory implements Handler
20
{
21
    use HandlerTrait;
22
23
    /**
24
     * @var array
25
     */
26
    protected $data = [];
27
28
    /**
29
     * {@inheritdoc}
30
     *
31
     * @throws \RuntimeException
32
     *
33
     * @SuppressWarnings(PMD.UnusedFormalParameter)
34
     */
35
    public function open($savePath, $sessionName)
36
    {
37
        $this->testConfiguration();
38
39
        return true;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function close()
46
    {
47
        return true;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     *
53
     * @SuppressWarnings(PMD.UnusedFormalParameter)
54
     */
55
    public function read($sessionId)
56
    {
57
        return serialize($this->data);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     *
63
     * @SuppressWarnings(PMD.UnusedFormalParameter)
64
     */
65
    public function write($sessionId, $sessionData)
66
    {
67
        $this->data = unserialize($sessionData);
68
69
        return true;
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     *
75
     * @SuppressWarnings(PMD.UnusedFormalParameter)
76
     */
77
    public function destroy($sessionId)
78
    {
79
        $this->data = [];
80
81
        return true;
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     *
87
     * @SuppressWarnings(PMD.ShortMethodName)
88
     * @SuppressWarnings(PMD.UnusedFormalParameter)
89
     */
90
    public function gc($maxLifetime)
91
    {
92
        return true;
93
    }
94
}
95