Completed
Pull Request — master (#43)
by X
04:25
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
 * 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