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