Completed
Push — master ( a7afc7...f7865d )
by Karsten
08:02
created

ToFloat::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Created by gerk on 20.11.17 17:34
4
 */
5
6
namespace PeekAndPoke\Component\Psi\Psi\Map;
7
8
use PeekAndPoke\Component\Psi\UnaryFunction;
9
10
/**
11
 * @author Karsten J. Gerber <[email protected]>
12
 */
13 View Code Duplication
class ToFloat implements UnaryFunction
14
{
15
    /** @var float */
16
    private $default;
17
18
    /**
19
     * @param float $default
20
     */
21 27
    public function __construct($default = 0.0)
22
    {
23 27
        $this->default  = (float) $default;
24 27
    }
25
26
    /**
27
     * @param mixed $input
28
     *
29
     * @return float
30
     */
31 27
    public function __invoke($input)
32
    {
33 27
        if (is_object($input) && method_exists($input, '__toString')) {
34 3
            $input = (string) $input;
35
        }
36
37 27
        if (is_numeric($input)) {
38 12
            return (float) (0 + $input);
39
        }
40
41 15
        return $this->default;
42
    }
43
}
44