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

FloatValue::value()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 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