Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| PhpDateTimeObjectFaker | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| supports | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| fakeFor | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | namespace Apie\Faker\Fakers; |
| 3 | |
| 4 | use Apie\Faker\Interfaces\ApieClassFaker; |
| 5 | use DateTime; |
| 6 | use DateTimeInterface; |
| 7 | use Faker\Generator; |
| 8 | use ReflectionClass; |
| 9 | |
| 10 | /** @implements ApieClassFaker<DateTimeInterface> */ |
| 11 | class PhpDateTimeObjectFaker implements ApieClassFaker |
| 12 | { |
| 13 | public function supports(ReflectionClass $class): bool |
| 14 | { |
| 15 | return $class->implementsInterface(DateTimeInterface::class); |
| 16 | } |
| 17 | |
| 18 | public function fakeFor(Generator $generator, ReflectionClass $class): DateTimeInterface |
| 19 | { |
| 20 | $className = $class->name; |
| 21 | return match ($className) { |
| 22 | DateTimeInterface::class => new DateTime('@' . $generator->unixTime()), |
| 23 | default => new $className('@' . $generator->unixTime()), |
| 24 | }; |
| 25 | } |
| 26 | } |