ToFloat::extract()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApiSkeletons\Doctrine\ORM\GraphQL\Hydrator\Strategy;
6
7
use Laminas\Hydrator\Strategy\StrategyInterface;
8
9
use function floatval;
10
11
/**
12
 * Transform a number value into a php native float
13
 *
14
 * @returns float
15
 */
16
class ToFloat extends Collection implements
17
    StrategyInterface
18
{
19
    /** @param mixed|null $object */
20
    public function extract(mixed $value, object|null $object = null): mixed
21
    {
22
        if ($value === null) {
23
            // @codeCoverageIgnoreStart
24
            return $value;
25
            // @codeCoverageIgnoreEnd
26
        }
27
28
        return floatval($value);
29
    }
30
31
    /**
32
     * @param mixed[]|null $data
33
     *
34
     * @codeCoverageIgnore
35
     */
36
    public function hydrate(mixed $value, array|null $data): mixed
37
    {
38
        if ($value === null) {
39
            return $value;
40
        }
41
42
        return floatval($value);
43
    }
44
}
45