Completed
Push — master ( 2994aa...19d116 )
by Patrick
08:28
created

SessionPersistentDataStore   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 21.43%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 62
ccs 3
cts 14
cp 0.2143
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 8 2
A set() 0 4 1
A clear() 0 6 2
1
<?php
2
namespace Dropbox\Store;
3
4
class SessionPersistentDataStore implements PersistentDataStoreInterface
5
{
6
7
    /**
8
     * Session Variable Prefix
9
     *
10
     * @var string
11
     */
12
    protected $prefix;
13
14
    /**
15
     * Create a new SessionPersistentDataStore instance
16
     *
17
     * @param string $prefix Session Variable Prefix
18
     */
19 58
    public function __construct($prefix = "DBAPI_")
20
    {
21 58
        $this->prefix = $prefix;
22 58
    }
23
24
    /**
25
     * Get a value from the store
26
     *
27
     * @param  string $key Data Key
28
     *
29
     * @return string|null
30
     */
31
    public function get($key)
32
    {
33
        if (isset($_SESSION[$this->prefix . $key])) {
34
            return $_SESSION[$this->prefix . $key];
35
        }
36
37
        return null;
38
    }
39
40
    /**
41
     * Set a value in the store
42
     * @param string $key   Data Key
43
     * @param string $value Data Value
44
     *
45
     * @return void
46
     */
47
    public function set($key, $value)
48
    {
49
        $_SESSION[$this->prefix . $key] = $value;
50
    }
51
52
    /**
53
     * Clear the key from the store
54
     *
55
     * @param $key Data Key
56
     *
57
     * @return void
58
     */
59
    public function clear($key)
60
    {
61
        if (isset($_SESSION[$this->prefix . $key])) {
62
            unset($_SESSION[$this->prefix . $key]);
63
        }
64
    }
65
}
66