FloatGuard::value()   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 0
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;
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 11
    public function __construct($input, ?float $default = null)
23
    {
24 11
        $this->input = $input;
25 11
        $this->value = $default;
26 11
    }
27
28 8
    public function value(): ?float
29
    {
30 8
        $this->success();
31
32 8
        return $this->value;
33
    }
34
}
35