Completed
Push — master ( bf71a3...ce0169 )
by Nikolas
03:09
created

RangeField::inflate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4286
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
namespace rtens\domin\delivery\cli\fields;
3
4
use rtens\domin\Parameter;
5
use rtens\domin\reflection\types\RangeType;
6
7
class RangeField extends PrimitiveField {
8
9
    /**
10
     * @param Parameter $parameter
11
     * @return bool
12
     */
13
    public function handles(Parameter $parameter) {
14
        return $parameter->getType() instanceof RangeType;
15
    }
16
17
    /**
18
     * @param Parameter $parameter
19
     * @param string $serialized
20
     * @return mixed
21
     * @throws \Exception
22
     */
23
    public function inflate(Parameter $parameter, $serialized) {
24
        if (!$parameter->getType()->is(intval($serialized))) {
25
            throw new \Exception("[$serialized] is not in range " . $parameter->getType());
26
        }
27
28
        return (int)$serialized;
29
    }
30
}