Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| StringToValueObject | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| convert | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\StorageMetadata\Converters; |
| 3 | |
| 4 | use Apie\Core\Utils\ConverterUtils; |
| 5 | use Apie\Core\ValueObjects\Interfaces\ValueObjectInterface; |
| 6 | use Apie\TypeConverter\ConverterInterface; |
| 7 | use ReflectionType; |
| 8 | |
| 9 | /** |
| 10 | * @implements ConverterInterface<string|null, ValueObjectInterface> |
| 11 | */ |
| 12 | class StringToValueObject implements ConverterInterface |
| 13 | { |
| 14 | public function convert(?string $input, ?ReflectionType $wantedType): ValueObjectInterface |
| 15 | { |
| 16 | $class = ConverterUtils::toReflectionClass($wantedType); |
| 17 | assert(null !== $class); |
| 18 | $className = $class->name; |
| 19 | // @phpstan-ignore-next-line |
| 20 | return $className::fromNative($input); |
| 21 | } |
| 22 | } |