Completed
Push — master ( eaf770...e2d746 )
by Sebastian
04:09
created

Number   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 37
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMessage() 0 3 1
A validate() 0 8 2
1
<?php
2
3
/**
4
 * Linna Filter
5
 *
6
 * @author Sebastian Rapetti <[email protected]>
7
 * @copyright (c) 2018, 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 if provided value is a number.
16
 */
17
class Number extends AbstractNumber implements RuleSanitizeInterface
18
{
19
    /**
20
     * @var array Arguments expected.
21
     */
22
    private $arguments = [];
0 ignored issues
show
introduced by
The private property $arguments is not used, and could be removed.
Loading history...
23
24
    /**
25
     * @var string Error message
26
     */
27
    private $message = '';
28
29
    /**
30
     * Validate.
31
     *
32
     * @param int|float $received
33
     *
34
     * @return bool
35
     */
36 19
    public function validate($received): bool
37
    {
38 19
        if (!is_numeric($received)) {
0 ignored issues
show
introduced by
The condition is_numeric($received) is always true.
Loading history...
39 9
            $this->message = "Received value is not a number";
40 9
            return true;
41
        }
42
43 10
        return false;
44
    }
45
46
    /**
47
     * Return error message.
48
     *
49
     * @return string Error message
50
     */
51 1
    public function getMessage(): string
52
    {
53 1
        return $this->message;
54
    }
55
}
56