LaminasSession   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 71
ccs 29
cts 29
cp 1
rs 10
c 0
b 0
f 0
wmc 12

12 Methods

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