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

IntegerField   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 26
rs 10

2 Methods

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