Passed
Push — master ( b424db...12a61c )
by Jelmer
03:50
created

GenericSession::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php declare(strict_types = 1);
2
3
namespace jschreuder\Middle\Session;
4
5
class GenericSession implements SessionInterface
6
{
7
    /** @var  array */
8
    private $sessionData;
9
10
    /** @var  bool */
11
    private $changed = false;
12
13
    public function __construct(array $sessionData = [])
14
    {
15
        $this->sessionData = $sessionData;
16
    }
17
18
    public function has(string $key) : bool
19
    {
20
        return isset($this->sessionData[$key]);
21
    }
22
23
    public function get(string $key)
24
    {
25
        return $this->sessionData[$key] ?? null;
26
    }
27
28
    public function set(string $key, $value)
29
    {
30
        $this->changed = true;
31
        $this->sessionData[$key] = $value;
32
    }
33
34
    public function getFlash(string $key)
35
    {
36
        return $this->sessionData[$key] ?? null;
37
    }
38
39
    public function setFlash(string $key, $value)
40
    {
41
        $this->changed = true;
42
        $this->sessionData[$key] = $value;
43
    }
44
45
    public function destroy()
46
    {
47
        $this->sessionData = [];
48
    }
49
50
    public function rotateId()
51
    {
52
        // These sessions don't have an ID
53
    }
54
55
    public function isEmpty() : bool
56
    {
57
        return count($this->sessionData) > 0;
58
    }
59
60
    public function hasChanged() : bool
61
    {
62
        return $this->changed;
63
    }
64
}
65