ToInteger::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 intval;
10
11
/**
12
 * Transform a number value into a php native integer
13
 *
14
 * @returns integer
15
 */
16
class ToInteger extends Collection implements
17
    StrategyInterface
18
{
19
    public function extract(mixed $value, object|null $object = null): mixed
20
    {
21
        if ($value === null) {
22
            // @codeCoverageIgnoreStart
23
            return $value;
24
            // @codeCoverageIgnoreEnd
25
        }
26
27
        return intval($value);
28
    }
29
30
    /**
31
     * @param mixed[]|null $data
32
     *
33
     * @codeCoverageIgnore
34
     */
35
    public function hydrate(mixed $value, array|null $data): mixed
36
    {
37
        if ($value === null) {
38
            return $value;
39
        }
40
41
        return intval($value);
42
    }
43
}
44