Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| IntToAutoincrementIntegerConverter | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
56 | |
0.00% |
0 / 1 |
| convert | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
56 | |||
| 1 | <?php |
| 2 | namespace Apie\Core\TypeConverters; |
| 3 | |
| 4 | use Apie\Core\Identifiers\AutoIncrementInteger; |
| 5 | use Apie\TypeConverter\ConverterInterface; |
| 6 | use Apie\TypeConverter\TypeConverter; |
| 7 | use ReflectionClass; |
| 8 | use ReflectionNamedType; |
| 9 | use ReflectionType; |
| 10 | use ReflectionUnionType; |
| 11 | |
| 12 | /** |
| 13 | * @implements ConverterInterface<int, AutoIncrementInteger> |
| 14 | */ |
| 15 | class IntToAutoincrementIntegerConverter implements ConverterInterface |
| 16 | { |
| 17 | public function convert(int $integer, ReflectionType $wantedType, TypeConverter $typeConverter): AutoIncrementInteger |
| 18 | { |
| 19 | $class = AutoIncrementInteger::class; |
| 20 | if ($wantedType instanceof ReflectionNamedType) { |
| 21 | $class = $wantedType->getName(); |
| 22 | } elseif ($wantedType instanceof ReflectionUnionType) { |
| 23 | foreach ($wantedType->getTypes() as $subType) { |
| 24 | if ($subType instanceof ReflectionNamedType) { |
| 25 | $classToCheck = $typeConverter->convertTo($subType, ReflectionClass::class); |
| 26 | if ($classToCheck instanceof ReflectionClass && $classToCheck->implementsInterface(AutoincrementInteger::class)) { |
| 27 | $class = $classToCheck->name; |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | return $class::fromNative($integer); |
| 33 | } |
| 34 | } |