Completed
Pull Request — master (#14)
by Pavel
03:40
created

ScalarKeyStrategy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
dl 0
loc 20
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1
ccs 7
cts 8
cp 0.875
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntityPrefix() 0 4 1
A getEntityKey() 0 10 3
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 $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) . '_' . json_encode($identifier);
25
    }
26
}
27