DateIntervalGenerator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 6
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A __invoke() 0 3 1
1
<?php
2
namespace DBFaker\Generators;
3
4
use Faker\Factory;
5
use Faker\Generator;
6
7
class DateIntervalGenerator implements FakeDataGeneratorInterface
8
{
9
10
    /**
11
     * @var Generator
12
     */
13
    private $faker;
14
15
    /**
16
     * ComplexObjectGenerator constructor.
17
     * @param bool $generateUniqueValues
18
     */
19
    public function __construct(bool $generateUniqueValues = false)
20
    {
21
        $this->faker = Factory::create();
22
        if ($generateUniqueValues) {
23
            $this->faker->unique();
24
        }
25
    }
26
27
    /**
28
     * @return \DateInterval
29
     */
30
    public function __invoke() : \DateInterval
31
    {
32
        return $this->faker->dateTime->diff($this->faker->dateTime);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->faker->dat...$this->faker->dateTime) could return the type false which is incompatible with the type-hinted return DateInterval. Consider adding an additional type-check to rule them out.
Loading history...
33
    }
34
}
35