Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ReflectionUnionTypeToReflectionClassConverter
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 convert
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2namespace Apie\Core\TypeConverters;
3
4use Apie\TypeConverter\ConverterInterface;
5use Apie\TypeConverter\TypeConverter;
6use ReflectionClass;
7use ReflectionType;
8use ReflectionUnionType;
9
10/**
11 * @implements ConverterInterface<ReflectionUnionType, ReflectionClass|null>
12 */
13class ReflectionUnionTypeToReflectionClassConverter implements ConverterInterface
14{
15    /**
16     * @return ReflectionClass<object>|null
17     */
18    public function convert(ReflectionUnionType $input, ?ReflectionType $wantedType = null, ?TypeConverter $typeConverter = null): ?ReflectionClass
19    {
20        assert($typeConverter !== null);
21        foreach ($input->getTypes() as $type) {
22            $class = $typeConverter->convertTo($type, $wantedType);
23            if ($class) {
24                return $class;
25            }
26        }
27
28        return null;
29    }
30}