Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
ReflectionUnionTypeToReflectionClassConverter | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
convert | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | namespace Apie\Core\TypeConverters; |
3 | |
4 | use Apie\TypeConverter\ConverterInterface; |
5 | use Apie\TypeConverter\TypeConverter; |
6 | use ReflectionClass; |
7 | use ReflectionType; |
8 | use ReflectionUnionType; |
9 | |
10 | /** |
11 | * @implements ConverterInterface<ReflectionUnionType, ReflectionClass|null> |
12 | */ |
13 | class 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 | } |