Field::isPrimaryKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity;
4
5
use Mdiyakov\DoctrineSolrBundle\Exception\InvalidFieldValueException;
6
use Mdiyakov\DoctrineSolrBundle\Schema\Field\DocumentFieldInterface;
7
use Symfony\Component\PropertyAccess\PropertyAccess;
8
9
abstract class Field implements DocumentFieldInterface
10
{
11
    /**
12
     * @var bool
13
     */
14
    private $primaryKey = false;
15
16
    /**
17
     * @var string
18
     */
19
    private $entityFieldName;
20
21
    /**
22
     * @var string
23
     */
24
    private $documentFieldName;
25
26
    /**
27
     * @var int
28
     */
29
    private $priority;
30
31
    /**
32
     * @var string
33
     */
34
    private $suggester;
35
36
    /**
37
     * @param string $entityFieldName
38
     * @param string $documentFieldName
39
     * @param bool $primaryKey
40
     * @param int $priority
41
     * @param string $suggester
42
     */
43
    public function __construct(
44
        $entityFieldName,
45
        $documentFieldName,
46
        $primaryKey,
47
        $priority,
48
        $suggester
49
        )
50
    {
51
        $this->entityFieldName = $entityFieldName;
52
        $this->documentFieldName = $documentFieldName;
53
        $this->primaryKey = $primaryKey;
54
        $this->priority = (int) $priority;
55
        $this->suggester = $suggester;
56
    }
57
58
    /**
59
     * @param object $entity
60
     * @return mixed
61
     */
62
    abstract public function getDocumentFieldValue($entity);
63
64
    /**
65
     * @return string
66
     */
67
    public function getEntityFieldName()
68
    {
69
        return $this->entityFieldName;
70
    }
71
72
    /**
73
     * @return string
74
     */
75
    public function getDocumentFieldName()
76
    {
77
        return $this->documentFieldName;
78
    }
79
80
    /**
81
     * @return boolean
82
     */
83
    public function isPrimaryKey()
84
    {
85
        return $this->primaryKey;
86
    }
87
88
    /**
89
     * @return int
90
     */
91
    public function getPriority()
92
    {
93
        return $this->priority;
94
    }
95
96
    /**
97
     * @param object $entity
98
     * @return mixed
99
     * @throws InvalidFieldValueException
100
     */
101
    public function getEntityFieldValue($entity)
102
    {
103
        if (!is_object($entity)) {
104
            throw new InvalidFieldValueException('Argument must be an object');
105
        }
106
107
        return PropertyAccess::createPropertyAccessor()->getValue($entity, $this->getEntityFieldName());
108
    }
109
110
    /**
111
     * @return string
112
     */
113
    public function getSuggester()
114
    {
115
        return $this->suggester;
116
    }
117
}