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

Sha1KeyStrategy   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 27
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getKey() 0 11 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