Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
ValueObjectToInt
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
3.14
0.00% covered (danger)
0.00%
0 / 1
 convert
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
3.14
1<?php
2namespace Apie\StorageMetadata\Converters;
3
4use Apie\Core\ValueObjects\Interfaces\ValueObjectInterface;
5use Apie\Core\ValueObjects\Utils;
6use Apie\TypeConverter\ConverterInterface;
7use ReflectionType;
8
9/**
10 * @implements ConverterInterface<ValueObjectInterface, int|null>
11 */
12class ValueObjectToInt implements ConverterInterface
13{
14    public function convert(ValueObjectInterface $input, ?ReflectionType $wantedType): ?int
15    {
16        $native = $input->toNative();
17        if (null === $native && $wantedType?->allowsNull()) {
18            return null;
19        }
20        return Utils::toInt($native);
21    }
22}