ToBoolean::hydrate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 7
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
/**
10
 * Transform a value into a php native boolean
11
 *
12
 * @returns float
13
 */
14
class ToBoolean extends Collection implements
15
    StrategyInterface
16
{
17
    public function extract(mixed $value, object|null $object = null): bool|null
18
    {
19
        if ($value === null) {
20
            // @codeCoverageIgnoreStart
21
            return $value;
22
            // @codeCoverageIgnoreEnd
23
        }
24
25
        return (bool) $value;
26
    }
27
28
    /**
29
     * @param mixed[]|null $data
30
     *
31
     * @codeCoverageIgnore
32
     */
33
    public function hydrate(mixed $value, array|null $data): bool|null
34
    {
35
        if ($value === null) {
36
            return $value;
37
        }
38
39
        return (bool) $value;
40
    }
41
}
42