KeyValueStorage   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 35
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 4 1
A set() 0 4 1
A has() 0 4 1
A remove() 0 4 1
A createKey() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Explicit Architecture POC,
7
 * which is created on top of the Symfony Demo application.
8
 *
9
 * (c) Herberto Graça <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Acme\App\Infrastructure\Persistence\Session;
16
17
use Acme\App\Core\Port\Persistence\KeyValueStorageInterface;
18
use Symfony\Component\HttpFoundation\Session\SessionInterface;
19
20
/**
21
 * @author Kasper Agg
22
 * @author Herberto Graca <[email protected]>
23
 */
24
final class KeyValueStorage implements KeyValueStorageInterface
25
{
26
    /** @var SessionInterface */
27
    private $session;
28
29
    public function __construct(SessionInterface $session)
30
    {
31
        $this->session = $session;
32
    }
33
34
    public function get(string $namespace, string $key): ?string
35
    {
36
        return $this->session->get($this->createKey($namespace, $key));
37
    }
38
39
    public function set(string $namespace, string $key, string $value): void
40
    {
41
        $this->session->set($this->createKey($namespace, $key), $value);
42
    }
43
44
    public function has(string $namespace, string $key): bool
45
    {
46
        return $this->session->has($this->createKey($namespace, $key));
47
    }
48
49
    public function remove(string $namespace, string $key): void
50
    {
51
        $this->session->remove($this->createKey($namespace, $key));
52
    }
53
54
    private function createKey(string $namespace, string $key): string
55
    {
56
        return sprintf('%s_%s', $namespace, $key);
57
    }
58
}
59