Completed
Push — master ( 813469...d9bcbf )
by Travis
02:04
created

FloatBase::max()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
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
    /**
9
     * @var float
10
     */
11
    private $min = PHP_FLOAT_MIN;
12
13
    /**
14
     * @var float
15
     */
16
    private $max = PHP_FLOAT_MAX;
17
18
    public function between(float $min, float $max): self
19
    {
20
        $this->min = $min;
21
        $this->max = $max;
22
23
        return $this;
24
    }
25
26
    public function min(float $min): self
27
    {
28
        $this->min = $min;
29
30
        return $this;
31
    }
32
33
    public function max(float $max): self
34
    {
35
        $this->max = $max;
36
37
        return $this;
38
    }
39
40
    protected function validation($input, &$value): bool
41
    {
42
        if (\is_bool($input)) {
43
            return false;
44
        }
45
46
        $return = filter_var($input, FILTER_VALIDATE_FLOAT);
47
        if ($return === false) {
48
            return false;
49
        }
50
51
        if ($return < $this->min || $return > $this->max) {
52
            return false;
53
        }
54
55
        $value = $return;
56
57
        return true;
58
    }
59
}
60