Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
StringToDateTime
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 1
 convert
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2namespace Apie\StorageMetadata\Converters;
3
4use Apie\Core\Utils\ConverterUtils;
5use Apie\TypeConverter\ConverterInterface;
6use DateTime;
7use DateTimeInterface;
8use ReflectionType;
9
10/**
11 * @implements ConverterInterface<string, DateTimeInterface>
12 */
13class StringToDateTime implements ConverterInterface
14{
15    public function convert(string $input, ?ReflectionType $wantedType): ?DateTimeInterface
16    {
17        $class = ConverterUtils::toReflectionClass($wantedType);
18        assert(null !== $class);
19        $className = $class->name;
20        return match ($className) {
21            DateTimeInterface::class => new DateTime($input),
22            default => new $className($input),
23        };
24    }
25}