Completed
Push — master ( 05aed6...998c1c )
by Jesse
05:22
created

FloatValue   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 4
dl 0
loc 10
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A value() 0 7 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\Hydration\Mapping\Property\Type;
5
6
use function is_numeric;
7
use Stratadox\Hydration\Mapping\Property\UnmappableProperty;
8
9
/**
10
 * Maps numeric input to a float property in an object property.
11
 *
12
 * @package Stratadox\Hydrate
13
 * @author  Stratadox
14
 */
15
final class FloatValue extends ScalarValue
16
{
17
    /** @inheritdoc */
18
    public function value(array $data, $owner = null): float
19
    {
20
        $value = $this->my($data);
21
        if (!is_numeric($value)) {
22
            throw UnmappableProperty::itMustBeNumeric($this, $value);
23
        }
24
        return (float) $value;
25
    }
26
}
27