NumericField::getDocumentFieldValue()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 2
nop 1
1
<?php
2
3
namespace Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity;
4
5
use Mdiyakov\DoctrineSolrBundle\Exception\InvalidFieldValueException;
6
7
abstract class NumericField extends Field
8
{
9
10
    /**
11
     * @param object $entity
12
     * @return mixed
13
     * @throws InvalidFieldValueException
14
     */
15
    public function getDocumentFieldValue($entity)
16
    {
17
        $value = $this->getEntityFieldValue($entity);
18
        if (!empty($value) && !is_numeric($value)) {
19
            throw new InvalidFieldValueException(
20
                sprintf(
21
                    '"%s" field value of "%s" must be a numeric',
22
                    $this->getEntityFieldName(),
23
                    get_class($entity)
24
                )
25
            );
26
        }
27
28
        return $this->castValue($value);
29
    }
30
31
    abstract protected function castValue($value);
32
}