NumericField   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDocumentFieldValue() 0 14 3
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
}