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

ScalarKeyStrategy::getEntityPrefix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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