Passed
Push — master ( 5f4fe5...4b34bb )
by Lee
10:35
created

Integer::isValid()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 12
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 21
rs 9.8666
1
<?php
2
3
namespace Lavibi\Popoya;
4
5
class Integer extends AbstractValidator
6
{
7
    const NOT_INTEGER = 'not_integer';
8
    const NOT_INTEGER_MESSAGE = 'The given value must be integer.';
9
10
    protected $messages = [
11
        self::NOT_INTEGER => self::NOT_INTEGER_MESSAGE
12
    ];
13
14
    public function isValid($value): bool
15
    {
16
        var_dump($value);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($value) looks like debug code. Are you sure you do not want to remove it?
Loading history...
17
        $this->value = $this->standardValue = $value;
18
19
        if (is_string($value)) {
20
            if (!preg_match('/^[1-9][0-9]*$|^0$/', $value)) {
21
                $this->setError(static::NOT_INTEGER);
22
                return false;
23
            }
24
25
            $this->standardValue = (int) $value;
26
            return true;
27
        }
28
29
        if (is_int($value)) {
30
            return true;
31
        }
32
33
        $this->setError(self::NOT_INTEGER);
34
        return false;
35
    }
36
}
37