DoctrineCacheSessionHandler::read()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Nofw\Session;
4
5
use Doctrine\Common\Cache\Cache;
6
7
/**
8
 * Doctrine Cache Session handler implementation.
9
 *
10
 * @author Márk Sági-Kazár <[email protected]>
11
 */
12
final class DoctrineCacheSessionHandler implements \SessionHandlerInterface
13
{
14
    /**
15
     * @var Cache
16
     */
17
    private $cache;
18
19
    /**
20
     * @param Cache $cache
21
     */
22 11
    public function __construct(Cache $cache)
23
    {
24 11
        $this->cache = $cache;
25 11
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 1
    public function close()
31
    {
32 1
        return true;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 2
    public function destroy($session_id)
39
    {
40 2
        return $this->cache->delete($session_id);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 1
    public function gc($maxlifetime)
47
    {
48 1
        return true;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 1
    public function open($save_path, $name)
55
    {
56 1
        return true;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 2
    public function read($session_id)
63
    {
64 2
        return (string) $this->cache->fetch($session_id);
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 2
    public function write($session_id, $session_data)
71
    {
72 2
        return $this->cache->save($session_id, $session_data);
73
    }
74
}
75