Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
ReflectionTypeToReflectionClassConverter
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
4.13
0.00% covered (danger)
0.00%
0 / 1
 convert
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
4.13
1<?php
2namespace Apie\Core\TypeConverters;
3
4use Apie\TypeConverter\ConverterInterface;
5use Apie\TypeConverter\Exceptions\CanNotConvertObjectException;
6use Apie\TypeConverter\ReflectionTypeFactory;
7use ReflectionClass;
8use ReflectionNamedType;
9use ReflectionType;
10
11/**
12 * @implements ConverterInterface<ReflectionType, ReflectionClass|null>
13 */
14class ReflectionTypeToReflectionClassConverter implements ConverterInterface
15{
16    /**
17     * @return ReflectionClass<object>|null
18     */
19    public function convert(ReflectionNamedType $input, ?ReflectionType $wantedType = null): ?ReflectionClass
20    {
21        if (!$input->isBuiltin()) {
22            return new ReflectionClass($input->getName());
23        }
24        if (!$wantedType || !$wantedType->allowsNull()) {
25            throw new CanNotConvertObjectException($input, $wantedType ?? ReflectionTypeFactory::createReflectionType('mixed'));
26        }
27
28        return null;
29    }
30}