Total Complexity | 3 |
Total Lines | 59 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
12 | class DateTime implements GeneratorInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var FakerProviderDateTime |
||
16 | */ |
||
17 | private $provider; |
||
18 | |||
19 | /** |
||
20 | * Generated datetime format acceptable by @see date(). |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | private $format; |
||
25 | |||
26 | /** |
||
27 | * In seconds relative to the beginning of unix epoch. |
||
28 | * Defaults to -30 years. |
||
29 | * |
||
30 | * @var int |
||
31 | */ |
||
32 | private $start; |
||
33 | |||
34 | /** |
||
35 | * In seconds relative to the beginning of unix epoch. |
||
36 | * Defaults to current time. |
||
37 | * |
||
38 | * @var int |
||
39 | */ |
||
40 | private $end; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | private $timezone = null; |
||
46 | |||
47 | /** |
||
48 | * @param FakerProviderDateTime $provider |
||
49 | * @param array $config |
||
50 | */ |
||
51 | public function __construct(FakerProviderDateTime $provider, array $config) |
||
52 | { |
||
53 | $this->provider = $provider; |
||
54 | |||
55 | $this->format = $config['format'] ?? false; |
||
|
|||
56 | if (!$this->format) { |
||
57 | throw new \InvalidArgumentException("You must define 'format' for date generator."); |
||
58 | } |
||
59 | |||
60 | $this->start = $config['start'] ?? '-30 years'; |
||
61 | $this->end = $config['end'] ?? 'now'; |
||
62 | $this->timezone = $config['timezone'] ?? null; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @inheritdoc |
||
67 | */ |
||
68 | public function generate() |
||
71 | } |
||
72 | } |
||
73 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.