Integer   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setCanEmpty() 0 5 1
A getCanEmpty() 0 4 1
B validate() 0 11 6
A getErrorMessage() 0 4 1
1
<?php
2
namespace FMUP\Import\Config\Field\Validator;
3
4
use FMUP\Import\Config\Field\Validator;
5
6
class Integer implements Validator
7
{
8
    private $empty;
9
10 3
    public function __construct($empty = false)
11
    {
12 3
        $this->setCanEmpty($empty);
13 3
    }
14
15 3
    public function setCanEmpty($empty = false)
16
    {
17 3
        $this->empty = (bool)$empty;
18 3
        return $this;
19
    }
20
21 2
    public function getCanEmpty()
22
    {
23 2
        return (bool)$this->empty;
24
    }
25
26 1
    public function validate($value)
27
    {
28 1
        if ($this->getCanEmpty() && $value == '') {
29 1
            return true;
30
        }
31 1
        if (is_float($value) && ((int)$value === 0)) {
32 1
            return false;
33
        }
34 1
        $valueTest = (int) $value;
35 1
        return ($valueTest === 0) ? is_numeric($value) : ($valueTest == $value);
36
    }
37
38 1
    public function getErrorMessage()
39
    {
40 1
        return "Le champ reçu n'est pas un nombre entier";
41
    }
42
}
43