Completed
Push — master ( b10a48...29cde4 )
by Ori
05:27
created

NumberField::validateValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
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 validateValue($val)
12
    {
13
        if (!is_numeric($val)) {
14
            throw $this->getValidationException("value must be numeric", $val);
15
        } else {
16
            return (float)$val;
17
        }
18
    }
19
20
    public static function type()
21
    {
22
        return "number";
23
    }
24
}