LaminasSession::has()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 18
    public function __construct(
15
        private readonly SessionManager $sessionManager,
16
        private readonly Container $container
17
    )
18
    {
19 18
    }
20
21 4
    public function has(string $key): bool
22
    {
23 4
        return isset($this->container[$key]);
24
    }
25
26 3
    public function get(string $key): mixed
27
    {
28 3
        return $this->container[$key];
29
    }
30
31 6
    public function set(string $key, $value): void
32
    {
33 6
        $this->changed = true;
34 6
        $this->container[$key] = $value;
35
    }
36
37 4
    public function hasFlash(string $key): bool
38
    {
39 4
        return isset($this->container[self::FLASH_DATA_KEY_PREFIX . $key]);
40
    }
41
42 3
    public function getFlash(string $key): mixed
43
    {
44 3
        return $this->container[self::FLASH_DATA_KEY_PREFIX . $key];
45
    }
46
47 3
    public function setFlash(string $key, $value): void
48
    {
49 3
        $key = self::FLASH_DATA_KEY_PREFIX . $key;
50 3
        $this->changed = true;
51 3
        $this->container[$key] = $value;
52 3
        $this->container->setExpirationHops(1, [$key]);
53
    }
54
55 2
    public function destroy(): void
56
    {
57 2
        $this->container->exchangeArray([]);
58 2
        $this->sessionManager->destroy();
59
    }
60
61 1
    public function rotateId(): void
62
    {
63 1
        $this->changed = true;
64 1
        $this->sessionManager->regenerateId();
65
    }
66
67 3
    public function isEmpty(): bool
68
    {
69 3
        return empty($this->toArray());
70
    }
71
72 2
    public function hasChanged(): bool
73
    {
74 2
        return $this->changed;
75
    }
76
77 4
    public function toArray(): array
78
    {
79 4
        return $this->container->getArrayCopy();
80
    }
81
}
82