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

RangeField   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 24
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handles() 0 3 1
A inflate() 0 7 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
}