Passed
Branch master (f61680)
by Pavel
02:38
created

Sha1KeyStrategy::__construct()   A

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 1
    public function __construct($keyPrefix)
19
    {
20 1
        $this->keyPrefix = $keyPrefix;
21 1
    }
22
23 1
    public function getKey(RpcRequestInterface $request)
24
    {
25
        $data = [
26 1
            'method' => (string)$request->getMethod(),
27 1
            'params' => json_decode(json_encode($request->getParameters()), true),
28 1
        ];
29
30 1
        $stringData = json_encode($data);
31
32 1
        return $this->keyPrefix.sha1($stringData);
33
    }
34
}
35