Completed
Push — master ( 29cde4...77c4c6 )
by Ori
03:02
created

NumberField::isEmptyValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 1
1
<?php
2
namespace frictionlessdata\tableschema\Fields;
3
4
class NumberField extends BaseField
5
{
6
    /**
7
     * @param mixed $val
8
     * @return float
9
     * @throws \frictionlessdata\tableschema\Exceptions\FieldValidationException;
10
     */
11
    public function validateCastValue($val)
12
    {
13
        $val = parent::validateCastValue($val);
14
        if (!is_numeric($val)) {
15
            throw $this->getValidationException("value must be numeric", $val);
16
        } else {
17
            return (float)$val;
18
        }
19
    }
20
21
    public static function type()
22
    {
23
        return "number";
24
    }
25
26
    protected function isEmptyValue($val)
27
    {
28
        return (!is_numeric($val) && empty($val));
29
    }
30
}