DocumentUniqueField   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 44
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A __construct() 0 4 1
A getValue() 0 9 1
1
<?php
2
3
namespace Mdiyakov\DoctrineSolrBundle\Schema\Field;
4
5
use Mdiyakov\DoctrineSolrBundle\Schema\Schema;
6
7
class DocumentUniqueField
8
{
9
    /**
10
     * @var string
11
     */
12
    private $name;
13
14
    /**
15
     * @var
16
     */
17
    private $schema;
18
19
    /**
20
     * @param $documentUniqueFieldConfig
21
     * @param Schema $schema
22
     */
23
    public function __construct($documentUniqueFieldConfig, Schema $schema)
24
    {
25
        $this->name = $documentUniqueFieldConfig['name'];
26
        $this->schema = $schema;
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    public function getName()
33
    {
34
        return $this->name;
35
    }
36
37
    /**
38
     * @param object $entity
39
     * @param array $entityConfig
40
     * @return mixed
41
     */
42
    public function getValue($entity, $entityConfig)
43
    {
44
        $entityPrimaryKeyField = $this->schema->getEntityPrimaryKeyField();
45
        $discriminatorConfigField = $this->schema->getDiscriminatorConfigField();
46
47
        return sprintf(
48
            '%s-%s',
49
            $discriminatorConfigField->getValue($entityConfig),
50
            $entityPrimaryKeyField->getEntityFieldValue($entity)
51
        );
52
    }
53
}