FloatBase::min()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace InputGuard\Guards\Bases;
5
6
trait FloatBase
7
{
8
    use Strict;
9
10
    /**
11
     * @var float
12
     */
13
    private $min = PHP_FLOAT_MIN;
14
15
    /**
16
     * @var float
17
     */
18
    private $max = PHP_FLOAT_MAX;
19
20 5
    public function between(float $min, float $max): self
21
    {
22 5
        $this->min = $min;
23 5
        $this->max = $max;
24
25 5
        return $this;
26
    }
27
28 12
    public function min(float $min): self
29
    {
30 12
        $this->min = $min;
31
32 12
        return $this;
33
    }
34
35 11
    public function max(float $max): self
36
    {
37 11
        $this->max = $max;
38
39 11
        return $this;
40
    }
41
42 28
    protected function validation($input, &$value): bool
43
    {
44 28
        if (\is_bool($input)) {
45 2
            return false;
46
        }
47
48 26
        if ($this->strict) {
49 2
            $return = \is_float($input) ? $input : false;
0 ignored issues
show
Coding Style introduced by
Inline IF statements are not allowed
Loading history...
50
        } else {
51 24
            $return = filter_var($input, FILTER_VALIDATE_FLOAT);
52
        }
53
54 26
        if ($return === false) {
55 6
            return false;
56
        }
57
58 20
        if ($return < $this->min || $return > $this->max) {
59 4
            return false;
60
        }
61
62 17
        $value = $return;
63
64 17
        return true;
65
    }
66
}
67