Completed
Push — master ( a293a3...292fca )
by X
02:23
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
 * handler for PHP serialized float number
4
 */
5
namespace xKerman\Restricted;
6
7
/**
8
 * Handler for PHP serialized float number
9
 */
10
class FloatHandler implements HandlerInterface
11
{
12
    /** @var array $mapping parser result mapping */
13
    private $mapping;
14
15
    /**
16
     * constructor
17
     */
18 107
    public function __construct()
19
    {
20 107
        $this->mapping = array(
21 107
            'INF'  => INF,
22 107
            '-INF' => -INF,
23 107
            'NAN'  => NAN,
24
        );
25 107
    }
26
27
    /**
28
     * parse given `$source` as PHP serialized float number
29
     *
30
     * @param Source $source parser input
31
     * @param string $args   float value
32
     * @return array
33
     * @throws UnserializeFailedException
34
     */
35 15
    public function handle(Source $source, $args)
36
    {
37 15
        if (array_key_exists($args, $this->mapping)) {
38 3
            return array($this->mapping[$args], $source);
39
        }
40 12
        return array(floatval($args), $source);
41
    }
42
}
43