Total Complexity | 6 |
Total Lines | 92 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
8 | abstract class AbstractEntity implements EntityInterface |
||
9 | { |
||
10 | /** |
||
11 | * @var SimpleXMLElement |
||
12 | */ |
||
13 | protected $xml; |
||
14 | |||
15 | /** |
||
16 | * The entity ID. |
||
17 | * |
||
18 | * @var int |
||
19 | */ |
||
20 | protected $id; |
||
21 | |||
22 | /** |
||
23 | * The entity name. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $name; |
||
28 | |||
29 | /** |
||
30 | * The date on which the entity was created. |
||
31 | * |
||
32 | * @var DateTime |
||
33 | */ |
||
34 | protected $createdAt; |
||
35 | |||
36 | /** |
||
37 | * The date on which the entity was updated. |
||
38 | * |
||
39 | * @var DateTime |
||
40 | */ |
||
41 | protected $updatedAt; |
||
42 | |||
43 | public function __construct(string $xml) |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Returns the SimpleXMLElement. |
||
54 | * |
||
55 | * @return SimpleXMLElement |
||
56 | */ |
||
57 | final public function getXml(): SimpleXMLElement |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Returns the entity ID. |
||
64 | * |
||
65 | * @return int |
||
66 | */ |
||
67 | public function getId(): int |
||
68 | { |
||
69 | return $this->id; |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Returns the entity name; |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | public function getName(): string |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Returns the date on which the entity was created. |
||
84 | * |
||
85 | * @return DateTime |
||
86 | */ |
||
87 | public function getCreatedAt(): DateTime |
||
88 | { |
||
89 | return $this->createdAt; |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Returns the date on which the entity was updated. |
||
94 | * |
||
95 | * @return DateTime |
||
96 | */ |
||
97 | public function getUpdatedAt(): DateTime |
||
100 | } |
||
101 | } |
||
102 |
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.