Completed
Push — master ( fbe049...cd378b )
by Ori
07:11
created

IntegerField::isEmptyValue()   A

Complexity

Conditions 2
Paths 2

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 2
eloc 2
nc 2
nop 1
1
<?php
2
3
namespace frictionlessdata\tableschema\Fields;
4
5
class IntegerField extends BaseField
6
{
7
    /**
8
     * @param mixed $val
9
     *
10
     * @return int
11
     *
12
     * @throws \frictionlessdata\tableschema\Exceptions\FieldValidationException;
13
     */
14
    protected function validateCastValue($val)
15
    {
16 View Code Duplication
        if (!is_numeric($val)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
            throw $this->getValidationException('value must be numeric', $val);
18
        } else {
19
            $intVal = (int) $val;
20
            if ($intVal != (float) $val) {
21
                throw $this->getValidationException('value must be an integer', $val);
22
            } else {
23
                return $intVal;
24
            }
25
        }
26
    }
27
28
    public static function type()
29
    {
30
        return 'integer';
31
    }
32
}
33