Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
PhpDateTimeObjectFaker
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 supports
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 fakeFor
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2namespace Apie\Faker\Fakers;
3
4use Apie\Faker\Interfaces\ApieClassFaker;
5use DateTime;
6use DateTimeInterface;
7use Faker\Generator;
8use ReflectionClass;
9
10/** @implements ApieClassFaker<DateTimeInterface> */
11class 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}