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

ToInteger::__invoke()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 12
loc 12
ccs 6
cts 6
cp 1
rs 9.2
cc 4
eloc 6
nc 4
nop 1
crap 4
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 ToInteger implements UnaryFunction
14
{
15
    /** @var int */
16
    private $default;
17
18
    /**
19
     * ToInteger constructor.
20
     *
21
     * @param int $default
22
     */
23 29
    public function __construct($default = 0)
24
    {
25 29
        $this->default = (int) $default;
26 29
    }
27
28
    /**
29
     * @param mixed $input
30
     *
31
     * @return int
32
     */
33 31
    public function __invoke($input)
34
    {
35 31
        if (is_object($input) && method_exists($input, '__toString')) {
36 3
            $input = (string) $input;
37
        }
38
39 31
        if (is_numeric($input)) {
40 16
            return (int) (0 + $input);
41
        }
42
43 15
        return $this->default;
44
    }
45
}
46