Completed
Push — master ( f09269...1cbedf )
by Matthew
02:36
created

ZendSessionTokenStorage   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 26
ccs 11
cts 11
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A store() 0 3 1
A retrieve() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PublishingKit\Csrf;
6
7
use Zend\Session\Container;
8
9
final class ZendSessionTokenStorage implements TokenStorage
10
{
11
    /**
12
     * @var Container
13
     */
14
    private $session;
15
16 3
    public function __construct(Container $session)
17
    {
18 3
        $this->session = $session;
19 3
    }
20
21 3
    public function store(string $key, Token $token): void
22
    {
23 3
        $this->session->$key = $token->__toString();
24 3
    }
25
26 3
    public function retrieve(string $key): ?Token
27
    {
28 3
        $tokenValue = $this->session->$key;
29
30 3
        if ($tokenValue === null) {
31 3
            return null;
32
        }
33
34 3
        return new Token($tokenValue);
35
    }
36
}
37