Completed
Push — master ( 63117e...c0048b )
by Sebastian
02:30
created

Number::sanitize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 0
cts 7
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Linna Filter
5
 *
6
 * @author Sebastian Rapetti <[email protected]>
7
 * @copyright (c) 2017, Sebastian Rapetti
8
 * @license http://opensource.org/licenses/MIT MIT License
9
 */
10
declare(strict_types = 1);
11
12
namespace Linna\Filter\Rules;
13
14
/**
15
 * Check required.
16
 */
17
class Number
18
{
19
    /**
20
     * Validate.
21
     *
22
     * @return bool
23
     */
24
    public function validate($received): bool
25
    {
26
        if (is_numeric($received)) {
27
            return false;
28
        }
29
30
        return true;
31
    }
32
    
33
    /**
34
     * Sanitize.
35
     *
36
     * @param mixed $value
37
     */
38
    public function sanitize(&$value)
39
    {
40
        if (fmod((float) $value, 1.0) === 0.0) {
41
            settype($value, 'integer');
42
            return;
43
        }
44
45
        settype($value, 'float');
46
    }
47
}
48