Passed
Push — master ( 473b48...eb1314 )
by Jelmer
01:55
created

ZendSession::getFlash()   A

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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 ZendSession implements SessionInterface
9
{
10
    const FLASH_DATA_KEY_PREFIX = '_flash_data.';
11
12
    private SessionManager $sessionManager;
13
    private \ArrayAccess $container;
14
    private bool $changed = false;
15
16 12
    public function __construct(SessionManager $sessionManager, Container $container)
17
    {
18 12
        $this->sessionManager = $sessionManager;
19 12
        $this->container = $container;
20
    }
21
22 2
    public function has(string $key): bool
23
    {
24 2
        return isset($this->container[$key]);
25
    }
26
27 1
    public function get(string $key): mixed
28
    {
29 1
        return $this->container[$key];
30
    }
31
32 1
    public function set(string $key, $value): void
33
    {
34 1
        $this->changed = true;
35 1
        $this->container[$key] = $value;
36
    }
37
38 2
    public function hasFlash(string $key): bool
39
    {
40 2
        return isset($this->container[self::FLASH_DATA_KEY_PREFIX . $key]);
41
    }
42
43 1
    public function getFlash(string $key): mixed
44
    {
45 1
        return $this->container[self::FLASH_DATA_KEY_PREFIX . $key];
46
    }
47
48 1
    public function setFlash(string $key, $value): void
49
    {
50 1
        $key = self::FLASH_DATA_KEY_PREFIX . $key;
51 1
        $this->changed = true;
52 1
        $this->container[$key] = $value;
53 1
        $this->container->setExpirationHops(1, [$key]);
0 ignored issues
show
Bug introduced by
The method setExpirationHops() does not exist on ArrayAccess. It seems like you code against a sub-type of ArrayAccess such as PhpSpec\ObjectBehavior or PhpSpec\Wrapper\Subject or Laminas\Session\AbstractContainer. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
        $this->container->/** @scrutinizer ignore-call */ 
54
                          setExpirationHops(1, [$key]);
Loading history...
54
    }
55
56 1
    public function destroy(): void
57
    {
58 1
        $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 2
    public function isEmpty(): bool
68
    {
69 2
        return $this->container->count() === 0;
0 ignored issues
show
Bug introduced by
The method count() does not exist on ArrayAccess. It seems like you code against a sub-type of said class. However, the method does not exist in http\Params or pq\Types or HttpQueryString or SolrObject or http\QueryString or Symfony\Component\EventDispatcher\GenericEvent or SolrDocument. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
        return $this->container->/** @scrutinizer ignore-call */ count() === 0;
Loading history...
70
    }
71
72 1
    public function hasChanged(): bool
73
    {
74 1
        return $this->changed;
75
    }
76
77 1
    public function toArray(): array
78
    {
79 1
        return $this->container->getArrayCopy();
0 ignored issues
show
Bug introduced by
The method getArrayCopy() does not exist on ArrayAccess. It seems like you code against a sub-type of ArrayAccess such as PhpSpec\ObjectBehavior or PhpSpec\Wrapper\Subject or Laminas\Stdlib\ArrayObject or ArrayObject or ArrayIterator or Laminas\Session\Storage\ArrayStorage or Laminas\Stdlib\Parameters. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

79
        return $this->container->/** @scrutinizer ignore-call */ getArrayCopy();
Loading history...
80
    }
81
}
82