Passed
Push — master ( 1ae96b...301b02 )
by Jelmer
03:29
created

ZendSession   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 81.25%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 0
loc 74
ccs 26
cts 32
cp 0.8125
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A has() 0 4 1
A get() 0 4 1
A set() 0 5 1
A getFlash() 0 4 1
A setFlash() 0 6 1
A destroy() 0 4 1
A rotateId() 0 5 1
A isEmpty() 0 4 1
A hasChanged() 0 4 1
A toArray() 0 4 1
1
<?php declare(strict_types = 1);
2
3
namespace jschreuder\Middle\Session;
4
5
use Zend\Session\Container;
6
use Zend\Session\SessionManager;
7
8
class ZendSession implements SessionInterface
9
{
10
    /** @var  SessionManager */
11
    private $sessionManager;
12
13
    /** @var  Container */
14
    private $container;
15
16
    private $changed = false;
17
18 9
    public function __construct(SessionManager $sessionManager, Container $container)
19
    {
20 9
        $this->sessionManager = $sessionManager;
21 9
        $this->container = $container;
22 9
    }
23
24 1
    public function has(string $key) : bool
25
    {
26 1
        return isset($this->container[$key]);
27
    }
28
29 1
    public function get(string $key)
30
    {
31 1
        return $this->container[$key];
32
    }
33
34
    /** @return  void */
35 1
    public function set(string $key, $value)
36
    {
37 1
        $this->changed = true;
38 1
        $this->container[$key] = $value;
39 1
    }
40
41 1
    public function getFlash(string $key)
42
    {
43 1
        return $this->container[$key];
44
    }
45
46
    /** @return  void */
47 1
    public function setFlash(string $key, $value)
48
    {
49 1
        $this->changed = true;
50 1
        $this->container[$key] = $value;
51 1
        $this->container->setExpirationHops(1, [$key]);
52 1
    }
53
54
    /** @return  void */
55 1
    public function destroy()
56
    {
57 1
        $this->sessionManager->destroy();
58 1
    }
59
60
    /** @return  void */
61 1
    public function rotateId()
62
    {
63 1
        $this->changed = true;
64 1
        $this->sessionManager->regenerateId();
65 1
    }
66
67
    public function isEmpty() : bool
68
    {
69
        return $this->container->count() === 0;
70
    }
71
72
    public function hasChanged() : bool
73
    {
74
        return $this->changed;
75
    }
76
77
    public function toArray() : array
78
    {
79
        return $this->container->getArrayCopy();
80
    }
81
}
82