Sha1KeyStrategy::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace ScayTrase\Api\Rpc\Decorators;
4
5
use ScayTrase\Api\Rpc\RpcRequestInterface;
6
7
/** @internal */
8
final class Sha1KeyStrategy implements CacheKeyStrategyInterface
9
{
10
    /** @var string */
11
    private $keyPrefix;
12
13
    /**
14
     * Sha1KeyStrategy constructor.
15
     *
16
     * @param string $keyPrefix
17
     */
18 3
    public function __construct($keyPrefix)
19
    {
20 3
        $this->keyPrefix = $keyPrefix;
21 3
    }
22
23 3
    public function getKey(RpcRequestInterface $request)
24
    {
25
        $data = [
26 3
            'method' => (string)$request->getMethod(),
27 3
            'params' => json_decode(json_encode($request->getParameters()), true),
28 3
        ];
29
30 3
        $stringData = json_encode($data);
31
32 3
        return $this->keyPrefix.sha1($stringData);
33
    }
34
}
35