Passed
Pull Request — master (#14)
by Pavel
05:12
created

ScalarKeyStrategy::getEntityKey()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
ccs 5
cts 6
cp 0.8333
rs 9.4285
cc 3
eloc 5
nc 3
nop 2
crap 3.0416
1
<?php
2
3
namespace Bankiru\Api\Doctrine\Cache;
4
5
use Bankiru\Api\Doctrine\Mapping\ApiMetadata;
6
7
final class ScalarKeyStrategy implements KeyStrategyInterface
8
{
9
    /** {@inheritdoc} */
10 1
    public function getEntityPrefix(ApiMetadata $metadata)
11
    {
12 1
        return str_replace('\\', '__', $metadata->getName());
13
    }
14
15
    /** {@inheritdoc} */
16 1
    public function getEntityKey(ApiMetadata $metadata, array $identifier)
17
    {
18 1
        foreach ($metadata->getIdentifierFieldNames() as $name) {
19 1
            if ($metadata->hasAssociation($name)) {
20
                throw new \LogicException('Invalid strategy for relation-based identifier');
21
            }
22 1
        }
23
24 1
        return $this->getEntityPrefix($metadata) . '_' . sha1(json_encode($identifier));
25
    }
26
}
27