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

IntegerField::type()   A

Complexity

Conditions 1
Paths 1

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 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace frictionlessdata\tableschema\Fields;
3
4
class IntegerField extends BaseField
5
{
6
    /**
7
     * @param mixed $val
8
     * @return integer
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
            $intVal = (integer)$val;
17
            if ($intVal != (float)$val) {
18
                throw $this->getValidationException("value must be an integer", $val);
19
            } else {
20
                return $intVal;
21
            }
22
        }
23
    }
24
25
    public static function type()
26
    {
27
        return "integer";
28
    }
29
}