Mcrouter::getSharedKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Inspirum\Mcrouter\Model\Values;
4
5
class Mcrouter
6
{
7
    /**
8
     * Prefix for shared cache (used in Mcrouter)
9
     *
10
     * @var string
11
     */
12
    public const SHARED_PREFIX = '/default/shr/';
13
14
    /**
15
     * Shared prefix for tags
16
     *
17
     * @var string
18
     */
19
    private $sharedPrefix;
20
21
    /**
22
     * Supported prefixes in Mcrouter
23
     *
24
     * @var array<string>
25
     */
26
    private $prefixes = [];
27
28
    /**
29
     * Mcrouter constructor
30
     *
31
     * @param string        $sharedPrefix
32
     * @param array<string> $supportedPrefixes
33
     */
34 27
    public function __construct(string $sharedPrefix, array $supportedPrefixes = [])
35
    {
36 27
        $this->sharedPrefix = $sharedPrefix;
37 27
        $this->prefixes     = array_filter(array_merge([$sharedPrefix], $supportedPrefixes));
38 27
    }
39
40
    /**
41
     * Get the cache prefixes.
42
     *
43
     * @return array<string>
44
     */
45 18
    public function getPrefixes(): array
46
    {
47 18
        return $this->prefixes;
48
    }
49
50
    /**
51
     * Get the cache key with Mcrouter shared prefix.
52
     *
53
     * @param string $key
54
     *
55
     * @return string
56
     */
57 10
    public function getSharedKey(string $key): string
58
    {
59 10
        return $this->sharedPrefix . $key;
60
    }
61
}
62