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

IntegerField::validateValue()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 3
eloc 9
nc 3
nop 1
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
}