Completed
Pull Request — master (#14)
by Pavel
04:42
created

Sha1Strategy   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 35
c 0
b 0
f 0
wmc 3
lcom 2
cbo 2
ccs 0
cts 14
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getEntityPrefix() 0 4 1
A getEntityKey() 0 6 1
1
<?php
2
3
namespace Bankiru\Api\Doctrine\Cache;
4
5
use Bankiru\Api\Doctrine\Mapping\ApiMetadata;
6
use Bankiru\Api\Doctrine\Utility\IdentifierFlattener;
7
8
final class Sha1Strategy implements KeyStrategyInterface
9
{
10
    /** @var  IdentifierFlattener */
11
    private $flattener;
12
    /**
13
     * @var string
14
     */
15
    private $prefix;
16
17
    /**
18
     * Sha1Strategy constructor.
19
     *
20
     * @param IdentifierFlattener $flattener
21
     * @param string              $prefix
22
     */
23
    public function __construct(IdentifierFlattener $flattener, $prefix = '')
24
    {
25
        $this->flattener = $flattener;
26
        $this->prefix    = (string)$prefix;
27
    }
28
29
    /** {@inheritdoc} */
30
    public function getEntityPrefix(ApiMetadata $metadata)
31
    {
32
        return $this->prefix;
33
    }
34
35
    /** {@inheritdoc} */
36
    public function getEntityKey(ApiMetadata $metadata, array $identifier)
37
    {
38
        $flattenIdentifiers = $this->flattener->flattenIdentifier($metadata, $identifier);
39
40
        return sha1(sprintf('%s %s', $metadata->getName(), implode(' ', $flattenIdentifiers)));
41
    }
42
}
43