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

Number   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 7 2
A sanitize() 0 8 2
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