1 | <?php |
||
19 | class Story |
||
20 | { |
||
21 | |||
22 | 1 | public static function fromList(EntityManager $entityManager, array $values) |
|
32 | |||
33 | 2 | public static function fromValue(EntityManager $entityManager, \stdClass $value) |
|
37 | |||
38 | /** |
||
39 | * @var EntityManager |
||
40 | */ |
||
41 | protected $entityManager; |
||
42 | |||
43 | /** |
||
44 | * @var \stdClass |
||
45 | */ |
||
46 | protected $source; |
||
47 | |||
48 | /** |
||
49 | * @var \DateTime |
||
50 | */ |
||
51 | protected $updatedOn; |
||
52 | |||
53 | /** |
||
54 | * @var \DateTime |
||
55 | */ |
||
56 | protected $createdOn; |
||
57 | |||
58 | /** |
||
59 | * @var Subdef|null |
||
60 | */ |
||
61 | protected $thumbnail; |
||
62 | |||
63 | /** |
||
64 | * @var ArrayCollection|Record[] |
||
65 | */ |
||
66 | protected $records; |
||
67 | |||
68 | /** |
||
69 | * @var ArrayCollection|Metadata[] |
||
70 | */ |
||
71 | protected $metadata; |
||
72 | |||
73 | /** |
||
74 | * @var ArrayCollection|RecordStatus[] |
||
75 | */ |
||
76 | protected $status; |
||
77 | |||
78 | /** |
||
79 | * @var ArrayCollection|RecordCaption[] |
||
80 | */ |
||
81 | protected $caption; |
||
82 | |||
83 | /** |
||
84 | * @var int |
||
85 | */ |
||
86 | protected $recordCount; |
||
87 | |||
88 | /** |
||
89 | * @param EntityManager $entityManager |
||
90 | * @param \stdClass $source |
||
91 | */ |
||
92 | 2 | public function __construct(EntityManager $entityManager, \stdClass $source) |
|
97 | |||
98 | /** |
||
99 | * Get unique id |
||
100 | * |
||
101 | * @return string |
||
102 | */ |
||
103 | 2 | public function getId() |
|
107 | |||
108 | /** |
||
109 | * Get the record id |
||
110 | * |
||
111 | * @return integer |
||
112 | */ |
||
113 | 2 | public function getStoryId() |
|
117 | |||
118 | /** |
||
119 | * Get the databox id |
||
120 | * |
||
121 | * @return integer |
||
122 | */ |
||
123 | 2 | public function getDataboxId() |
|
127 | |||
128 | /** |
||
129 | * @return null|Subdef |
||
130 | */ |
||
131 | 2 | public function getThumbnail() |
|
139 | |||
140 | /** |
||
141 | * Last updated date |
||
142 | * |
||
143 | * @return \DateTime |
||
144 | */ |
||
145 | 2 | public function getUpdatedOn() |
|
149 | |||
150 | /** |
||
151 | * Creation date |
||
152 | * |
||
153 | * @return \DateTime |
||
154 | */ |
||
155 | 2 | public function getCreatedOn() |
|
159 | |||
160 | /** |
||
161 | * Get the record collection id |
||
162 | * |
||
163 | * @return integer |
||
164 | */ |
||
165 | 2 | public function getCollectionId() |
|
169 | |||
170 | /** |
||
171 | * Get the record UUID |
||
172 | * |
||
173 | * @return string |
||
174 | */ |
||
175 | 2 | public function getUuid() |
|
179 | |||
180 | /** |
||
181 | * @return int |
||
182 | */ |
||
183 | public function getRecordCount() |
||
189 | |||
190 | /** |
||
191 | * @return Record[]|ArrayCollection |
||
192 | */ |
||
193 | public function getRecords() |
||
201 | |||
202 | /** |
||
203 | * @return Metadata[]|ArrayCollection |
||
204 | */ |
||
205 | 2 | public function getMetadata() |
|
213 | |||
214 | /** |
||
215 | * @return RecordStatus[]|ArrayCollection |
||
216 | */ |
||
217 | public function getStatus() |
||
228 | |||
229 | /** |
||
230 | * @return RecordCaption[]|ArrayCollection |
||
231 | */ |
||
232 | public function getCaption() |
||
243 | } |
||
244 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: