Completed
Push — master ( a293a3...292fca )
by X
02:23
created

FloatHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A handle() 0 7 2
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