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

NumberField   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 21
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateValue() 0 8 2
A type() 0 4 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
}