Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ValueObjectToInt
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 convert
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
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}