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

NumberField   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 27
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validateCastValue() 0 9 2
A type() 0 4 1
A isEmptyValue() 0 4 2
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
}