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

FloatGuard   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 17
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A value() 0 5 1
A __construct() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace InputGuard\Guards;
5
6
use InputGuard\Guards\Bases\FloatBase;
7
use InputGuard\Guards\Bases\SingleInput;
8
9
/**
10
 * This validates floating point numbers.
11
 *
12
 * Please be aware that it currently does not handle very large and very small numbers well. Additional research into
13
 * PHP's handling of floating point handling needs to be done. It turns out that floating points for all computers are
14
 * hard. Who knew?
15
 */
16
class FloatGuard implements Guard
17
{
18
    use ErrorMessagesBase;
19
    use FloatBase;
20
    use SingleInput;
21
22
    public function __construct($input, ?float $default = null)
23
    {
24
        $this->input = $input;
25
        $this->value = $default;
26
    }
27
28
    public function value(): ?float
29
    {
30
        $this->success();
31
32
        return $this->value;
33
    }
34
}
35