Completed
Pull Request — master (#43)
by X
04:25
created

FloatHandler::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * parser for PHP serialized float number
4
 */
5
namespace xKerman\Restricted;
6
7
/**
8
 * Parser for PHP serialized float number
9
 *
10
 * format: http://php.net/manual/en/language.types.float.php
11
 */
12
class FloatHandler implements HandlerInterface
13
{
14
    /** @var array $mapping parser result mapping */
15
    private $mapping;
16
17
    /**
18
     * constructor
19
     */
20 107
    public function __construct()
21
    {
22 107
        $this->mapping = array(
23 107
            'INF'  => INF,
24 107
            '-INF' => -INF,
25 107
            'NAN'  => NAN,
26
        );
27 107
    }
28
29
    /**
30
     * parse given `$source` as PHP serialized float number
31
     *
32
     * @param Source $source parser input
33
     * @param string $args   submatched
34
     * @return array
35
     * @throws UnserializeFailedException
36
     */
37 15
    public function handle(Source $source, $args)
38
    {
39 15
        if (array_key_exists($args, $this->mapping)) {
40 3
            return array($this->mapping[$args], $source);
41
        }
42 12
        return array(floatval($args), $source);
43
    }
44
}
45