Total Complexity | 7 |
Total Lines | 44 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | final class CacheKeyBuilder |
||
10 | { |
||
11 | private string $namespace = ''; |
||
12 | |||
13 | private int $namespaceLength; |
||
14 | |||
15 | private function __construct(?string $namespace = null) |
||
16 | { |
||
17 | if ($namespace) { |
||
18 | $this->namespace = $namespace . ':'; |
||
19 | } |
||
20 | |||
21 | $this->namespaceLength = \mb_strlen($this->namespace); |
||
22 | } |
||
23 | |||
24 | public static function create(?string $namespace = null): self |
||
25 | { |
||
26 | return new self($namespace); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * @param mixed $key |
||
31 | * |
||
32 | * @return string |
||
33 | */ |
||
34 | public function buildKey($key): string |
||
35 | { |
||
36 | Assertions::assertValidKey($key); |
||
37 | return "{$this->namespace}{$key}"; |
||
38 | } |
||
39 | |||
40 | public function removeNamespace(string $key): string |
||
41 | { |
||
42 | return \mb_substr($key, $this->namespaceLength); |
||
43 | } |
||
44 | |||
45 | public function buildKeys(array $keys): array |
||
53 | } |
||
54 | } |
||
55 |