IntegerField   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
B validateCastValue() 0 15 5
A type() 0 4 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
        if (isset($this->descriptor()->bareNumber) && $this->descriptor()->bareNumber === false) {
17
            return mb_ereg_replace('((^\D*)|(\D*$))', '', $val);
18
        } elseif (!is_numeric($val)) {
19
            throw $this->getValidationException('value must be numeric', $val);
20
        } else {
21
            $intVal = (int) $val;
22
            if ($intVal != (float) $val) {
23
                throw $this->getValidationException('value must be an integer', $val);
24
            } else {
25
                return $intVal;
26
            }
27
        }
28
    }
29
30
    public static function type()
31
    {
32
        return 'integer';
33
    }
34
}
35