Completed
Pull Request — master (#46)
by Klaus
09:50
created

AbstractAdapter   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 0
loc 63
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Linio\Component\Cache\Adapter;
6
7
abstract class AbstractAdapter
8
{
9
    protected string $namespace = '';
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
10
    protected bool $cacheNotFoundKeys = false;
11
12
    public function cacheNotFoundKeys(): bool
13
    {
14
        return $this->cacheNotFoundKeys;
15
    }
16
17
    protected function addNamespaceToKey(string $key): string
18
    {
19
        return $this->namespace . ':' . $key;
20
    }
21
22
    protected function addNamespaceToKeys(array $keys, bool $isKeyValue = false): array
23
    {
24
        $namespacedKeys = [];
25
26
        foreach ($keys as $key => $value) {
27
            if ($isKeyValue) {
28
                $namespacedKeys[$this->addNamespaceToKey($key)] = $value;
29
            } else {
30
                $namespacedKeys[$key] = $this->addNamespaceToKey($value);
31
            }
32
        }
33
34
        return $namespacedKeys;
35
    }
36
37
    protected function removeNamespaceFromKey(string $key): string
38
    {
39
        return substr($key, strlen($this->namespace) + 1);
40
    }
41
42
    protected function removeNamespaceFromKeys(array $keys): array
43
    {
44
        $nonNamespacedKeys = [];
45
46
        foreach ($keys as $key => $value) {
47
            $nonNamespacedKeys[$this->removeNamespaceFromKey($key)] = $value;
48
        }
49
50
        return $nonNamespacedKeys;
51
    }
52
53
    public function getNamespace(): string
54
    {
55
        return $this->namespace;
56
    }
57
58
    public function setNamespace(string $namespace): void
59
    {
60
        $this->namespace = $namespace;
61
    }
62
}
63