1 | <?php declare(strict_types=1); |
||
18 | class DateTimeSerializer |
||
19 | { |
||
20 | const FORMAT_RFC3339_USEC = 'Y-m-d\TH:i:s.uP'; |
||
21 | const FORMAT_RFC3339_MSEC = \DateTime::RFC3339_EXTENDED; |
||
22 | const FORMAT_RFC3339 = \DateTime::RFC3339; |
||
23 | const FORMAT_ISO8601 = \DateTime::ATOM; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $outputFormat; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $inputDateTimeFormats = [ |
||
34 | self::FORMAT_RFC3339_USEC, |
||
35 | self::FORMAT_RFC3339_MSEC, |
||
36 | self::FORMAT_RFC3339, |
||
37 | self::FORMAT_ISO8601, |
||
38 | ]; |
||
39 | |||
40 | /** |
||
41 | * DateTimeSerializer constructor. |
||
42 | * |
||
43 | * @param string|string[] ...$formats |
||
44 | */ |
||
45 | public function __construct(string ...$formats) |
||
53 | |||
54 | /** |
||
55 | * @param \DateTimeInterface $value |
||
56 | * @param Schema $schema |
||
57 | * |
||
58 | * @return string |
||
59 | */ |
||
60 | public function serialize(\DateTimeInterface $value, Schema $schema): string |
||
68 | |||
69 | /** |
||
70 | * @param mixed $value |
||
71 | * @param Schema $schema |
||
72 | * |
||
73 | * @return \DateTime |
||
74 | * |
||
75 | */ |
||
76 | public function deserialize($value, Schema $schema): \DateTime |
||
98 | } |
||
99 |
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.